Skip to content

Commit 5ca4f6f

Browse files
Trottjasnell
authored andcommitted
test: test util rather than common
test-sys.js tests common.inspect() (which is test-specific code) and not sys (which, although deprecated, should still be tested). This commit moves the tests to the not-deprecated util and adds a test to check that deprecated sys and util are the same. PR-URL: #3256 Reviewed-By: Evan Lucas <[email protected]>
1 parent 7a5ae34 commit 5ca4f6f

File tree

2 files changed

+109
-106
lines changed

2 files changed

+109
-106
lines changed

test/parallel/test-sys.js

+4-106
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,7 @@
11
'use strict';
2-
var common = require('../common');
2+
require('../common');
33
var assert = require('assert');
4+
var sys = require('sys');
5+
var util = require('util');
46

5-
assert.equal('0', common.inspect(0));
6-
assert.equal('1', common.inspect(1));
7-
assert.equal('false', common.inspect(false));
8-
assert.equal("''", common.inspect(''));
9-
assert.equal("'hello'", common.inspect('hello'));
10-
assert.equal('[Function]', common.inspect(function() {}));
11-
assert.equal('undefined', common.inspect(undefined));
12-
assert.equal('null', common.inspect(null));
13-
assert.equal('/foo(bar\\n)?/gi', common.inspect(/foo(bar\n)?/gi));
14-
assert.equal(new Date('2010-02-14T12:48:40+01:00').toString(),
15-
common.inspect(new Date('Sun, 14 Feb 2010 11:48:40 GMT')));
16-
17-
assert.equal("'\\n\\u0001'", common.inspect('\n\u0001'));
18-
19-
assert.equal('[]', common.inspect([]));
20-
assert.equal('Array {}', common.inspect(Object.create([])));
21-
assert.equal('[ 1, 2 ]', common.inspect([1, 2]));
22-
assert.equal('[ 1, [ 2, 3 ] ]', common.inspect([1, [2, 3]]));
23-
24-
assert.equal('{}', common.inspect({}));
25-
assert.equal('{ a: 1 }', common.inspect({a: 1}));
26-
assert.equal('{ a: [Function] }', common.inspect({a: function() {}}));
27-
assert.equal('{ a: 1, b: 2 }', common.inspect({a: 1, b: 2}));
28-
assert.equal('{ a: {} }', common.inspect({'a': {}}));
29-
assert.equal('{ a: { b: 2 } }', common.inspect({'a': {'b': 2}}));
30-
assert.equal('{ a: { b: { c: [Object] } } }',
31-
common.inspect({'a': {'b': { 'c': { 'd': 2 }}}}));
32-
assert.equal('{ a: { b: { c: { d: 2 } } } }',
33-
common.inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null));
34-
assert.equal('[ 1, 2, 3, [length]: 3 ]', common.inspect([1, 2, 3], true));
35-
assert.equal('{ a: [Object] }',
36-
common.inspect({'a': {'b': { 'c': 2}}}, false, 0));
37-
assert.equal('{ a: { b: [Object] } }',
38-
common.inspect({'a': {'b': { 'c': 2}}}, false, 1));
39-
assert.equal('{ visible: 1 }',
40-
common.inspect(Object.create({},
41-
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}))
42-
);
43-
44-
// Due to the hash seed randomization it's not deterministic the order that
45-
// the following ways this hash is displayed.
46-
// See http://codereview.chromium.org/9124004/
47-
48-
var out = common.inspect(Object.create({},
49-
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true);
50-
if (out !== '{ [hidden]: 2, visible: 1 }' &&
51-
out !== '{ visible: 1, [hidden]: 2 }') {
52-
assert.ok(false);
53-
}
54-
55-
56-
// Objects without prototype
57-
var out = common.inspect(Object.create(null,
58-
{ name: {value: 'Tim', enumerable: true},
59-
hidden: {value: 'secret'}}), true);
60-
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
61-
out !== "{ name: 'Tim', [hidden]: 'secret' }") {
62-
assert(false);
63-
}
64-
65-
66-
assert.equal('{ name: \'Tim\' }',
67-
common.inspect(Object.create(null,
68-
{name: {value: 'Tim', enumerable: true},
69-
hidden: {value: 'secret'}}))
70-
);
71-
72-
73-
// Dynamic properties
74-
assert.equal('{ readonly: [Getter] }',
75-
common.inspect({get readonly() {}}));
76-
77-
assert.equal('{ readwrite: [Getter/Setter] }',
78-
common.inspect({get readwrite() {}, set readwrite(val) {}}));
79-
80-
assert.equal('{ writeonly: [Setter] }',
81-
common.inspect({set writeonly(val) {}}));
82-
83-
var value = {};
84-
value['a'] = value;
85-
assert.equal('{ a: [Circular] }', common.inspect(value));
86-
87-
// Array with dynamic properties
88-
value = [1, 2, 3];
89-
value.__defineGetter__('growingLength', function() {
90-
this.push(true); return this.length;
91-
});
92-
assert.equal('[ 1, 2, 3, growingLength: [Getter] ]', common.inspect(value));
93-
94-
// Function with properties
95-
value = function() {};
96-
value.aprop = 42;
97-
assert.equal('{ [Function] aprop: 42 }', common.inspect(value));
98-
99-
// Regular expressions with properties
100-
value = /123/ig;
101-
value.aprop = 42;
102-
assert.equal('{ /123/gi aprop: 42 }', common.inspect(value));
103-
104-
// Dates with properties
105-
value = new Date('Sun, 14 Feb 2010 11:48:40 GMT');
106-
value.aprop = 42;
107-
assert.equal('{ Sun, 14 Feb 2010 11:48:40 GMT aprop: 42 }',
108-
common.inspect(value)
109-
);
7+
assert.strictEqual(sys, util);

test/parallel/test-util-inspect.js

+105
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,111 @@ var common = require('../common');
33
var assert = require('assert');
44
var util = require('util');
55

6+
assert.equal(util.inspect(1), '1');
7+
assert.equal(util.inspect(false), 'false');
8+
assert.equal(util.inspect(''), "''");
9+
assert.equal(util.inspect('hello'), "'hello'");
10+
assert.equal(util.inspect(function() {}), '[Function]');
11+
assert.equal(util.inspect(undefined), 'undefined');
12+
assert.equal(util.inspect(null), 'null');
13+
assert.equal(util.inspect(/foo(bar\n)?/gi), '/foo(bar\\n)?/gi');
14+
assert.equal(util.inspect(new Date('Sun, 14 Feb 2010 11:48:40 GMT')),
15+
new Date('2010-02-14T12:48:40+01:00').toString());
16+
17+
assert.equal(util.inspect('\n\u0001'), "'\\n\\u0001'");
18+
19+
assert.equal(util.inspect([]), '[]');
20+
assert.equal(util.inspect(Object.create([])), 'Array {}');
21+
assert.equal(util.inspect([1, 2]), '[ 1, 2 ]');
22+
assert.equal(util.inspect([1, [2, 3]]), '[ 1, [ 2, 3 ] ]');
23+
24+
assert.equal(util.inspect({}), '{}');
25+
assert.equal(util.inspect({a: 1}), '{ a: 1 }');
26+
assert.equal(util.inspect({a: function() {}}), '{ a: [Function] }');
27+
assert.equal(util.inspect({a: 1, b: 2}), '{ a: 1, b: 2 }');
28+
assert.equal(util.inspect({'a': {}}), '{ a: {} }');
29+
assert.equal(util.inspect({'a': {'b': 2}}), '{ a: { b: 2 } }');
30+
assert.equal(util.inspect({'a': {'b': { 'c': { 'd': 2 }}}}),
31+
'{ a: { b: { c: [Object] } } }');
32+
assert.equal(util.inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null),
33+
'{ a: { b: { c: { d: 2 } } } }');
34+
assert.equal(util.inspect([1, 2, 3], true), '[ 1, 2, 3, [length]: 3 ]');
35+
assert.equal(util.inspect({'a': {'b': { 'c': 2}}}, false, 0),
36+
'{ a: [Object] }');
37+
assert.equal(util.inspect({'a': {'b': { 'c': 2}}}, false, 1),
38+
'{ a: { b: [Object] } }');
39+
assert.equal(util.inspect(Object.create({},
40+
{visible: {value: 1, enumerable: true}, hidden: {value: 2}})),
41+
'{ visible: 1 }'
42+
);
43+
44+
// Due to the hash seed randomization it's not deterministic the order that
45+
// the following ways this hash is displayed.
46+
// See http://codereview.chromium.org/9124004/
47+
48+
var out = util.inspect(Object.create({},
49+
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true);
50+
if (out !== '{ [hidden]: 2, visible: 1 }' &&
51+
out !== '{ visible: 1, [hidden]: 2 }') {
52+
assert.ok(false);
53+
}
54+
55+
56+
// Objects without prototype
57+
var out = util.inspect(Object.create(null,
58+
{ name: {value: 'Tim', enumerable: true},
59+
hidden: {value: 'secret'}}), true);
60+
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
61+
out !== "{ name: 'Tim', [hidden]: 'secret' }") {
62+
assert(false);
63+
}
64+
65+
66+
assert.equal(
67+
util.inspect(Object.create(null,
68+
{name: {value: 'Tim', enumerable: true},
69+
hidden: {value: 'secret'}})),
70+
'{ name: \'Tim\' }'
71+
);
72+
73+
74+
// Dynamic properties
75+
assert.equal(util.inspect({get readonly() {}}),
76+
'{ readonly: [Getter] }');
77+
78+
assert.equal(util.inspect({get readwrite() {}, set readwrite(val) {}}),
79+
'{ readwrite: [Getter/Setter] }');
80+
81+
assert.equal(util.inspect({set writeonly(val) {}}),
82+
'{ writeonly: [Setter] }');
83+
84+
var value = {};
85+
value['a'] = value;
86+
assert.equal(util.inspect(value), '{ a: [Circular] }');
87+
88+
// Array with dynamic properties
89+
value = [1, 2, 3];
90+
value.__defineGetter__('growingLength', function() {
91+
this.push(true); return this.length;
92+
});
93+
assert.equal(util.inspect(value), '[ 1, 2, 3, growingLength: [Getter] ]');
94+
95+
// Function with properties
96+
value = function() {};
97+
value.aprop = 42;
98+
assert.equal(util.inspect(value), '{ [Function] aprop: 42 }');
99+
100+
// Regular expressions with properties
101+
value = /123/ig;
102+
value.aprop = 42;
103+
assert.equal(util.inspect(value), '{ /123/gi aprop: 42 }');
104+
105+
// Dates with properties
106+
value = new Date('Sun, 14 Feb 2010 11:48:40 GMT');
107+
value.aprop = 42;
108+
assert.equal(util.inspect(value), '{ Sun, 14 Feb 2010 11:48:40 GMT aprop: 42 }'
109+
);
110+
6111
// test the internal isDate implementation
7112
var Date2 = require('vm').runInNewContext('Date');
8113
var d = new Date2();

0 commit comments

Comments
 (0)