|
19 | 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21 | 21 |
|
| 22 | +'use strict'; |
22 | 23 | var assert = require('assert');
|
23 |
| -var util = require('../../'); |
24 | 24 |
|
25 |
| -if (process.argv[2] === 'child') |
26 |
| - child(); |
| 25 | +var modeArgv = process.argv[2] |
| 26 | +var sectionArgv = process.argv[3] |
| 27 | + |
| 28 | +if (modeArgv === 'child') |
| 29 | + child(sectionArgv); |
27 | 30 | else
|
28 | 31 | parent();
|
29 | 32 |
|
30 | 33 | function parent() {
|
31 |
| - test('foo,tud,bar', true); |
32 |
| - test('foo,tud', true); |
33 |
| - test('tud,bar', true); |
34 |
| - test('tud', true); |
35 |
| - test('foo,bar', false); |
36 |
| - test('', false); |
| 34 | + test('foo,tud,bar', true, 'tud'); |
| 35 | + test('foo,tud', true, 'tud'); |
| 36 | + test('tud,bar', true, 'tud'); |
| 37 | + test('tud', true, 'tud'); |
| 38 | + test('foo,bar', false, 'tud'); |
| 39 | + test('', false, 'tud'); |
| 40 | + |
| 41 | + test('###', true, '###'); |
| 42 | + test('hi:)', true, 'hi:)'); |
| 43 | + test('f$oo', true, 'f$oo'); |
| 44 | + test('f$oo', false, 'f.oo'); |
| 45 | + test('no-bar-at-all', false, 'bar'); |
| 46 | + |
| 47 | + test('test-abc', true, 'test-abc'); |
| 48 | + test('test-a', false, 'test-abc'); |
| 49 | + test('test-*', true, 'test-abc'); |
| 50 | + test('test-*c', true, 'test-abc'); |
| 51 | + test('test-*abc', true, 'test-abc'); |
| 52 | + test('abc-test', true, 'abc-test'); |
| 53 | + test('a*-test', true, 'abc-test'); |
| 54 | + test('*-test', true, 'abc-test'); |
37 | 55 | }
|
38 | 56 |
|
39 |
| -function test(environ, shouldWrite) { |
| 57 | +function test(environ, shouldWrite, section) { |
40 | 58 | var expectErr = '';
|
41 |
| - if (shouldWrite) { |
42 |
| - expectErr = 'TUD %PID%: this { is: \'a\' } /debugging/\n' + |
43 |
| - 'TUD %PID%: number=1234 string=asdf obj={"foo":"bar"}\n'; |
44 |
| - } |
45 | 59 | var expectOut = 'ok\n';
|
46 |
| - var didTest = false; |
47 | 60 |
|
48 | 61 | var spawn = require('child_process').spawn;
|
49 |
| - var child = spawn(process.execPath, [__filename, 'child'], { |
50 |
| - env: { NODE_DEBUG: environ } |
| 62 | + var child = spawn(process.execPath, [__filename, 'child', section], { |
| 63 | + env: Object.assign(process.env, { NODE_DEBUG: environ }) |
51 | 64 | });
|
52 | 65 |
|
53 |
| - expectErr = expectErr.split('%PID%').join(child.pid); |
| 66 | + if (shouldWrite) { |
| 67 | + expectErr = |
| 68 | + section.toUpperCase() + ' ' + child.pid + ': this { is: \'a\' } /debugging/\n' + |
| 69 | + section.toUpperCase() + ' ' + child.pid + ': num=1 str=a obj={"foo":"bar"}\n'; |
| 70 | + } |
54 | 71 |
|
55 | 72 | var err = '';
|
56 | 73 | child.stderr.setEncoding('utf8');
|
57 |
| - child.stderr.on('data', function(c) { |
| 74 | + child.stderr.on('data', function (c) { |
58 | 75 | err += c;
|
59 | 76 | });
|
60 | 77 |
|
61 | 78 | var out = '';
|
62 | 79 | child.stdout.setEncoding('utf8');
|
63 |
| - child.stdout.on('data', function(c) { |
| 80 | + child.stdout.on('data', function (c) { |
64 | 81 | out += c;
|
65 | 82 | });
|
66 | 83 |
|
67 |
| - child.on('close', function(c) { |
| 84 | + var didTest = false; |
| 85 | + child.on('close', function (c) { |
68 | 86 | assert(!c);
|
69 |
| - assert.equal(err, expectErr); |
70 |
| - assert.equal(out, expectOut); |
| 87 | + assert.strictEqual(err, expectErr); |
| 88 | + assert.strictEqual(out, expectOut); |
71 | 89 | didTest = true;
|
72 |
| - console.log('ok %j %j', environ, shouldWrite); |
73 | 90 | });
|
74 | 91 |
|
75 |
| - process.on('exit', function() { |
| 92 | + process.on('exit', function () { |
76 | 93 | assert(didTest);
|
77 | 94 | });
|
78 | 95 | }
|
79 | 96 |
|
80 | 97 |
|
81 |
| -function child() { |
82 |
| - var debug = util.debuglog('tud'); |
| 98 | +function child(section) { |
| 99 | + var util = require('../../util'); |
| 100 | + var debug = util.debuglog(section); |
83 | 101 | debug('this', { is: 'a' }, /debugging/);
|
84 |
| - debug('number=%d string=%s obj=%j', 1234, 'asdf', { foo: 'bar' }); |
| 102 | + debug('num=%d str=%s obj=%j', 1, 'a', { foo: 'bar' }); |
85 | 103 | console.log('ok');
|
86 | 104 | }
|
0 commit comments