Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80537 views
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
var assert = require('assert');
23
var util = require('../../');
24
25
if (process.argv[2] === 'child')
26
child();
27
else
28
parent();
29
30
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);
37
}
38
39
function test(environ, shouldWrite) {
40
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
var expectOut = 'ok\n';
46
var didTest = false;
47
48
var spawn = require('child_process').spawn;
49
var child = spawn(process.execPath, [__filename, 'child'], {
50
env: { NODE_DEBUG: environ }
51
});
52
53
expectErr = expectErr.split('%PID%').join(child.pid);
54
55
var err = '';
56
child.stderr.setEncoding('utf8');
57
child.stderr.on('data', function(c) {
58
err += c;
59
});
60
61
var out = '';
62
child.stdout.setEncoding('utf8');
63
child.stdout.on('data', function(c) {
64
out += c;
65
});
66
67
child.on('close', function(c) {
68
assert(!c);
69
assert.equal(err, expectErr);
70
assert.equal(out, expectOut);
71
didTest = true;
72
console.log('ok %j %j', environ, shouldWrite);
73
});
74
75
process.on('exit', function() {
76
assert(didTest);
77
});
78
}
79
80
81
function child() {
82
var debug = util.debuglog('tud');
83
debug('this', { is: 'a' }, /debugging/);
84
debug('number=%d string=%s obj=%j', 1234, 'asdf', { foo: 'bar' });
85
console.log('ok');
86
}
87
88