@@ -566,28 +566,17 @@ Test.prototype._runChild = function runChild (child, name, extra, cb) {
566
566
self . _currentChild = null
567
567
var time = results ? '# time=' + results . time + 'ms' : ''
568
568
if ( extra . buffered ) {
569
- var bail = false
570
- if ( self . _bail && ! child . _ok ) {
571
- bail = true
572
- self . _bail = false
573
- }
574
-
575
569
var endThis = false
576
570
if ( self . _plan === self . _count + 1 ) {
577
571
endThis = true
578
572
self . _ending = true
579
573
}
580
574
581
- self . ok ( child . _ok , child . _name + ' {' , { diagnostic : false } )
582
- var b = child . _buffer . trim ( ) . split ( '\n' ) . join ( '\n ' ) + '\n'
583
- b = b . split ( '\n \n' ) . join ( '\n\n' )
584
- if ( time ) {
585
- b += ' ' + time + '\n'
586
- }
587
- self . push ( ' ' + b + '}\n' )
588
- if ( bail ) {
589
- self . bailout ( child . _name )
590
- } else if ( endThis ) {
575
+ self . ok ( child . _ok , child . _name , {
576
+ _tapChildBuffer : child . _buffer
577
+ } )
578
+
579
+ if ( endThis ) {
591
580
self . _ending = false
592
581
self . end ( IMPLICIT )
593
582
}
@@ -598,16 +587,16 @@ Test.prototype._runChild = function runChild (child, name, extra, cb) {
598
587
self . push ( '\n' )
599
588
}
600
589
} )
590
+
601
591
child . on ( 'bailout' , function ( message ) {
602
592
if ( extra . buffered ) {
593
+ self . _currentChild = null
603
594
self . _bail = false
604
- if ( ! ended ) {
605
- child . emit ( 'end' )
606
- }
607
- self . bailout ( message )
608
- } else {
609
- rootBail ( self , message )
595
+ self . fail ( child . _name , {
596
+ _tapChildBuffer : child . _buffer
597
+ } )
610
598
}
599
+ rootBail ( self , message )
611
600
} )
612
601
613
602
// still need try/catch for synchronous errors
@@ -709,7 +698,7 @@ Test.prototype.stdin = function (name, extra, deferred) {
709
698
self . _processQueue ( )
710
699
} )
711
700
712
- parser . on ( 'bailout' , function ( message ) {
701
+ parser . once ( 'bailout' , function ( message ) {
713
702
rootBail ( self , message )
714
703
} )
715
704
@@ -732,14 +721,17 @@ function pruneFailures (res) {
732
721
function rootBail ( self , message ) {
733
722
var p = self
734
723
while ( p . _parent ) {
724
+ // end any buffered tests along the way
725
+ if ( p . _buffered ) {
726
+ p . emit ( 'end' )
727
+ }
735
728
p . _bailedOut = true
736
729
p = p . _parent
737
730
}
738
731
p . bailout ( message )
739
732
}
740
733
741
734
function childStream ( self , child , parser ) {
742
- var bailedOut = false
743
735
var emitter = parser || child
744
736
745
737
if ( parser ) {
@@ -754,17 +746,14 @@ function childStream (self, child, parser) {
754
746
rootBail ( self , reason )
755
747
} )
756
748
757
- emitter . on ( 'line' , function ( line ) {
758
- if ( line . match ( / ^ T A P v e r s i o n \d + \n $ / ) ) {
749
+ var sawVersion = false
750
+ emitter . on ( 'line' , function onEmitterLine ( line ) {
751
+ if ( ! sawVersion && line . match ( / ^ T A P v e r s i o n \d + \n $ / ) ) {
752
+ sawVersion = true
759
753
return
760
754
}
761
755
762
- if ( line . trim ( ) ) {
763
- line = ' ' + line
764
- } else {
765
- line = '\n'
766
- }
767
-
756
+ line = ' ' + line
768
757
self . push ( line )
769
758
} )
770
759
}
@@ -879,9 +868,11 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra, defe
879
868
childStream ( self , child . stdout , parser )
880
869
} else {
881
870
var buffer = ''
871
+ var sawVersion = false
882
872
child . stdout . pipe ( parser )
883
873
parser . on ( 'line' , function ( line ) {
884
- if ( line . match ( / T A P v e r s i o n \d + \n $ / ) ) {
874
+ if ( ! sawVersion && line . match ( / ^ T A P v e r s i o n \d + \n $ / ) ) {
875
+ sawVersion = true
885
876
return
886
877
}
887
878
buffer += line
@@ -943,40 +934,27 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra, defe
943
934
944
935
var ok = results . ok && ! code && ! signal
945
936
if ( extra . buffered ) {
946
- if ( extra . skip ) {
947
- if ( typeof extra . skip === 'string' ) {
948
- extra . skip += ' {'
949
- } else {
950
- extra . skip = ' {'
951
- }
952
- } else if ( extra . todo ) {
953
- if ( typeof extra . todo === 'string' ) {
954
- extra . todo += ' {'
955
- } else {
956
- extra . todo = ' {'
957
- }
958
- } else {
959
- name += ' {'
960
- }
961
- extra . diagnostic = false
962
-
963
- self . ok ( ok , name , extra )
964
- var b = buffer . trim ( ) . split ( '\n' ) . join ( '\n ' ) + '\n'
965
- b = b . split ( '\n \n' ) . join ( '\n\n' )
966
- b += ' ' + time + '\n'
967
- self . push ( ' ' + b + '}\n' )
968
- } else {
969
- self . ok ( ok , name , extra )
937
+ extra . _tapChildBuffer = buffer
970
938
}
939
+ self . ok ( ok , name , extra )
971
940
if ( ! self . _ended ) {
972
941
self . push ( '\n' )
973
942
}
943
+ if ( child . _bailedOut ) {
944
+ rootBail ( self , child . _bailedOut || name )
945
+ }
974
946
deferred . resolve ( self )
975
947
self . _processQueue ( )
976
948
} )
977
949
978
- parser . on ( 'bailout' , function ( message ) {
979
- child . kill ( 'SIGTERM' )
950
+ parser . once ( 'bailout' , function ( message ) {
951
+ // bailouts have 1 second to quit before being forcibly killed.
952
+ var timer = setTimeout ( function ( ) {
953
+ child . kill ( 'SIGKILL' )
954
+ } , 1000 )
955
+ timer . unref ( )
956
+ child . once ( 'close' , clearTimeout . bind ( null , timer ) )
957
+ child . _bailedOut = message
980
958
} )
981
959
982
960
if ( child . stderr ) {
@@ -1033,9 +1011,9 @@ function bailOnFail (self, stream, parser, root) {
1033
1011
} )
1034
1012
1035
1013
parser . on ( 'assert' , function ( res ) {
1036
- if ( ! res . todo && ! res . skip && ! res . ok ) {
1014
+ if ( ! res . todo && ! res . skip && ! res . ok && res . name . slice ( - 1 ) !== '{' ) {
1037
1015
var ind = new Array ( parser . level + 1 ) . join ( ' ' )
1038
- var line = ind + 'Bail out! # ' + res . name + '\n'
1016
+ var line = ind + 'Bail out! # ' + res . name . trim ( ) + '\n'
1039
1017
root . buffer = ''
1040
1018
root . write ( line )
1041
1019
}
@@ -1376,6 +1354,12 @@ Test.prototype.printResult = function printResult (ok, message, extra) {
1376
1354
return
1377
1355
}
1378
1356
1357
+ var buffer
1358
+ if ( extra . _tapChildBuffer ) {
1359
+ buffer = extra . _tapChildBuffer
1360
+ delete extra . _tapChildBuffer
1361
+ }
1362
+
1379
1363
var res = { ok : ok , message : message , extra : extra }
1380
1364
1381
1365
if ( extra . todo ) {
@@ -1404,6 +1388,10 @@ Test.prototype.printResult = function printResult (ok, message, extra) {
1404
1388
1405
1389
message = message . replace ( / [ \n \r ] / g, ' ' ) . replace ( / \t / g, ' ' )
1406
1390
1391
+ if ( buffer ) {
1392
+ message += ' {'
1393
+ }
1394
+
1407
1395
this . push ( util . format ( '%s %d%s' , ok ? 'ok' : 'not ok' , n , message ) )
1408
1396
1409
1397
var ending = false
@@ -1431,11 +1419,30 @@ Test.prototype.printResult = function printResult (ok, message, extra) {
1431
1419
this . push ( '\n' )
1432
1420
1433
1421
// If we're skipping, no need for diags.
1434
- if ( ! ok && ! extra . skip || extra . diagnostic ) {
1435
- this . writeDiags ( extra )
1422
+ // Also, never print diags if there's a child buffer to show
1423
+ if ( buffer ) {
1424
+ var b = buffer . trim ( ) . split ( '\n' ) . join ( '\n ' ) + '\n'
1425
+ this . push ( ' ' + b + '}\n' )
1426
+ } else {
1427
+ var diagnostic = process . env . TAP_DIAG === '1'
1428
+ if ( ! ok ) {
1429
+ diagnostic = true
1430
+ }
1431
+ if ( extra . skip ) {
1432
+ diagnostic = false
1433
+ }
1434
+ if ( process . env . TAP_DIAG === '0' ) {
1435
+ diagnostic = false
1436
+ }
1437
+ if ( typeof extra . diagnostic === 'boolean' ) {
1438
+ diagnostic = extra . diagnostic
1439
+ }
1440
+ if ( diagnostic ) {
1441
+ this . writeDiags ( extra )
1442
+ }
1436
1443
}
1437
1444
1438
- if ( this . _bail && ! ok && ! extra . skip && ! extra . todo ) {
1445
+ if ( this . _bail && ! ok && ! extra . skip && ! extra . todo && message . slice ( - 1 ) !== '{' ) {
1439
1446
this . bailout ( message . replace ( / ^ - / , '' ) )
1440
1447
}
1441
1448
@@ -1634,9 +1641,6 @@ Test.prototype.push = function (c, e) {
1634
1641
return
1635
1642
}
1636
1643
1637
- if ( ! line . trim ( ) )
1638
- line = ''
1639
-
1640
1644
this . emit ( 'line' , line + '\n' )
1641
1645
} , this )
1642
1646
@@ -1662,7 +1666,7 @@ Test.prototype.bailout = function (message) {
1662
1666
this . _bailedOut = true
1663
1667
this . _ok = false
1664
1668
this . emit ( 'bailout' , message )
1665
- this . push ( null )
1669
+ this . end ( IMPLICIT )
1666
1670
}
1667
1671
1668
1672
Test . prototype . _addMoment = function ( which , fn ) {
0 commit comments