Browse Source

test: Fix debugger repl tests

This makes the output of simple/test-debugger-repl and
simle/test-debugger-repl-utf8 mirror an actual debugger session, so it's
a bit easier to reason about.

Also, it uses the same code for both, and fixes it so that it doesn't
leave zombie processes lying around when it crashes.

Run 1000 times without any failures or zombies.
v0.9.11-release
isaacs 12 years ago
parent
commit
ec378aaa69
  1. 4
      test/fixtures/breakpoints_utf8.js
  2. 157
      test/simple/test-debugger-repl-utf8.js
  3. 99
      test/simple/test-debugger-repl.js

4
test/fixtures/breakpoints_utf8.js

@ -17,3 +17,7 @@ b();
setInterval(function() { setInterval(function() {
}, 5000); }, 5000);
now = new Date();
debugger;

157
test/simple/test-debugger-repl-utf8.js

@ -19,162 +19,9 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
process.env.NODE_DEBUGGER_TIMEOUT = 2000;
var common = require('../common'); var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
var debug = require('_debugger');
var port = common.PORT + 1337;
var script = common.fixturesDir + '/breakpoints_utf8.js'; var script = common.fixturesDir + '/breakpoints_utf8.js';
process.env.NODE_DEBUGGER_TEST_SCRIPT = script;
var child = spawn(process.execPath, ['debug', '--port=' + port, script]); require('./test-debugger-repl.js');
console.error('./node', 'debug', '--port=' + port, script);
var buffer = '';
child.stdout.setEncoding('utf-8');
child.stdout.on('data', function(data) {
data = (buffer + data.toString()).split(/\n/g);
buffer = data.pop();
data.forEach(function(line) {
child.emit('line', line);
});
});
child.stderr.pipe(process.stdout);
var expected = [];
child.on('line', function(line) {
line = line.replace(/^(debug> )+/, 'debug> ');
console.error('line> ' + line);
assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
var expectedLine = expected[0].lines.shift();
assert.ok(line.match(expectedLine) !== null, line + ' != ' + expectedLine);
if (expected[0].lines.length === 0) {
var callback = expected[0].callback;
expected.shift();
callback && callback();
}
});
function addTest(input, output) {
function next() {
if (expected.length > 0) {
child.stdin.write(expected[0].input + '\n');
if (!expected[0].lines) {
setTimeout(function() {
var callback = expected[0].callback;
expected.shift();
callback && callback();
}, 50);
}
} else {
finish();
}
};
expected.push({input: input, lines: output, callback: next});
}
// Initial lines
addTest(null, [
/listening on port \d+/,
/connecting... ok/,
/break in .*:1/,
/1/, /2/, /3/
]);
// Next
addTest('n', [
/break in .*:11/,
/9/, /10/, /11/, /12/, /13/
]);
// Watch
addTest('watch("\'x\'")');
// Continue
addTest('c', [
/break in .*:5/,
/Watchers/,
/0:\s+'x' = "x"/,
/()/,
/3/, /4/, /5/, /6/, /7/
]);
// Show watchers
addTest('watchers', [
/0:\s+'x' = "x"/
]);
// Unwatch
addTest('unwatch("\'x\'")');
// Step out
addTest('o', [
/break in .*:12/,
/10/, /11/, /12/, /13/, /14/
]);
// Continue
addTest('c', [
/break in .*:5/,
/3/, /4/, /5/, /6/, /7/
]);
// Set breakpoint by function name
addTest('sb("setInterval()", "!(setInterval.flag++)")', [
/1/, /2/, /3/, /4/, /5/, /6/, /7/, /8/, /9/, /10/
]);
// Continue
addTest('c', [
/break in node.js:\d+/,
/\d/, /\d/, /\d/, /\d/, /\d/
]);
function finish() {
process.exit(0);
}
function quit() {
if (quit.called) return;
quit.called = true;
child.stdin.write('quit');
}
setTimeout(function() {
console.error('dying badly');
var err = 'Timeout';
if (expected.length > 0 && expected[0].lines) {
err = err + '. Expected: ' + expected[0].lines.shift();
}
quit();
child.kill('SIGINT');
child.kill('SIGTERM');
// give the sigkill time to work.
setTimeout(function() {
throw new Error(err);
}, 100);
}, 5000);
process.once('uncaughtException', function(e) {
quit();
console.error(e.toString());
process.exit(1);
});
process.on('exit', function(code) {
quit();
if (code === 0) {
assert.equal(expected.length, 0);
}
});

99
test/simple/test-debugger-repl.js

@ -19,7 +19,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
process.env.NODE_DEBUGGER_TIMEOUT = 2000; process.env.NODE_DEBUGGER_TIMEOUT = 2000;
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
@ -28,11 +27,10 @@ var debug = require('_debugger');
var port = common.PORT + 1337; var port = common.PORT + 1337;
var script = common.fixturesDir + '/breakpoints.js'; var script = process.env.NODE_DEBUGGER_TEST_SCRIPT ||
common.fixturesDir + '/breakpoints.js';
var child = spawn(process.execPath, ['debug', '--port=' + port, script], { var child = spawn(process.execPath, ['debug', '--port=' + port, script]);
env: { NODE_FORCE_READLINE: 1 }
});
console.error('./node', 'debug', '--port=' + port, script); console.error('./node', 'debug', '--port=' + port, script);
@ -45,14 +43,13 @@ child.stdout.on('data', function(data) {
child.emit('line', line); child.emit('line', line);
}); });
}); });
child.stderr.pipe(process.stdout); child.stderr.pipe(process.stderr);
var expected = []; var expected = [];
child.on('line', function(line) { child.on('line', function(line) {
line = line.replace(/^(debug> )+/, 'debug> '); line = line.replace(/^(debug> *)+/, '');
line = line.replace(/\u001b\[\d+\w/g, ''); console.log(line);
console.error('line> ' + line);
assert.ok(expected.length > 0, 'Got unexpected line: ' + line); assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
var expectedLine = expected[0].lines.shift(); var expectedLine = expected[0].lines.shift();
@ -68,23 +65,17 @@ child.on('line', function(line) {
function addTest(input, output) { function addTest(input, output) {
function next() { function next() {
if (expected.length > 0) { if (expected.length > 0) {
var res = child.stdin.write(expected[0].input + '\n'), console.log('debug> ' + expected[0].input);
callback; child.stdin.write(expected[0].input + '\n');
if (!expected[0].lines) { if (!expected[0].lines) {
callback = expected[0].callback; var callback = expected[0].callback;
expected.shift(); expected.shift();
}
if (callback) { callback && callback();
if (res !== true) {
child.stdin.on('drain', callback);
} else {
process.nextTick(callback);
}
} }
} else { } else {
finish(); quit();
} }
}; };
expected.push({input: input, lines: output, callback: next}); expected.push({input: input, lines: output, callback: next});
@ -100,17 +91,15 @@ addTest(null, [
// Next // Next
addTest('n', [ addTest('n', [
/debug> n/,
/break in .*:11/, /break in .*:11/,
/9/, /10/, /11/, /12/, /13/ /9/, /10/, /11/, /12/, /13/
]); ]);
// Watch // Watch
addTest('watch("\'x\'"), true', [/debug>/, /true/]); addTest('watch("\'x\'")');
// Continue // Continue
addTest('c', [ addTest('c', [
/debug>/,
/break in .*:5/, /break in .*:5/,
/Watchers/, /Watchers/,
/0:\s+'x' = "x"/, /0:\s+'x' = "x"/,
@ -120,98 +109,76 @@ addTest('c', [
// Show watchers // Show watchers
addTest('watchers', [ addTest('watchers', [
/debug>/,
/0:\s+'x' = "x"/ /0:\s+'x' = "x"/
]); ]);
// Unwatch // Unwatch
addTest('unwatch("\'x\'"), true', [/debug>/, /true/]); addTest('unwatch("\'x\'")');
// Step out // Step out
addTest('o', [ addTest('o', [
/debug>/,
/break in .*:12/, /break in .*:12/,
/10/, /11/, /12/, /13/, /14/ /10/, /11/, /12/, /13/, /14/
]); ]);
// Continue // Continue
addTest('c', [ addTest('c', [
/debug>/,
/break in .*:5/, /break in .*:5/,
/3/, /4/, /5/, /6/, /7/ /3/, /4/, /5/, /6/, /7/
]); ]);
// Set breakpoint by function name // Set breakpoint by function name
addTest('sb("setInterval()", "!(setInterval.flag++)")', [ addTest('sb("setInterval()", "!(setInterval.flag++)")', [
/debug>/,
/1/, /2/, /3/, /4/, /5/, /6/, /7/, /8/, /9/, /10/ /1/, /2/, /3/, /4/, /5/, /6/, /7/, /8/, /9/, /10/
]); ]);
// Continue // Continue
addTest('c', [ addTest('c', [
/debug>/,
/break in node.js:\d+/, /break in node.js:\d+/,
/\d/, /\d/, /\d/, /\d/, /\d/ /\d/, /\d/, /\d/, /\d/, /\d/
]); ]);
// Repeat last command addTest('quit', []);
addTest('', [
/debug>/,
/break in .*breakpoints.js:\d+/,
/\d/, /\d/, /\d/, /\d/, /\d/
]);
addTest('repl', [
/debug>/,
/Press Ctrl \+ C to leave debug repl/
]);
addTest('now', [
/> now/,
/\w* \w* \d* \d* \d*:\d*:\d* GMT[+-]\d* (\w*)/
]);
function finish() {
// Exit debugger repl
child.kill('SIGINT');
child.kill('SIGINT');
// Exit debugger var childClosed = false;
child.kill('SIGINT'); child.on('close', function(code) {
process.exit(0); assert(!code);
} childClosed = true;
});
var quitCalled = false;
function quit() { function quit() {
if (quit.called) return; if (quitCalled || childClosed) return;
quit.called = true; quitCalled = true;
child.stdin.write('quit'); child.stdin.write('quit');
child.kill('SIGTERM');
} }
setTimeout(function() { setTimeout(function() {
console.error('dying badly buffer=%j', buffer);
var err = 'Timeout'; var err = 'Timeout';
if (expected.length > 0 && expected[0].lines) { if (expected.length > 0 && expected[0].lines) {
err = err + '. Expected: ' + expected[0].lines.shift(); err = err + '. Expected: ' + expected[0].lines.shift();
} }
quit();
child.kill('SIGINT');
child.kill('SIGTERM');
// give the sigkill time to work. child.on('close', function() {
setTimeout(function() { console.error('child is closed');
throw new Error(err); throw new Error(err);
}, 100); });
}, 5000); quit();
}, 5000).unref();
process.once('uncaughtException', function(e) { process.once('uncaughtException', function(e) {
console.error('UncaughtException', e, e.stack);
quit(); quit();
console.error(e.toString()); console.error(e.toString());
process.exit(1); process.exit(1);
}); });
process.on('exit', function(code) { process.on('exit', function(code) {
console.error('process exit', code);
quit(); quit();
if (code === 0) { if (code === 0)
assert.equal(expected.length, 0); assert(childClosed);
}
}); });

Loading…
Cancel
Save