11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// --warnings is on by default.
71cb0ef41Sopenharmony_ciassertHasWarning(spawnWithFlags([]));
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci// --warnings can be passed alone.
101cb0ef41Sopenharmony_ciassertHasWarning(spawnWithFlags(['--warnings']));
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci// --no-warnings can be passed alone.
131cb0ef41Sopenharmony_ciassertHasNoWarning(spawnWithFlags(['--no-warnings']));
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci// Last flag takes precedence.
161cb0ef41Sopenharmony_ciassertHasWarning(spawnWithFlags(['--no-warnings', '--warnings']));
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci// Non-boolean flags cannot be negated.
191cb0ef41Sopenharmony_ciassert(spawnWithFlags(['--no-max-http-header-size']).stderr.toString().includes(
201cb0ef41Sopenharmony_ci  '--no-max-http-header-size is an invalid negation because it is not ' +
211cb0ef41Sopenharmony_ci  'a boolean option',
221cb0ef41Sopenharmony_ci));
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci// Inexistant flags cannot be negated.
251cb0ef41Sopenharmony_ciassert(spawnWithFlags(['--no-i-dont-exist']).stderr.toString().includes(
261cb0ef41Sopenharmony_ci  'bad option: --no-i-dont-exist',
271cb0ef41Sopenharmony_ci));
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_cifunction spawnWithFlags(flags) {
301cb0ef41Sopenharmony_ci  return spawnSync(process.execPath, [...flags, '-e', 'new Buffer(0)']);
311cb0ef41Sopenharmony_ci}
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_cifunction assertHasWarning(proc) {
341cb0ef41Sopenharmony_ci  assert(proc.stderr.toString().includes('Buffer() is deprecated'));
351cb0ef41Sopenharmony_ci}
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_cifunction assertHasNoWarning(proc) {
381cb0ef41Sopenharmony_ci  assert(!proc.stderr.toString().includes('Buffer() is deprecated'));
391cb0ef41Sopenharmony_ci}
40