@@ -50,11 +50,9 @@ def for_all_files(dir, callback):
5050# restore the config file and set it up for our uses
5151def restore_and_set_up ():
5252 restore ()
53- with open (EM_CONFIG , 'a' ) as f :
54- # make LLVM_ROOT sensitive to the LLVM env var, as we test that
55- f .write ('LLVM_ROOT = "%s"\n ' % config .LLVM_ROOT )
56- # unfreeze the cache, so we can test that
57- f .write ('FROZEN_CACHE = False\n ' )
53+ # make LLVM_ROOT sensitive to the LLVM env var, as we test that
54+ add_to_config ('LLVM_ROOT = "%s"' % config .LLVM_ROOT )
55+ add_to_config ('FROZEN_CACHE = False' )
5856
5957
6058# wipe the config and sanity files, creating a blank slate
@@ -64,7 +62,7 @@ def wipe():
6462
6563
6664def add_to_config (content ):
67- with open (EM_CONFIG , 'a' ) as f :
65+ with open (EM_CONFIG , 'a' , encoding = 'utf-8' ) as f :
6866 f .write ('\n ' + content + '\n ' )
6967
7068
@@ -658,11 +656,10 @@ def test_vanilla(self):
658656 self .clear_cache ()
659657
660658 def make_fake (report ):
661- with open (EM_CONFIG , 'a' ) as f :
662- f .write ('LLVM_ROOT = "' + self .in_dir ('fake' , 'bin' ) + '"\n ' )
663- # BINARYEN_ROOT needs to exist in the config, even though this test
664- # doesn't actually use it.
665- f .write ('BINARYEN_ROOT = "%s"\n ' % self .in_dir ('fake' , 'bin' ))
659+ add_to_config ('LLVM_ROOT = "%s"' % self .in_dir ('fake' , 'bin' ))
660+ # BINARYEN_ROOT needs to exist in the config, even though this test
661+ # doesn't actually use it.
662+ add_to_config ('BINARYEN_ROOT = "%s"' % self .in_dir ('fake' , 'bin' ))
666663
667664 make_fake_clang (self .in_dir ('fake' , 'bin' , 'clang' ), expected_llvm_version , report )
668665 make_fake_tool (self .in_dir ('fake' , 'bin' , 'wasm-ld' ), expected_llvm_version )
@@ -703,10 +700,10 @@ def test_required_config_settings(self):
703700 env = os .environ .copy ()
704701 env ['PATH' ] = path_without_tool (env ['PATH' ], 'wasm-opt' )
705702
706- open ( EM_CONFIG , 'a' ). write ( ' \n BINARYEN_ROOT = ""\n ' )
703+ add_to_config ( 'BINARYEN_ROOT = ""' )
707704 self .check_working ([EMCC , test_file ('hello_world.c' )], 'BINARYEN_ROOT is set to empty value in %s' % EM_CONFIG , env = env )
708705
709- open ( EM_CONFIG , 'a' ). write ( ' \n del BINARYEN_ROOT\n ' )
706+ add_to_config ( 'del BINARYEN_ROOT' )
710707 self .check_working ([EMCC , test_file ('hello_world.c' )], 'BINARYEN_ROOT not set in config (%s), and `wasm-opt` not found in PATH' % EM_CONFIG , env = env )
711708
712709 @no_windows ('Test relies on Unix-specific make_fake_tool' )
@@ -811,8 +808,7 @@ def test_embuilder_transitive_pic(self):
811808 @no_windows ('Test relies on Unix-specific make_fake_tool' )
812809 def test_binaryen_version (self ):
813810 restore_and_set_up ()
814- with open (EM_CONFIG , 'a' ) as f :
815- f .write ('\n BINARYEN_ROOT = "' + self .in_dir ('fake' ) + '"' )
811+ add_to_config ('BINARYEN_ROOT = "' + self .in_dir ('fake' ) + '"' )
816812
817813 make_fake_tool (self .in_dir ('fake' , 'bin' , 'wasm-opt' ), 'foo' )
818814 self .check_working ([EMCC , test_file ('hello_world.c' ), '-O2' ], 'error parsing binaryen version (wasm-opt version foo). Please check your binaryen installation' )
0 commit comments