test: refactor test-repl-tab-complete
The original test uses a variable to explicitly count how many times the callback is invoked. This patch uses common.mustCall() to track if the callback is called or not. This makes the test more robust, as we don't explicitly hardcode the number of times to be called. PR-URL: https://github.com/nodejs/io.js/pull/2122 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
84b3915764
commit
180fd392ca
@ -4,15 +4,17 @@ var assert = require('assert');
|
|||||||
var util = require('util');
|
var util = require('util');
|
||||||
var repl = require('repl');
|
var repl = require('repl');
|
||||||
var referenceErrors = 0;
|
var referenceErrors = 0;
|
||||||
var completionCount = 0;
|
var expectedReferenceErrors = 0;
|
||||||
|
|
||||||
function doNotCall() {
|
function getDoNotCallFunction() {
|
||||||
assert(false);
|
expectedReferenceErrors += 1;
|
||||||
|
return function() {
|
||||||
|
assert(false);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
assert.strictEqual(referenceErrors, 6);
|
assert.strictEqual(referenceErrors, expectedReferenceErrors);
|
||||||
assert.strictEqual(completionCount, 12);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// A stream to push an array into a REPL
|
// A stream to push an array into a REPL
|
||||||
@ -51,19 +53,17 @@ putIn.run([
|
|||||||
'var inner = {',
|
'var inner = {',
|
||||||
'one:1'
|
'one:1'
|
||||||
]);
|
]);
|
||||||
testMe.complete('inner.o', doNotCall);
|
testMe.complete('inner.o', getDoNotCallFunction());
|
||||||
|
|
||||||
testMe.complete('console.lo', function(error, data) {
|
testMe.complete('console.lo', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.deepEqual(data, [['console.log'], 'console.lo']);
|
assert.deepEqual(data, [['console.log'], 'console.lo']);
|
||||||
});
|
}));
|
||||||
|
|
||||||
// Tab Complete will return globaly scoped variables
|
// Tab Complete will return globaly scoped variables
|
||||||
putIn.run(['};']);
|
putIn.run(['};']);
|
||||||
testMe.complete('inner.o', function(error, data) {
|
testMe.complete('inner.o', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.deepEqual(data, works);
|
assert.deepEqual(data, works);
|
||||||
});
|
}));
|
||||||
|
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ putIn.run([
|
|||||||
'?',
|
'?',
|
||||||
'{one: 1} : '
|
'{one: 1} : '
|
||||||
]);
|
]);
|
||||||
testMe.complete('inner.o', doNotCall);
|
testMe.complete('inner.o', getDoNotCallFunction());
|
||||||
|
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
|
|
||||||
@ -82,15 +82,14 @@ putIn.run([
|
|||||||
'var top = function() {',
|
'var top = function() {',
|
||||||
'var inner = {one:1};'
|
'var inner = {one:1};'
|
||||||
]);
|
]);
|
||||||
testMe.complete('inner.o', function(error, data) {
|
testMe.complete('inner.o', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.deepEqual(data, works);
|
assert.deepEqual(data, works);
|
||||||
});
|
}));
|
||||||
|
|
||||||
// When you close the function scope tab complete will not return the
|
// When you close the function scope tab complete will not return the
|
||||||
// locally scoped variable
|
// locally scoped variable
|
||||||
putIn.run(['};']);
|
putIn.run(['};']);
|
||||||
testMe.complete('inner.o', doNotCall);
|
testMe.complete('inner.o', getDoNotCallFunction());
|
||||||
|
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
|
|
||||||
@ -101,10 +100,9 @@ putIn.run([
|
|||||||
' one:1',
|
' one:1',
|
||||||
'};'
|
'};'
|
||||||
]);
|
]);
|
||||||
testMe.complete('inner.o', function(error, data) {
|
testMe.complete('inner.o', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.deepEqual(data, works);
|
assert.deepEqual(data, works);
|
||||||
});
|
}));
|
||||||
|
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
|
|
||||||
@ -116,10 +114,9 @@ putIn.run([
|
|||||||
' one:1',
|
' one:1',
|
||||||
'};'
|
'};'
|
||||||
]);
|
]);
|
||||||
testMe.complete('inner.o', function(error, data) {
|
testMe.complete('inner.o', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.deepEqual(data, works);
|
assert.deepEqual(data, works);
|
||||||
});
|
}));
|
||||||
|
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
|
|
||||||
@ -132,10 +129,9 @@ putIn.run([
|
|||||||
' one:1',
|
' one:1',
|
||||||
'};'
|
'};'
|
||||||
]);
|
]);
|
||||||
testMe.complete('inner.o', function(error, data) {
|
testMe.complete('inner.o', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.deepEqual(data, works);
|
assert.deepEqual(data, works);
|
||||||
});
|
}));
|
||||||
|
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
|
|
||||||
@ -148,7 +144,7 @@ putIn.run([
|
|||||||
' one:1',
|
' one:1',
|
||||||
'};'
|
'};'
|
||||||
]);
|
]);
|
||||||
testMe.complete('inner.o', doNotCall);
|
testMe.complete('inner.o', getDoNotCallFunction());
|
||||||
|
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
|
|
||||||
@ -161,7 +157,7 @@ putIn.run([
|
|||||||
' one:1',
|
' one:1',
|
||||||
'};'
|
'};'
|
||||||
]);
|
]);
|
||||||
testMe.complete('inner.o', doNotCall);
|
testMe.complete('inner.o', getDoNotCallFunction());
|
||||||
|
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
|
|
||||||
@ -175,7 +171,7 @@ putIn.run([
|
|||||||
' one:1',
|
' one:1',
|
||||||
'};'
|
'};'
|
||||||
]);
|
]);
|
||||||
testMe.complete('inner.o', doNotCall);
|
testMe.complete('inner.o', getDoNotCallFunction());
|
||||||
|
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
|
|
||||||
@ -183,10 +179,9 @@ putIn.run(['.clear']);
|
|||||||
putIn.run([
|
putIn.run([
|
||||||
'var str = "test";'
|
'var str = "test";'
|
||||||
]);
|
]);
|
||||||
testMe.complete('str.len', function(error, data) {
|
testMe.complete('str.len', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.deepEqual(data, [['str.length'], 'str.len']);
|
assert.deepEqual(data, [['str.length'], 'str.len']);
|
||||||
});
|
}));
|
||||||
|
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
|
|
||||||
@ -195,32 +190,28 @@ var spaceTimeout = setTimeout(function() {
|
|||||||
throw new Error('timeout');
|
throw new Error('timeout');
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
testMe.complete(' ', function(error, data) {
|
testMe.complete(' ', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.deepEqual(data, [[], undefined]);
|
assert.deepEqual(data, [[], undefined]);
|
||||||
clearTimeout(spaceTimeout);
|
clearTimeout(spaceTimeout);
|
||||||
});
|
}));
|
||||||
|
|
||||||
// tab completion should pick up the global "toString" object, and
|
// tab completion should pick up the global "toString" object, and
|
||||||
// any other properties up the "global" object's prototype chain
|
// any other properties up the "global" object's prototype chain
|
||||||
testMe.complete('toSt', function(error, data) {
|
testMe.complete('toSt', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.deepEqual(data, [['toString'], 'toSt']);
|
assert.deepEqual(data, [['toString'], 'toSt']);
|
||||||
});
|
}));
|
||||||
|
|
||||||
// Tab complete provides built in libs for require()
|
// Tab complete provides built in libs for require()
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
|
|
||||||
testMe.complete('require(\'', function(error, data) {
|
testMe.complete('require(\'', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.strictEqual(error, null);
|
assert.strictEqual(error, null);
|
||||||
repl._builtinLibs.forEach(function(lib) {
|
repl._builtinLibs.forEach(function(lib) {
|
||||||
assert.notStrictEqual(data[0].indexOf(lib), -1, lib + ' not found');
|
assert.notStrictEqual(data[0].indexOf(lib), -1, lib + ' not found');
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
testMe.complete('require(\'n', function(error, data) {
|
testMe.complete('require(\'n', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.strictEqual(error, null);
|
assert.strictEqual(error, null);
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
assert.strictEqual(data[1], 'n');
|
assert.strictEqual(data[1], 'n');
|
||||||
@ -230,7 +221,7 @@ testMe.complete('require(\'n', function(error, data) {
|
|||||||
if (completion)
|
if (completion)
|
||||||
assert(/^n/.test(completion));
|
assert(/^n/.test(completion));
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
// Make sure tab completion works on context properties
|
// Make sure tab completion works on context properties
|
||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
@ -238,7 +229,6 @@ putIn.run(['.clear']);
|
|||||||
putIn.run([
|
putIn.run([
|
||||||
'var custom = "test";'
|
'var custom = "test";'
|
||||||
]);
|
]);
|
||||||
testMe.complete('cus', function(error, data) {
|
testMe.complete('cus', common.mustCall(function(error, data) {
|
||||||
completionCount++;
|
|
||||||
assert.deepEqual(data, [['custom'], 'cus']);
|
assert.deepEqual(data, [['custom'], 'cus']);
|
||||||
});
|
}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user