Skip to content

Commit

Permalink
Add more debugger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Dec 30, 2010
1 parent 8e96b8a commit a8417c1
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 13 deletions.
32 changes: 31 additions & 1 deletion lib/_debugger.js
Expand Up @@ -187,7 +187,30 @@ Client.prototype.reqBacktrace = function(cb) {
};


var helpMessage = "Commands: backtrace, version, eval, help, quit";
// Returns an array of objects like this:
//
// { handle: 11,
// type: 'script',
// name: 'node.js',
// id: 14,
// lineOffset: 0,
// columnOffset: 0,
// lineCount: 562,
// sourceStart: '(function(process) {\n\n ',
// sourceLength: 15939,
// scriptType: 2,
// compilationType: 0,
// context: { ref: 10 },
// text: 'node.js (lines: 562)' }
//
Client.prototype.reqScripts = function(cb) {
this.req({ command: 'scripts' } , function (res) {
if (cb) cb(res.body);
});
};


var helpMessage = "Commands: scripts, backtrace, version, eval, help, quit";


function startInterface() {
Expand Down Expand Up @@ -226,6 +249,13 @@ function startInterface() {
i.prompt();
});

} else if (/^scripts/.test(cmd)) {
c.reqScripts(function (res) {
var text = res.map(function (x) { return x.text; });
console.log(text.join('\n'));
i.prompt();
});

} else if (/^eval/.test(cmd)) {
c.reqEval(cmd.slice(5), function (res) {
console.log(res);
Expand Down
73 changes: 61 additions & 12 deletions test/simple/test-debugger-client.js
Expand Up @@ -18,17 +18,59 @@ p.execute("Type: connect\r\n" +
"Content-Length: 0\r\n\r\n");
assert.equal(1, resCount);

var expectedConnections = 0;
var tests = [];
function addTest (cb) {
expectedConnections++;
tests.push(cb);
}

addTest(function (client, done) {
console.error("requesting version");
client.reqVersion(function (v) {
console.log("version: %s", v);
assert.equal(process.versions.v8, v);
done();
});
});

addTest(function (client, done) {
console.error("requesting scripts");
client.reqScripts(function (s) {
console.error("got %d scripts", s.length);
var foundMainScript = false;
for (var i = 0; i < s.length; i++) {
if (s[i].name === 'node.js') {
foundMainScript = true;
break;
}
}
assert.ok(foundMainScript);
done();
});
});

addTest(function (client, done) {
console.error("eval 2+2");
client.reqEval("2+2", function (res) {
console.error(res);
assert.equal('4', res.text);
assert.equal(4, res.value);
done();
});
});


var connectCount = 0;

function test(cb) {
function doTest(cb, done) {
var nodeProcess = spawn(process.execPath,
['-e', 'setInterval(function () { console.log("blah"); }, 1000);']);

nodeProcess.stdout.once('data', function () {
console.log("new node process: %d", nodeProcess.pid);
console.log(">>> new node process: %d", nodeProcess.pid);
process.kill(nodeProcess.pid, "SIGUSR1");
console.log("signaling it with SIGUSR1");
console.log(">>> signaling it with SIGUSR1");
});

var didTryConnect = false;
Expand All @@ -39,27 +81,34 @@ function test(cb) {

// Wait for some data before trying to connect
var c = new debug.Client();
process.stdout.write("connecting...");
process.stdout.write(">>> connecting...");
c.connect(debug.port, function () {
connectCount++;
console.log("connected!");
cb(c, nodeProcess);
cb(c, function () {
console.error(">>> killing node process %d\n\n", nodeProcess.pid);
nodeProcess.kill();
done();
});
});
}
});
}


test(function (client, nodeProcess) {
client.reqVersion(function (v) {
console.log("version: %s", v);
assert.equal(process.versions.v8, v);
nodeProcess.kill();
function run () {
var t = tests[0];
if (!t) return;

doTest(t, function () {
tests.shift();
run();
});
});
}

run();

process.on('exit', function() {
assert.equal(1, connectCount);
assert.equal(expectedConnections, connectCount);
});

0 comments on commit a8417c1

Please sign in to comment.