1'use strict';
2require('../common');
3const assert = require('assert');
4const { spawnSync } = require('child_process');
5
6// --warnings is on by default.
7assertHasWarning(spawnWithFlags([]));
8
9// --warnings can be passed alone.
10assertHasWarning(spawnWithFlags(['--warnings']));
11
12// --no-warnings can be passed alone.
13assertHasNoWarning(spawnWithFlags(['--no-warnings']));
14
15// Last flag takes precedence.
16assertHasWarning(spawnWithFlags(['--no-warnings', '--warnings']));
17
18// Non-boolean flags cannot be negated.
19assert(spawnWithFlags(['--no-max-http-header-size']).stderr.toString().includes(
20  '--no-max-http-header-size is an invalid negation because it is not ' +
21  'a boolean option',
22));
23
24// Inexistant flags cannot be negated.
25assert(spawnWithFlags(['--no-i-dont-exist']).stderr.toString().includes(
26  'bad option: --no-i-dont-exist',
27));
28
29function spawnWithFlags(flags) {
30  return spawnSync(process.execPath, [...flags, '-e', 'new Buffer(0)']);
31}
32
33function assertHasWarning(proc) {
34  assert(proc.stderr.toString().includes('Buffer() is deprecated'));
35}
36
37function assertHasNoWarning(proc) {
38  assert(!proc.stderr.toString().includes('Buffer() is deprecated'));
39}
40