@@ -3,9 +3,22 @@ require('shelljs/global');
3
3
4
4
var TEST_DIR = 'scripts' ;
5
5
6
+ var shouldLog = ( process . argv [ 2 ] === 'log' ) ;
7
+ var log = [ ] ;
8
+
9
+ function writeLog ( msg , link ) {
10
+ console . log ( msg ) ;
11
+ if ( link ) {
12
+ msg = msg . replace ( ']' , '](' + link + ')' ) ;
13
+ }
14
+ log . push ( msg ) ;
15
+ }
16
+
6
17
cd ( __dirname + '/' + TEST_DIR ) ;
18
+ var prefix ;
7
19
ls ( ) . forEach ( function ( dir ) {
8
- echo ( dir )
20
+ prefix = TEST_DIR + '/' + dir ;
21
+ writeLog ( '### [' + dir + ']' , prefix )
9
22
cd ( dir )
10
23
11
24
// Find the files
@@ -31,28 +44,37 @@ ls().forEach(function (dir) {
31
44
js_output = exec ( 'node ' + jsfile ) . output ;
32
45
end_time = new Date ( ) . getTime ( ) ;
33
46
js_time = end_time - start_time ;
34
- echo ( '> ShellJS took ' + js_time + ' milliseconds' ) ;
47
+ writeLog ( ' - [ ShellJS] took ` ' + js_time + '` milliseconds' , prefix + '/' + jsfile ) ;
35
48
36
49
start_time = new Date ( ) . getTime ( ) ;
37
50
shell_output = exec ( 'bash ' + shfile ) . output ;
38
51
end_time = new Date ( ) . getTime ( ) ;
39
52
shell_time = end_time - start_time ;
40
- echo ( '> Bash took ' + shell_time + ' milliseconds' ) ;
53
+ writeLog ( ' - [ Bash] took ` ' + shell_time + '` milliseconds' , prefix + '/' + shfile ) ;
41
54
42
55
if ( shell_time < js_time ) {
43
- echo ( 'Bash won' ) ;
44
- echo ( 'Bash was ' + ( js_time / shell_time ) . toFixed ( 3 ) + ' times faster than ShellJS' ) ;
56
+ writeLog ( 'Bash was `' + ( js_time / shell_time ) . toFixed ( 3 ) +
9E7A
9;` times faster than ShellJS' ) ;
45
57
} else {
46
- echo ( 'ShellJS won!!' ) ;
47
- echo ( 'ShellJS was ' + ( shell_time / js_time ) . toFixed ( 3 ) + ' times faster than Bash' ) ;
58
+ writeLog ( 'ShellJS was `' + ( shell_time / js_time ) . toFixed ( 3 ) + '` times faster than Bash' ) ;
48
59
}
49
60
50
61
if ( shell_output !== js_output )
51
- echo ( 'Output differs' ) ;
62
+ writeLog ( 'Output differs' ) ;
52
63
53
64
// Clean up
54
65
echo ( '=======================' ) ;
55
66
echo ( ) ;
56
67
config . silent = false ;
57
68
cd ( '..' )
58
69
} ) ;
70
+
71
+ if ( shouldLog ) {
72
+ cd ( __dirname ) ;
73
+ var text = log . join ( '\n\n' ) ;
74
+
75
+ // Wipe out the old results
76
+ cat ( 'README.md' ) . replace ( / # # R e s u l t s ( .| \n ) * / , '## Results' ) . to ( 'README.md' ) ;
77
+
78
+ // Append new docs to README
79
+ sed ( '-i' , / # # R e s u l t s / , '## Results\n\n' + text , 'README.md' ) ;
80
+ }
0 commit comments