@@ -31,9 +31,11 @@ PhpjsUtil.opener = function (name, cb) {
31
31
} ) ;
32
32
} ;
33
33
34
+ // --debug works out of the box. See -h
34
35
cli . parse ( {
35
36
name : [ 'name' , 'Function name to test' , 'path' , '*' ] ,
36
- category : [ 'c' , 'Category to test' , 'path' , '*' ]
37
+ category : [ 'c' , 'Category to test' , 'path' , '*' ] ,
38
+ abort : [ 'a' , 'Abort on first failure' ]
37
39
} ) ;
38
40
39
41
cli . pad = function ( str , pad , chr , dir ) {
@@ -55,8 +57,18 @@ cli.pad = function(str, pad, chr, dir) {
55
57
var width = 120 ;
56
58
57
59
cli . main ( function ( args , options ) {
60
+ var self = this ;
58
61
var globpath = __dirname + '/../functions/' + options . category + '/' + options . name + '.js' ;
59
62
63
+ process . on ( 'exit' , function ( ) {
64
+ var msg = self . pass_cnt + ' passed / ' + self . fail_cnt + ' failed / ' + self . skip_cnt + ' skipped' ;
65
+ if ( self . fail_cnt ) {
66
+ cli . fatal ( msg ) ;
67
+ } else {
68
+ cli . ok ( msg ) ;
69
+ }
70
+ } ) ;
71
+
60
72
glob ( globpath , { } , function ( err , files ) {
61
73
var names = [ ] ;
62
74
for ( var i in files ) {
@@ -66,41 +78,32 @@ cli.main(function(args, options) {
66
78
}
67
79
}
68
80
69
- // cli.spinner('Working..');
70
- var processed = 0 ;
81
+ self . pass_cnt = 0 ;
82
+ self . fail_cnt = 0 ;
83
+ self . skip_cnt = 0 ;
84
+
71
85
names . forEach ( function ( name ) {
72
86
PhpjsUtil . load ( name , function ( err , params ) {
73
87
if ( err ) {
74
88
return cli . fatal ( err ) ;
75
89
}
76
90
77
91
if ( params [ 'headKeys' ] [ 'test' ] && params [ 'headKeys' ] [ 'test' ] [ 0 ] === 'skip' ) {
78
- return cli . ok ( 'Skipped ' + params [ 'name' ] ) ;
92
+ self . skip_cnt ++ ;
93
+ return cli . info ( '--> ' + params [ 'name' ] + ' skipped as instructed. ' ) ;
79
94
}
80
95
81
96
PhpjsUtil . test ( params , function ( err , test , params ) {
82
- var testline = cli . pad ( params [ 'name' ] + '#' + test [ 'number' ] , ( width * 0.4 ) , ' ' , 'right' ) ;
83
- testline += ' ' + cli . pad ( test [ 'example' ] , ( width * 0.6 - 7 ) ) ;
84
-
85
- if ( err ) {
86
- if ( 'expected' in test ) {
87
- testline += '\n expected' + cli . pad ( JSON . stringify ( test [ 'expected' ] , undefined , 2 ) . replace ( / \n / g, '' ) , width - 8 ) ;
88
- } else {
89
- testline += '\n expected' + cli . pad ( 'undefined' , width - 8 ) ;
90
- }
91
- if ( 'result' in test ) {
92
- testline += '\n result ' + cli . pad ( JSON . stringify ( test [ 'result' ] , undefined , 2 ) . replace ( / \n / g, '' ) , width - 8 ) ;
93
- } else {
94
- testline += '\n result ' + cli . pad ( 'undefined' , width - 8 ) ;
95
- }
96
- cli . error ( testline + '' ) ;
97
- // cli.error(err);
97
+ if ( ! err ) {
98
+ self . pass_cnt ++ ;
99
+ cli . debug ( '--> ' + params [ 'name' ] + '#' + test [ 'number' ] + ' passed. ' ) ;
98
100
} else {
99
- cli . ok ( ' ' + testline + '' ) ;
100
- }
101
-
102
- if ( ++ processed === names . length ) {
103
- cli . spinner ( 'Working.. done!' , true ) ; //End the spinner
101
+ self . fail_cnt ++ ;
102
+ cli . error ( '--> ' + params [ 'name' ] + '#' + test [ 'number' ] + ' failed. ' ) ;
103
+ cli . error ( err ) ;
104
+ if ( options . abort ) {
105
+ cli . fatal ( 'Aborting on first failure as instructed. ' ) ;
106
+ }
104
107
}
105
108
} ) ;
106
109
} ) ;
0 commit comments