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