1'use strict';
2require('../common');
3const assert = require('assert');
4const child_process = require('child_process');
5const { debuglog, inspect } = require('util');
6const debug = debuglog('test');
7
8const p = child_process.spawnSync(
9  process.execPath, [ '--completion-bash' ]);
10assert.ifError(p.error);
11
12const output = p.stdout.toString().trim().replace(/\r/g, '');
13debug(output);
14
15const prefix = `_node_complete() {
16  local cur_word options
17  cur_word="\${COMP_WORDS[COMP_CWORD]}"
18  if [[ "\${cur_word}" == -* ]] ; then
19    COMPREPLY=( $(compgen -W '`.replace(/\r/g, '');
20const suffix = `' -- "\${cur_word}") )
21    return 0
22  else
23    COMPREPLY=( $(compgen -f "\${cur_word}") )
24    return 0
25  fi
26}
27complete -o filenames -o nospace -o bashdefault -F _node_complete node node_g`
28  .replace(/\r/g, '');
29
30assert.ok(
31  output.includes(prefix),
32  `Expect\n\n ${inspect(output)}\n\nto include\n\n${inspect(prefix)}`);
33assert.ok(
34  output.includes(suffix),
35  `Expect\n\n ${inspect(output)}\n\nto include\n\n${inspect(suffix)}`);
36