1515# limitations under the License.
1616
1717import glob
18+ import io
1819import os
20+ import queue
1921import subprocess
2022import sys
23+ import threading
2124import unittest
2225from collections import OrderedDict
2326from concurrent .futures import ThreadPoolExecutor
24- from pathlib import Path
25- import queue
26- import io
27- import threading
2827from functools import partial
28+ from pathlib import Path
2929
30- from scripts .test import binaryenjs
31- from scripts .test import lld
32- from scripts .test import shared
33- from scripts .test import support
34- from scripts .test import wasm2js
35- from scripts .test import wasm_opt
30+ from scripts .test import binaryenjs , lld , shared , support , wasm2js , wasm_opt
3631
3732
3833def get_changelog_version ():
@@ -41,7 +36,7 @@ def get_changelog_version():
4136 lines = [line for line in lines if len (line .split ()) == 1 ]
4237 lines = [line for line in lines if line .startswith ('v' )]
4338 version = lines [0 ][1 :]
44- print ("Parsed CHANGELOG.md version: %s" % version )
39+ print (f "Parsed CHANGELOG.md version: { version } " )
4540 return int (version )
4641
4742
@@ -55,16 +50,16 @@ def run_version_tests():
5550 not any (f .endswith (s ) for s in not_executable_suffix ) and
5651 any (os .path .basename (f ).startswith (s ) for s in executable_prefix )]
5752 executables = sorted (executables )
58- assert len ( executables )
53+ assert executables
5954
6055 changelog_version = get_changelog_version ()
6156 for e in executables :
62- print ('.. %s --version' % e )
57+ print (f '.. { e } --version' )
6358 proc = subprocess .run ([e , '--version' ], capture_output = True , text = True )
64- assert len (proc .stderr ) == 0 , 'Expected no stderr, got:\n %s' % proc .stderr
59+ assert len (proc .stderr ) == 0 , f 'Expected no stderr, got:\n { proc .stderr } '
6560 out = proc .stdout
66- assert os .path .basename (e ).replace ('.exe' , '' ) in out , 'Expected version to contain program name, got:\n %s' % out
67- assert len (out .strip ().splitlines ()) == 1 , 'Expected only version info, got:\n %s' % out
61+ assert os .path .basename (e ).replace ('.exe' , '' ) in out , f 'Expected version to contain program name, got:\n { out } '
62+ assert len (out .strip ().splitlines ()) == 1 , f 'Expected only version info, got:\n { out } '
6863 parts = out .split ()
6964 assert parts [1 ] == 'version'
7065 version = int (parts [2 ])
@@ -158,7 +153,8 @@ def run_wasm_reduce_tests():
158153 print ('..' , os .path .basename (t ))
159154 # convert to wasm
160155 support .run_command (shared .WASM_AS + [t , '-o' , 'a.wasm' , '-all' ])
161- 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' ])
156+ cmd = shared .WASM_OPT [0 ]
157+ support .run_command (shared .WASM_REDUCE + ['a.wasm' , f'--command={ cmd } b.wasm --fuzz-exec -all ' , '-t' , 'b.wasm' , '-w' , 'c.wasm' , '--timeout=4' ])
162158 expected = t + '.txt'
163159 support .run_command (shared .WASM_DIS + ['c.wasm' , '-o' , 'a.wat' ])
164160 with open ('a.wat' ) as seen :
@@ -171,14 +167,15 @@ def run_wasm_reduce_tests():
171167 # TODO: re-enable multivalue once it is better optimized
172168 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' ])
173169 before = os .stat ('a.wasm' ).st_size
174- 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' ])
170+ cmd = shared .WASM_OPT [0 ]
171+ support .run_command (shared .WASM_REDUCE + ['a.wasm' , f'--command={ cmd } b.wasm --fuzz-exec --detect-features' , '-t' , 'b.wasm' , '-w' , 'c.wasm' ])
175172 after = os .stat ('c.wasm' ).st_size
176173 # This number is a custom threshold to check if we have shrunk the
177174 # output sufficiently
178175 assert after < 0.85 * before , [before , after ]
179176
180177
181- def run_spec_test (wast , stdout = None , stderr = None ):
178+ def run_spec_test (wast , stdout = None , _stderr = None ):
182179 cmd = shared .WASM_SHELL + [wast ]
183180 output = support .run_command (cmd , stdout = stdout , stderr = subprocess .PIPE )
184181 # filter out binaryen interpreter logging that the spec suite
@@ -187,7 +184,7 @@ def run_spec_test(wast, stdout=None, stderr=None):
187184 return '\n ' .join (filtered ) + '\n '
188185
189186
190- def run_opt_test (wast , stdout = None , stderr = None ):
187+ def run_opt_test (wast , stdout = None , _stderr = None ):
191188 # check optimization validation
192189 cmd = shared .WASM_OPT + [wast , '-O' , '-all' , '-q' ]
193190 support .run_command (cmd , stdout = stdout )
@@ -242,7 +239,7 @@ def run_one_spec_test(wast: Path, stdout=None, stderr=None):
242239 support .write_wast (split_name , module )
243240 run_opt_test (split_name , stdout = stdout , stderr = stderr ) # also that our optimizer doesn't break on it
244241
245- result_wast_file = shared .binary_format_check (split_name , verify_final_result = False , base_name = base_name , stdout = stdout , stderr = stderr )
242+ result_wast_file = shared .binary_format_check (split_name , verify_final_result = False , base_name = base_name , stdout = stdout )
246243 with open (result_wast_file ) as f :
247244 result_wast = f .read ()
248245 # add the asserts, and verify that the test still passes
@@ -437,7 +434,7 @@ def main():
437434
438435 for r in shared .requested :
439436 if r not in all_suites :
440- print ('invalid test suite: %s (see --list-suites)\n ' % r )
437+ print (f 'invalid test suite: { r } (see --list-suites)\n ' )
441438 return 1
442439
443440 if not shared .requested :
0 commit comments