Skip to content

Commit 06721fe

Browse files
committed
test: fix test-repl-tab-complete.js
test-repl-tab-complete.js contains numerous assertions that are never run. Anything that results in a ReferenceError bails out, and never calls the functions containing the assertions. This commit adds checking for successful tab completions, as well as ReferenceErrors. PR-URL: #2052 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent a198c68 commit 06721fe

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

test/parallel/test-repl-tab-complete.js

+49-23
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22
var common = require('../common');
33
var assert = require('assert');
44
var util = require('util');
5-
65
var repl = require('repl');
6+
var referenceErrors = 0;
7+
var completionCount = 0;
8+
9+
function doNotCall() {
10+
assert(false);
11+
}
12+
13+
process.on('exit', function() {
14+
assert.strictEqual(referenceErrors, 6);
15+
assert.strictEqual(completionCount, 12);
16+
});
717

818
// A stream to push an array into a REPL
919
function ArrayStream() {
@@ -21,27 +31,37 @@ ArrayStream.prototype.resume = function() {};
2131
ArrayStream.prototype.write = function() {};
2232

2333
var works = [['inner.one'], 'inner.o'];
24-
var doesNotBreak = [[], 'inner.o'];
25-
2634
var putIn = new ArrayStream();
2735
var testMe = repl.start('', putIn);
2836

37+
// Some errors are passed to the domain, but do not callback
38+
testMe._domain.on('error', function(err) {
39+
// Errors come from another context, so instanceof doesn't work
40+
var str = err.toString();
41+
42+
if (/^ReferenceError:/.test(str))
43+
referenceErrors++;
44+
else
45+
assert(false);
46+
});
47+
2948
// Tab Complete will not break in an object literal
3049
putIn.run(['.clear']);
3150
putIn.run([
3251
'var inner = {',
3352
'one:1'
3453
]);
35-
testMe.complete('inner.o', function(error, data) {
36-
assert.deepEqual(data, doesNotBreak);
37-
});
54+
testMe.complete('inner.o', doNotCall);
55+
3856
testMe.complete('console.lo', function(error, data) {
57+
completionCount++;
3958
assert.deepEqual(data, [['console.log'], 'console.lo']);
4059
});
4160

4261
// Tab Complete will return globaly scoped variables
4362
putIn.run(['};']);
4463
testMe.complete('inner.o', function(error, data) {
64+
completionCount++;
4565
assert.deepEqual(data, works);
4666
});
4767

@@ -53,9 +73,7 @@ putIn.run([
5373
'?',
5474
'{one: 1} : '
5575
]);
56-
testMe.complete('inner.o', function(error, data) {
57-
assert.deepEqual(data, doesNotBreak);
58-
});
76+
testMe.complete('inner.o', doNotCall);
5977

6078
putIn.run(['.clear']);
6179

@@ -65,15 +83,14 @@ putIn.run([
6583
'var inner = {one:1};'
6684
]);
6785
testMe.complete('inner.o', function(error, data) {
86+
completionCount++;
6887
assert.deepEqual(data, works);
6988
});
7089

7190
// When you close the function scope tab complete will not return the
7291
// locally scoped variable
7392
putIn.run(['};']);
74-
testMe.complete('inner.o', function(error, data) {
75-
assert.deepEqual(data, doesNotBreak);
76-
});
93+
testMe.complete('inner.o', doNotCall);
7794

7895
putIn.run(['.clear']);
7996

@@ -85,6 +102,7 @@ putIn.run([
85102
'};'
86103
]);
87104
testMe.complete('inner.o', function(error, data) {
105+
completionCount++;
88106
assert.deepEqual(data, works);
89107
});
90108

@@ -99,6 +117,7 @@ putIn.run([
99117
'};'
100118
]);
101119
testMe.complete('inner.o', function(error, data) {
120+
completionCount++;
102121
assert.deepEqual(data, works);
103122
});
104123

@@ -114,12 +133,12 @@ putIn.run([
114133
'};'
115134
]);
116135
testMe.complete('inner.o', function(error, data) {
136+
completionCount++;
117137
assert.deepEqual(data, works);
118138
});
119139

120140
putIn.run(['.clear']);
121141

122-
// currently does not work, but should not break note the inner function
123142
// def has the params and { on a separate line
124143
putIn.run([
125144
'var top = function() {',
@@ -129,9 +148,7 @@ putIn.run([
129148
' one:1',
130149
'};'
131150
]);
132-
testMe.complete('inner.o', function(error, data) {
133-
assert.deepEqual(data, doesNotBreak);
134-
});
151+
testMe.complete('inner.o', doNotCall);
135152

136153
putIn.run(['.clear']);
137154

@@ -144,9 +161,7 @@ putIn.run([
144161
' one:1',
145162
'};'
146163
]);
147-
testMe.complete('inner.o', function(error, data) {
148-
assert.deepEqual(data, doesNotBreak);
149-
});
164+
testMe.complete('inner.o', doNotCall);
150165

151166
putIn.run(['.clear']);
152167

@@ -160,9 +175,7 @@ putIn.run([
160175
' one:1',
161176
'};'
162177
]);
163-
testMe.complete('inner.o', function(error, data) {
164-
assert.deepEqual(data, doesNotBreak);
165-
});
178+
testMe.complete('inner.o', doNotCall);
166179

167180
putIn.run(['.clear']);
168181

@@ -171,6 +184,7 @@ putIn.run([
171184
'var str = "test";'
172185
]);
173186
testMe.complete('str.len', function(error, data) {
187+
completionCount++;
174188
assert.deepEqual(data, [['str.length'], 'str.len']);
175189
});
176190

@@ -182,29 +196,40 @@ var spaceTimeout = setTimeout(function() {
182196
}, 1000);
183197

184198
testMe.complete(' ', function(error, data) {
199+
completionCount++;
185200
assert.deepEqual(data, [[], undefined]);
186201
clearTimeout(spaceTimeout);
187202
});
188203

189204
// tab completion should pick up the global "toString" object, and
190205
// any other properties up the "global" object's prototype chain
191206
testMe.complete('toSt', function(error, data) {
207+
completionCount++;
192208
assert.deepEqual(data, [['toString'], 'toSt']);
193209
});
194210

195211
// Tab complete provides built in libs for require()
196212
putIn.run(['.clear']);
197213

198214
testMe.complete('require(\'', function(error, data) {
215+
completionCount++;
199216
assert.strictEqual(error, null);
200217
repl._builtinLibs.forEach(function(lib) {
201218
assert.notStrictEqual(data[0].indexOf(lib), -1, lib + ' not found');
202219
});
203220
});
204221

205222
testMe.complete('require(\'n', function(error, data) {
223+
completionCount++;
206224
assert.strictEqual(error, null);
207-
assert.deepEqual(data, [['net'], 'n']);
225+
assert.strictEqual(data.length, 2);
226+
assert.strictEqual(data[1], 'n');
227+
assert.notStrictEqual(data[0].indexOf('net'), -1);
228+
// It's possible to pick up non-core modules too
229+
data[0].forEach(function(completion) {
230+
if (completion)
231+
assert(/^n/.test(completion));
232+
});
208233
});
209234

210235
// Make sure tab completion works on context properties
@@ -214,5 +239,6 @@ putIn.run([
214239
'var custom = "test";'
215240
]);
216241
testMe.complete('cus', function(error, data) {
242+
completionCount++;
217243
assert.deepEqual(data, [['custom'], 'cus']);
218244
});

0 commit comments

Comments
 (0)