@ -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 . call ed) return ;
if ( quitCalled || childClosed ) return ;
quit . c alled = 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 ) ;
}
} ) ;
} ) ;