|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | +const cp = require('child_process'); |
| 5 | + |
| 6 | +if (process.argv[2] === 'child') { |
| 7 | + process.emitWarning('foo'); |
| 8 | +} else { |
| 9 | + function test(env) { |
| 10 | + const cmd = `${process.execPath} ${__filename} child`; |
| 11 | + |
| 12 | + cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => { |
| 13 | + assert.strictEqual(err, null); |
| 14 | + assert.strictEqual(stdout, ''); |
| 15 | + |
| 16 | + if (env.NODE_NO_WARNINGS === '1') |
| 17 | + assert.strictEqual(stderr, ''); |
| 18 | + else |
| 19 | + assert(/Warning: foo$/.test(stderr.trim())); |
| 20 | + })); |
| 21 | + } |
| 22 | + |
| 23 | + test({}); |
| 24 | + test(process.env); |
| 25 | + test({ NODE_NO_WARNINGS: undefined }); |
| 26 | + test({ NODE_NO_WARNINGS: null }); |
| 27 | + test({ NODE_NO_WARNINGS: 'foo' }); |
| 28 | + test({ NODE_NO_WARNINGS: true }); |
| 29 | + test({ NODE_NO_WARNINGS: false }); |
| 30 | + test({ NODE_NO_WARNINGS: {} }); |
| 31 | + test({ NODE_NO_WARNINGS: [] }); |
| 32 | + test({ NODE_NO_WARNINGS: function() {} }); |
| 33 | + test({ NODE_NO_WARNINGS: 0 }); |
| 34 | + test({ NODE_NO_WARNINGS: -1 }); |
| 35 | + test({ NODE_NO_WARNINGS: '0' }); |
| 36 | + test({ NODE_NO_WARNINGS: '01' }); |
| 37 | + test({ NODE_NO_WARNINGS: '2' }); |
| 38 | + // Don't test the number 1 because it will come through as a string in the |
| 39 | + // the child process environment. |
| 40 | + test({ NODE_NO_WARNINGS: '1' }); |
| 41 | +} |
0 commit comments