Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80538 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
23
var assert = require('assert');
24
var util = require('../../');
25
26
assert.ok(process.stdout.writable);
27
assert.ok(process.stderr.writable);
28
29
var stdout_write = global.process.stdout.write;
30
var strings = [];
31
global.process.stdout.write = function(string) {
32
strings.push(string);
33
};
34
console._stderr = process.stdout;
35
36
var tests = [
37
{input: 'foo', output: 'foo'},
38
{input: undefined, output: 'undefined'},
39
{input: null, output: 'null'},
40
{input: false, output: 'false'},
41
{input: 42, output: '42'},
42
{input: function(){}, output: '[Function]'},
43
{input: parseInt('not a number', 10), output: 'NaN'},
44
{input: {answer: 42}, output: '{ answer: 42 }'},
45
{input: [1,2,3], output: '[ 1, 2, 3 ]'}
46
];
47
48
// test util.log()
49
tests.forEach(function(test) {
50
util.log(test.input);
51
var result = strings.shift().trim(),
52
re = (/[0-9]{1,2} [A-Z][a-z]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} - (.+)$/),
53
match = re.exec(result);
54
assert.ok(match);
55
assert.equal(match[1], test.output);
56
});
57
58
global.process.stdout.write = stdout_write;
59
60