@@ -8,16 +8,9 @@ var CommandlineTest = function(command) {
8
8
var self = this ;
9
9
this . command_ = command ;
10
10
this . expectedExitCode_ = 0 ;
11
- this . stdioOnlyOnFailures_ = true ;
12
11
this . expectedErrors_ = [ ] ;
13
12
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 ;
21
14
22
15
// Only assert the exit code and not failures.
23
16
// This must be true if the command you're running does not support
@@ -27,6 +20,10 @@ var CommandlineTest = function(command) {
27
20
return self ;
28
21
} ;
29
22
23
+ this . setTestLogFile = function ( filename ) {
24
+ self . testLogStream = fs . createWriteStream ( filename , { flags : 'a' } ) ;
25
+ } ;
26
+
30
27
// Set the expected exit code for the test command.
31
28
this . expectExitCode = function ( exitCode ) {
32
29
self . expectedExitCode_ = exitCode ;
@@ -75,19 +72,18 @@ var CommandlineTest = function(command) {
75
72
76
73
var test_process ;
77
74
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 ) ) ;
80
76
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
+ } ;
84
84
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 ) ;
91
87
92
88
test_process . on ( 'error' , function ( err ) {
93
89
reject ( err ) ;
@@ -102,6 +98,10 @@ var CommandlineTest = function(command) {
102
98
', actual: ' + exitCode ) ;
103
99
}
104
100
101
+ if ( self . testLogStream ) {
102
+ self . testLogStream . end ( ) ;
103
+ }
104
+
105
105
// Skip the rest if we are only verify exit code.
106
106
// Note: we're expecting a file populated by '--resultJsonOutputFile' after
107
107
// this point.
@@ -202,17 +202,20 @@ exports.Executor = function() {
202
202
return test ;
203
203
} ;
204
204
205
- this . execute = function ( ) {
205
+ this . execute = function ( logFile ) {
206
206
var failed = false ;
207
207
208
208
( function runTests ( i ) {
209
209
if ( i < tests . length ) {
210
210
console . log ( 'running: ' + tests [ i ] . command_ ) ;
211
+ if ( logFile ) {
212
+ tests [ i ] . setTestLogFile ( logFile ) ;
213
+ }
211
214
tests [ i ] . run ( ) . then ( function ( ) {
212
- console . log ( '>>> \033[1;32mpass\033[0m' ) ;
215
+ console . log ( '\n >>> \033[1;32mpass\033[0m' ) ;
213
216
} , function ( err ) {
214
217
failed = true ;
215
- console . log ( '>>> \033[1;31mfail: ' + err . toString ( ) + '\033[0m' ) ;
218
+ console . log ( '\n >>> \033[1;31mfail: ' + err . toString ( ) + '\033[0m' ) ;
216
219
} ) . fin ( function ( ) {
217
220
runTests ( i + 1 ) ;
218
221
} ) . done ( ) ;
0 commit comments