1515# limitations under the License.
1616
1717import glob
18+ import io
1819import os
1920import subprocess
2021import sys
2122import unittest
22- from multiprocessing .pool import ThreadPool
2323from collections import OrderedDict
24+ from multiprocessing .pool import ThreadPool
2425from pathlib import Path
25- import io
2626
27- from scripts .test import binaryenjs
28- from scripts .test import lld
29- from scripts .test import shared
30- from scripts .test import support
31- from scripts .test import wasm2js
32- from scripts .test import wasm_opt
27+ from scripts .test import binaryenjs , lld , shared , support , wasm2js , wasm_opt
3328
3429
3530def get_changelog_version ():
@@ -38,7 +33,7 @@ def get_changelog_version():
3833 lines = [line for line in lines if len (line .split ()) == 1 ]
3934 lines = [line for line in lines if line .startswith ('v' )]
4035 version = lines [0 ][1 :]
41- print ("Parsed CHANGELOG.md version: %s" % version )
36+ print (f "Parsed CHANGELOG.md version: { version } " )
4237 return int (version )
4338
4439
@@ -52,16 +47,16 @@ def run_version_tests():
5247 not any (f .endswith (s ) for s in not_executable_suffix ) and
5348 any (os .path .basename (f ).startswith (s ) for s in executable_prefix )]
5449 executables = sorted (executables )
55- assert len ( executables )
50+ assert executables
5651
5752 changelog_version = get_changelog_version ()
5853 for e in executables :
59- print ('.. %s --version' % e )
54+ print (f '.. { e } --version' )
6055 proc = subprocess .run ([e , '--version' ], capture_output = True , text = True )
61- assert len (proc .stderr ) == 0 , 'Expected no stderr, got:\n %s' % proc .stderr
56+ assert len (proc .stderr ) == 0 , f 'Expected no stderr, got:\n { proc .stderr } '
6257 out = proc .stdout
63- assert os .path .basename (e ).replace ('.exe' , '' ) in out , 'Expected version to contain program name, got:\n %s' % out
64- assert len (out .strip ().splitlines ()) == 1 , 'Expected only version info, got:\n %s' % out
58+ assert os .path .basename (e ).replace ('.exe' , '' ) in out , f 'Expected version to contain program name, got:\n { out } '
59+ assert len (out .strip ().splitlines ()) == 1 , f 'Expected only version info, got:\n { out } '
6560 parts = out .split ()
6661 assert parts [1 ] == 'version'
6762 version = int (parts [2 ])
@@ -155,7 +150,8 @@ def run_wasm_reduce_tests():
155150 print ('..' , os .path .basename (t ))
156151 # convert to wasm
157152 support .run_command (shared .WASM_AS + [t , '-o' , 'a.wasm' , '-all' ])
158- support .run_command (shared .WASM_REDUCE + ['a.wasm' , '--command=%s b.wasm --fuzz-exec -all ' % shared .WASM_OPT [0 ], '-t' , 'b.wasm' , '-w' , 'c.wasm' , '--timeout=4' ])
153+ cmd = shared .WASM_OPT [0 ]
154+ support .run_command (shared .WASM_REDUCE + ['a.wasm' , f'--command={ cmd } b.wasm --fuzz-exec -all ' , '-t' , 'b.wasm' , '-w' , 'c.wasm' , '--timeout=4' ])
159155 expected = t + '.txt'
160156 support .run_command (shared .WASM_DIS + ['c.wasm' , '-o' , 'a.wat' ])
161157 with open ('a.wat' ) as seen :
@@ -168,14 +164,15 @@ def run_wasm_reduce_tests():
168164 # TODO: re-enable multivalue once it is better optimized
169165 support .run_command (shared .WASM_OPT + [os .path .join (shared .options .binaryen_test , 'lit/basic/signext.wast' ), '-ttf' , '-Os' , '-o' , 'a.wasm' , '--detect-features' , '--disable-multivalue' ])
170166 before = os .stat ('a.wasm' ).st_size
171- support .run_command (shared .WASM_REDUCE + ['a.wasm' , '--command=%s b.wasm --fuzz-exec --detect-features' % shared .WASM_OPT [0 ], '-t' , 'b.wasm' , '-w' , 'c.wasm' ])
167+ cmd = shared .WASM_OPT [0 ]
168+ support .run_command (shared .WASM_REDUCE + ['a.wasm' , f'--command={ cmd } b.wasm --fuzz-exec --detect-features' , '-t' , 'b.wasm' , '-w' , 'c.wasm' ])
172169 after = os .stat ('c.wasm' ).st_size
173170 # This number is a custom threshold to check if we have shrunk the
174171 # output sufficiently
175172 assert after < 0.85 * before , [before , after ]
176173
177174
178- def run_spec_test (wast , stdout = None , stderr = None ):
175+ def run_spec_test (wast , stdout = None ):
179176 cmd = shared .WASM_SHELL + [wast ]
180177 output = support .run_command (cmd , stdout = stdout , stderr = subprocess .PIPE )
181178 # filter out binaryen interpreter logging that the spec suite
@@ -184,7 +181,7 @@ def run_spec_test(wast, stdout=None, stderr=None):
184181 return '\n ' .join (filtered ) + '\n '
185182
186183
187- def run_opt_test (wast , stdout = None , stderr = None ):
184+ def run_opt_test (wast , stdout = None ):
188185 # check optimization validation
189186 cmd = shared .WASM_OPT + [wast , '-O' , '-all' , '-q' ]
190187 support .run_command (cmd , stdout = stdout )
@@ -200,7 +197,7 @@ def check_expected(actual, expected, stdout=None):
200197 shared .fail (actual , expected )
201198
202199
203- def run_one_spec_test (wast : Path , stdout = None , stderr = None ):
200+ def run_one_spec_test (wast : Path , stdout = None ):
204201 test_name = wast .name
205202
206203 # /path/to/binaryen/test/spec/foo.wast -> test-spec-foo
@@ -215,7 +212,7 @@ def run_one_spec_test(wast: Path, stdout=None, stderr=None):
215212
216213 # some spec tests should fail (actual process failure, not just assert_invalid)
217214 try :
218- actual = run_spec_test (str (wast ), stdout = stdout , stderr = stderr )
215+ actual = run_spec_test (str (wast ), stdout = stdout )
219216 except Exception as e :
220217 if ('wasm-validator error' in str (e ) or 'error: ' in str (e )) and '.fail.' in test_name :
221218 print ('<< test failed as expected >>' , file = stdout )
@@ -237,23 +234,23 @@ def run_one_spec_test(wast: Path, stdout=None, stderr=None):
237234 print (f' testing split module { i } ' , file = stdout )
238235 split_name = base_name + f'_split{ i } .wast'
239236 support .write_wast (split_name , module )
240- run_opt_test (split_name , stdout = stdout , stderr = stderr ) # also that our optimizer doesn't break on it
237+ run_opt_test (split_name , stdout = stdout ) # also that our optimizer doesn't break on it
241238
242- result_wast_file = shared .binary_format_check (split_name , verify_final_result = False , base_name = base_name , stdout = stdout , stderr = stderr )
239+ result_wast_file = shared .binary_format_check (split_name , verify_final_result = False , base_name = base_name , stdout = stdout )
243240 with open (result_wast_file ) as f :
244241 result_wast = f .read ()
245242 # add the asserts, and verify that the test still passes
246243 transformed_spec_file .write (result_wast + '\n ' + '\n ' .join (asserts ))
247244
248245 # compare all the outputs to the expected output
249- actual = run_spec_test (transformed_path , stdout = stdout , stderr = stderr )
246+ actual = run_spec_test (transformed_path , stdout = stdout )
250247 check_expected (actual , os .path .join (shared .get_test_dir ('spec' ), 'expected-output' , test_name + '.log' ), stdout = stdout )
251248
252249
253250def run_spec_test_with_wrapped_stdout (wast : Path ):
254251 out = io .StringIO ()
255252 try :
256- run_one_spec_test (wast , stdout = out , stderr = out )
253+ run_one_spec_test (wast , stdout = out )
257254 except Exception as e :
258255 # Serialize exceptions into the output string buffer
259256 # so they can be reported on the main thread.
@@ -412,7 +409,7 @@ def main():
412409
413410 for r in shared .requested :
414411 if r not in all_suites :
415- print ('invalid test suite: %s (see --list-suites)\n ' % r )
412+ print (f 'invalid test suite: { r } (see --list-suites)\n ' )
416413 return 1
417414
418415 if not shared .requested :
0 commit comments