1717from __future__ import print_function
1818import argparse
1919import os
20+ import re
2021import shutil
2122import subprocess
2223import sys
@@ -41,8 +42,10 @@ def get_arguments():
4142 group = parser .add_mutually_exclusive_group (required = True )
4243 group .add_argument ('--es51' , action = 'store_true' ,
4344 help = 'Run test262 ES5.1 version' )
44- group .add_argument ('--es2015' , action = 'store_true' ,
45- help = 'Run test262 ES2015 version' )
45+ group .add_argument ('--es2015' , default = False , const = 'default' ,
46+ nargs = '?' , choices = ['default' , 'all' , 'update' ],
47+ help = 'Run test262 - ES2015. default: all tests except excludelist, ' +
48+ 'all: all tests, update: all tests and update excludelist' )
4649
4750 args = parser .parse_args ()
4851
@@ -75,15 +78,11 @@ def prepare_test262_test_suite(args):
7578 return return_code
7679
7780 if args .es2015 :
78- shutil .copyfile (os .path .join ('tests' , 'test262-es6-excludelist.xml' ),
79- os .path .join (args .test_dir , 'excludelist.xml' ))
80-
8181 return_code = subprocess .call (['git' , 'apply' , os .path .join ('..' , '..' , 'test262-es6.patch' )],
8282 cwd = args .test_dir )
8383 if return_code :
8484 print ('Applying test262-es6.patch failed' )
8585 return return_code
86-
8786 else :
8887 path_to_remove = os .path .join (args .test_dir , 'test' , 'suite' , 'bestPractice' )
8988 if os .path .isdir (path_to_remove ):
@@ -95,19 +94,93 @@ def prepare_test262_test_suite(args):
9594
9695 return 0
9796
97+
98+ def update_exclude_list (args ):
99+ assert args .es2015 == 'update' , "Only --es2015 option supports updating excludelist"
100+
101+ print ("=== Summary - updating excludelist ===\n " )
102+ failing_tests = set ()
103+ new_passing_tests = set ()
104+ with open (os .path .join (os .path .dirname (args .engine ), 'test262.report' ), 'r' ) as report_file :
105+ summary_found = False
106+ for line in report_file :
107+ if summary_found :
108+ match = re .match (r" (\S*) " , line )
109+ if match :
110+ failing_tests .add (match .group (1 ) + '.js' )
111+ elif line .startswith ('Failed Tests' ):
112+ summary_found = True
113+
114+ with open (os .path .join ('tests' , 'test262-es6-excludelist.xml' ), 'r+' ) as exclude_file :
115+ lines = exclude_file .readlines ()
116+ exclude_file .seek (0 )
117+ exclude_file .truncate ()
118+ exclude_file .write ('<?xml version="1.0" encoding="utf-8" ?>\n ' )
119+ exclude_file .write ('<excludeList>\n ' )
120+
121+ for line in lines :
122+ match = re .match (r" <test id=\"(\S*)\">" , line )
123+ if match :
124+ test = match .group (1 )
125+ if test in failing_tests :
126+ failing_tests .remove (test )
127+ exclude_file .write (line )
128+ else :
129+ new_passing_tests .add (test )
130+
131+ if failing_tests :
132+ print ("New failing tests added to the excludelist" )
133+ for test in sorted (failing_tests ):
134+ exclude_file .write (' <test id="' + test + '"><reason></reason></test>\n ' )
135+ print (" " + test )
136+ print ("" )
137+
138+ exclude_file .write ('</excludeList>\n ' )
139+
140+ if new_passing_tests :
141+ print ("New passing tests removed from the excludelist" )
142+ for test in sorted (new_passing_tests ):
143+ print (" " + test )
144+ print ("" )
145+
146+ if failing_tests or new_passing_tests :
147+ print ("Excludelist was updated succesfully." )
148+ return 1
149+
150+ print ("Excludelist was already up-to-date." )
151+ return 0
152+
153+
98154def main (args ):
99155 return_code = prepare_test262_test_suite (args )
100156 if return_code :
101157 return return_code
102158
159+ if args .es2015 == 'all' or args .es2015 == 'update' :
160+ return_code = subprocess .call (['git' , 'checkout' , 'excludelist.xml' ], cwd = args .test_dir )
161+ if return_code :
162+ print ('Reverting excludelist.xml failed' )
163+ return return_code
164+ elif args .es2015 == 'default' :
165+ shutil .copyfile (os .path .join ('tests' , 'test262-es6-excludelist.xml' ),
166+ os .path .join (args .test_dir , 'excludelist.xml' ))
167+
103168 if sys .platform == 'win32' :
104169 original_timezone = util .get_timezone ()
105170 util .set_sighdl_to_reset_timezone (original_timezone )
106171 util .set_timezone ('Pacific Standard Time' )
107172
173+ command = args .engine
174+ if args .es2015 :
175+ try :
176+ subprocess .check_output (["timeout" , "--version" ])
177+ command = "timeout 3 " + args .engine
178+ except subprocess .CalledProcessError :
179+ pass
180+
108181 proc = subprocess .Popen (get_platform_cmd_prefix () +
109182 [os .path .join (args .test_dir , 'tools/packaging/test262.py' ),
110- '--command' , ( args . runtime + ' ' + args . engine ). strip () ,
183+ '--command' , command ,
111184 '--tests' , args .test_dir ,
112185 '--summary' ],
113186 universal_newlines = True ,
@@ -140,6 +213,9 @@ def main(args):
140213 if sys .platform == 'win32' :
141214 util .set_timezone (original_timezone )
142215
216+ if args .es2015 == 'update' :
217+ return_code = update_exclude_list (args )
218+
143219 return return_code
144220
145221
0 commit comments