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