@@ -8,16 +8,9 @@ var CommandlineTest = function(command) {
88 var self = this ;
99 this . command_ = command ;
1010 this . expectedExitCode_ = 0 ;
11- this . stdioOnlyOnFailures_ = true ;
1211 this . expectedErrors_ = [ ] ;
1312 this . assertExitCodeOnly_ = false ;
14-
15- // If stdioOnlyOnFailures_ is true, do not stream stdio unless test failed.
16- // This is to prevent tests with expected failures from polluting the output.
17- this . alwaysEnableStdio = function ( ) {
18- self . stdioOnlyOnFailures_ = false ;
19- return self ;
20- } ;
13+ this . testLogStream = undefined ;
2114
2215 // Only assert the exit code and not failures.
2316 // This must be true if the command you're running does not support
@@ -27,6 +20,10 @@ var CommandlineTest = function(command) {
2720 return self ;
2821 } ;
2922
23+ this . setTestLogFile = function ( filename ) {
24+ self . testLogStream = fs . createWriteStream ( filename , { flags : 'a' } ) ;
25+ } ;
26+
3027 // Set the expected exit code for the test command.
3128 this . expectExitCode = function ( exitCode ) {
3229 self . expectedExitCode_ = exitCode ;
@@ -75,19 +72,18 @@ var CommandlineTest = function(command) {
7572
7673 var test_process ;
7774
78- if ( self . stdioOnlyOnFailures_ ) {
79- test_process = child_process . spawn ( args [ 0 ] , args . slice ( 1 ) ) ;
75+ test_process = child_process . spawn ( args [ 0 ] , args . slice ( 1 ) ) ;
8076
81- test_process . stdout . on ( 'data' , function ( data ) {
82- output += data ;
83- } ) ;
77+ var processData = function ( data ) {
78+ process . stdout . write ( '.' ) ;
79+ output += data ;
80+ if ( self . testLogStream ) {
81+ self . testLogStream . write ( data ) ;
82+ }
83+ } ;
8484
85- test_process . stderr . on ( 'data' , function ( data ) {
86- output += data ;
87- } ) ;
88- } else {
89- test_process = child_process . spawn ( args [ 0 ] , args . slice ( 1 ) , { stdio : 'inherit' } ) ;
90- }
85+ test_process . stdout . on ( 'data' , processData ) ;
86+ test_process . stderr . on ( 'data' , processData ) ;
9187
9288 test_process . on ( 'error' , function ( err ) {
9389 reject ( err ) ;
@@ -102,6 +98,10 @@ var CommandlineTest = function(command) {
10298 ', actual: ' + exitCode ) ;
10399 }
104100
101+ if ( self . testLogStream ) {
102+ self . testLogStream . end ( ) ;
103+ }
104+
105105 // Skip the rest if we are only verify exit code.
106106 // Note: we're expecting a file populated by '--resultJsonOutputFile' after
107107 // this point.
@@ -202,17 +202,20 @@ exports.Executor = function() {
202202 return test ;
203203 } ;
204204
205- this . execute = function ( ) {
205+ this . execute = function ( logFile ) {
206206 var failed = false ;
207207
208208 ( function runTests ( i ) {
209209 if ( i < tests . length ) {
210210 console . log ( 'running: ' + tests [ i ] . command_ ) ;
211+ if ( logFile ) {
212+ tests [ i ] . setTestLogFile ( logFile ) ;
213+ }
211214 tests [ i ] . run ( ) . then ( function ( ) {
212- console . log ( '>>> \033[1;32mpass\033[0m' ) ;
215+ console . log ( '\n >>> \033[1;32mpass\033[0m' ) ;
213216 } , function ( err ) {
214217 failed = true ;
215- console . log ( '>>> \033[1;31mfail: ' + err . toString ( ) + '\033[0m' ) ;
218+ console . log ( '\n >>> \033[1;31mfail: ' + err . toString ( ) + '\033[0m' ) ;
216219 } ) . fin ( function ( ) {
217220 runTests ( i + 1 ) ;
218221 } ) . done ( ) ;
0 commit comments