11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst cp = require('child_process');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') {
71cb0ef41Sopenharmony_ci  process.emitWarning('foo');
81cb0ef41Sopenharmony_ci} else {
91cb0ef41Sopenharmony_ci  function test(newEnv) {
101cb0ef41Sopenharmony_ci    const env = { ...process.env, ...newEnv };
111cb0ef41Sopenharmony_ci    const cmd = `"${process.execPath}" "${__filename}" child`;
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci    cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => {
141cb0ef41Sopenharmony_ci      assert.strictEqual(err, null);
151cb0ef41Sopenharmony_ci      assert.strictEqual(stdout, '');
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci      if (env.NODE_NO_WARNINGS === '1')
181cb0ef41Sopenharmony_ci        assert.strictEqual(stderr, '');
191cb0ef41Sopenharmony_ci      else
201cb0ef41Sopenharmony_ci        assert.match(stderr.trim(), /Warning: foo\n/);
211cb0ef41Sopenharmony_ci    }));
221cb0ef41Sopenharmony_ci  }
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  test({});
251cb0ef41Sopenharmony_ci  test(process.env);
261cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: undefined });
271cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: null });
281cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: 'foo' });
291cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: true });
301cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: false });
311cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: {} });
321cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: [] });
331cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: function() {} });
341cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: 0 });
351cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: -1 });
361cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: '0' });
371cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: '01' });
381cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: '2' });
391cb0ef41Sopenharmony_ci  // Don't test the number 1 because it will come through as a string in the
401cb0ef41Sopenharmony_ci  // child process environment.
411cb0ef41Sopenharmony_ci  test({ NODE_NO_WARNINGS: '1' });
421cb0ef41Sopenharmony_ci}
43