77import sys
88import os
99import subprocess as SP
10- import argparse , textwrap
10+ import argparse
1111import xml .etree .ElementTree as ET
1212
13+ # handle command line args
1314parser = argparse .ArgumentParser (
1415 description = 'ChakraCore *nix Test Script' ,
1516 formatter_class = argparse .RawDescriptionHelpFormatter ,
16- epilog = textwrap . dedent ( '''\
17- Samples:
17+ epilog = '''\
18+ Samples:
1819
19- test all folders:
20- {0}
20+ test all folders:
21+ {0}
2122
22- test only Array:
23- {0} Array
23+ test only Array:
24+ {0} Array
25+
26+ test a single file:
27+ {0} Basics/hello.js
28+ ''' .format (sys .argv [0 ]))
2429
25- test a single file:
26- {0} Basics/hello.js
27- ''' .format (sys .argv [0 ]))
28- )
2930parser .add_argument ('folders' , metavar = 'folder' , nargs = '*' ,
3031 help = 'folder subset to run tests' )
31- parser .add_argument ('-b' , '--binary' , metavar = 'binary ' , help = 'ch full path' );
32+ parser .add_argument ('-b' , '--binary' , metavar = 'bin ' , help = 'ch full path' )
3233parser .add_argument ('-d' , '--debug' , action = 'store_true' ,
3334 help = 'use debug build' );
34- parser .add_argument ('-t' , '--test' , action = 'store_true' , help = 'use test build' );
35- parser .add_argument ('--x86' , action = 'store_true' , help = 'use x86 build' );
36- parser .add_argument ('--x64' , action = 'store_true' , help = 'use x64 build' );
35+ parser .add_argument ('-t' , '--test' , action = 'store_true' , help = 'use test build' )
36+ parser .add_argument ('--x86' , action = 'store_true' , help = 'use x86 build' )
37+ parser .add_argument ('--x64' , action = 'store_true' , help = 'use x64 build' )
3738args = parser .parse_args ()
3839
3940
4647 arch = os .environ .get ('_BuildArch' , 'x86' )
4748
4849# flavor: debug, test, release
50+ type_flavor = {'chk' :'debug' , 'test' :'test' , 'fre' :'release' }
4951flavor = 'debug' if args .debug else ('test' if args .test else None )
5052if flavor == None :
51- flavor = {'chk' :'debug' , 'test' :'test' , 'fre' :'release' }\
52- [os .environ .get ('_BuildType' , 'fre' )]
53+ flavor = type_flavor [os .environ .get ('_BuildType' , 'fre' )]
5354
5455# binary: full ch path
5556binary = args .binary
5657if binary == None :
5758 if sys .platform == 'win32' :
58- binary = os .path .join (repo_root ,
59- 'Build/VcBuild/bin/{}_{}/ch.exe' .format (arch , flavor ))
59+ binary = 'Build/VcBuild/bin/{}_{}/ch.exe' .format (arch , flavor )
6060 else :
61- binary = os .path .join (repo_root , "BuildLinux/ch" )
61+ binary = 'BuildLinux/ch'
62+ binary = os .path .join (repo_root , binary )
6263if not os .path .isfile (binary ):
63- print '{} not found. Did you run ./build.sh already?' .format (binary )
64+ print ( '{} not found. Did you run ./build.sh already?' .format (binary ) )
6465 sys .exit (1 )
6566
66- pass_count = 0
67- fail_count = 0
67+
68+ # records pass_count/fail_count
69+ class PassFailCount (object ):
70+ def __init__ (self ):
71+ self .pass_count = 0
72+ self .fail_count = 0
73+
74+ def print_summary (self , label = None ):
75+ label = label + ': ' if label else ''
76+ print ('{}passed {}, failed {}' .format (
77+ label , self .pass_count , self .fail_count ))
78+
79+ # records total and individual folder's pass_count/fail_count
80+ class TestResult (PassFailCount ):
81+ def __init__ (self ):
82+ super (self .__class__ , self ).__init__ ()
83+ self .folders = {}
84+
85+ def _get_folder_result (self , folder ):
86+ r = self .folders .get (folder )
87+ if not r :
88+ r = PassFailCount ()
89+ self .folders [folder ] = r
90+ return r
91+
92+ def log (self , filename = None , folder = None , fail = False ):
93+ if not folder :
94+ folder = os .path .basename (os .path .dirname (filename ))
95+ r = self ._get_folder_result (folder )
96+ if fail :
97+ r .fail_count += 1
98+ self .fail_count += 1
99+ else :
100+ r .pass_count += 1
101+ self .pass_count += 1
102+
103+ test_result = TestResult ()
104+
68105
69106def show_failed (filename , output , exit_code , expected_output ):
70- print "\n Failed ->" , filename
107+ print ( "\n Failed ->" , filename )
71108 if expected_output == None :
72- print "\n Output:"
73- print "----------------------------"
74- print output
75- print "----------------------------"
109+ print ( "\n Output:" )
110+ print ( "----------------------------" )
111+ print ( output )
112+ print ( "----------------------------" )
76113 else :
77114 lst_output = output .split ('\n ' )
78115 lst_expected = expected_output .split ('\n ' )
79116 ln = min (len (lst_output ), len (lst_expected ))
80117 for i in range (0 , ln ):
81118 if lst_output [i ] != lst_expected [i ]:
82- print "Output: (at line " + str (i ) + ")"
83- print "----------------------------"
84- print lst_output [i ]
85- print "----------------------------"
86- print "Expected Output:"
87- print "----------------------------"
88- print lst_expected [i ]
89- print "----------------------------"
119+ print ( "Output: (at line " + str (i ) + ")" )
120+ print ( "----------------------------" )
121+ print ( lst_output [i ])
122+ print ( "----------------------------" )
123+ print ( "Expected Output:" )
124+ print ( "----------------------------" )
125+ print ( lst_expected [i ])
126+ print ( "----------------------------" )
90127 break
91128
92- print "exit code:" , exit_code
93- global fail_count
94- fail_count += 1
129+ print ("exit code:" , exit_code )
130+ test_result .log (filename , fail = True )
95131
96132def test_path (path ):
97133 if os .path .isfile (path ):
@@ -103,19 +139,18 @@ def test_path(path):
103139 if len (tests ) == 0 :
104140 return
105141
106- print "Testing ->" , os .path .basename (folder )
142+ print ( "Testing ->" + os .path .basename (folder ) )
107143 for test in tests :
108144 test_one (folder , test )
109145
110146def test_one (folder , test ):
111147 js_file = os .path .join (folder , test ['files' ])
112148 js_output = ""
113149
114- cmd = [x for x in [binary ,
115- '-WERExceptionSupport' ,
116- '-ExtendedErrorStackForTestHost' ,
117- test .get ('compile-flags' ),
118- js_file ] if x != None ]
150+ flags = test .get ('compile-flags' )
151+ cmd = [binary , '-WERExceptionSupport' , '-ExtendedErrorStackForTestHost' ] \
152+ + (flags .split () if flags else []) \
153+ + [js_file ]
119154 p = SP .Popen (cmd , stdout = SP .PIPE , stderr = SP .STDOUT )
120155 js_output = p .communicate ()[0 ].replace ('\r ' ,'' )
121156 exit_code = p .wait ()
@@ -133,9 +168,8 @@ def test_one(folder, test):
133168 if expected_output .replace ('\n ' , '' ) != js_output .replace ('\n ' , '' ):
134169 return show_failed (js_file , js_output , exit_code , expected_output )
135170
136- print "\t Passed ->" , os .path .basename (js_file )
137- global pass_count
138- pass_count += 1
171+ print ("\t Passed ->" + os .path .basename (js_file ))
172+ test_result .log (folder = folder )
139173
140174def load_tests (folder , file ):
141175 try :
@@ -169,8 +203,13 @@ def main():
169203 for folder in args .folders :
170204 test_path (folder )
171205
172- print 'Passed:' , pass_count , 'Failed:' , fail_count
173- print 'Success!' if fail_count == 0 else 'Failed!'
206+ print ('\n ' )
207+ print ("============================" )
208+ for folder , result in sorted (test_result .folders .items ()):
209+ result .print_summary (folder )
210+ print ("============================" )
211+ test_result .print_summary ('Total' )
212+ print ('Success!' if test_result .fail_count == 0 else 'Failed!' )
174213 return 0
175214
176215if __name__ == '__main__' :
0 commit comments