Skip to content

Commit 5ca9e3c

Browse files
authored
Revert "Remove tempfile usage from test_sanity.py. NFC" (#25625)
Reverts #25617 The tests in question did not pass. Reverting while I figure out what happened here.
1 parent 3bc4cf8 commit 5ca9e3c

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

test/test_sanity.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55

66
import glob
77
import os
8+
import platform
89
import re
910
import shutil
1011
import stat
12+
import tempfile
1113
import time
1214
from pathlib import Path
1315
from subprocess import PIPE, STDOUT
1416

17+
import common
1518
from common import (
1619
EMBUILDER,
1720
RunnerCore,
@@ -177,31 +180,32 @@ def test_aaa_normal(self):
177180

178181
@with_env_modify({'EM_CONFIG': None})
179182
def test_firstrun(self):
180-
default_config = EM_CONFIG
183+
default_config = path_from_root('.emscripten')
181184
output = self.do([EMCC, '-v'])
182185
self.assertContained('emcc: warning: config file not found: %s. You can create one by hand or run `emcc --generate-config`' % default_config, output)
183186

184-
temp_bin = os.path.abspath('bin')
185-
os.mkdir(temp_bin)
186-
187-
def make_new_executable(name):
188-
utils.write_file(os.path.join(temp_bin, name), '')
189-
make_executable(os.path.join(temp_bin, name))
187+
try:
188+
temp_bin = tempfile.mkdtemp()
190189

191-
make_new_executable('wasm-ld')
192-
make_new_executable('node')
190+
def make_new_executable(name):
191+
utils.write_file(os.path.join(temp_bin, name), '')
192+
make_executable(os.path.join(temp_bin, name))
193193

194-
with env_modify({'PATH': temp_bin + os.pathsep + os.environ['PATH']}):
195-
output = self.do([EMCC, '--generate-config'])
194+
make_new_executable('wasm-ld')
195+
make_new_executable('node')
196196

197-
config_data = utils.read_file(default_config)
197+
with env_modify({'PATH': temp_bin + os.pathsep + os.environ['PATH']}):
198+
output = self.do([EMCC, '--generate-config'])
199+
finally:
200+
shutil.rmtree(temp_bin)
201+
config_data = utils.read_file(default_config)
198202

199203
self.assertContained('An Emscripten settings file has been generated at:', output)
200204
self.assertContained(default_config, output)
201205
self.assertContained('It contains our best guesses for the important paths, which are:', output)
202206
self.assertContained('LLVM_ROOT', output)
203207
self.assertContained('NODE_JS', output)
204-
if not utils.WINDOWS:
208+
if platform.system() != 'Windows':
205209
# os.chmod can't make files executable on Windows
206210
self.assertIdentical(temp_bin, re.search("^ *LLVM_ROOT *= (.*)$", output, re.M).group(1))
207211
possible_nodes = [os.path.join(temp_bin, 'node')]
@@ -520,13 +524,29 @@ def test_emcc_cache_flag(self, use_response_files, relative):
520524

521525
def test_emconfig(self):
522526
restore_and_set_up()
523-
create_file('custom_config', get_basic_config())
527+
528+
fd, custom_config_filename = tempfile.mkstemp(prefix='.emscripten_config_')
529+
530+
orig_config = utils.read_file(EM_CONFIG)
531+
532+
# Move the ~/.emscripten to a custom location.
533+
with os.fdopen(fd, "w") as f:
534+
f.write(get_basic_config())
524535

525536
# Make a syntax error in the original config file so that attempting to access it would fail.
526-
utils.write_file(EM_CONFIG, 'asdfasdfasdfasdf\n')
537+
utils.write_file(EM_CONFIG, 'asdfasdfasdfasdf\n\'\'\'' + orig_config)
538+
539+
temp_dir = tempfile.mkdtemp(prefix='emscripten_temp_')
540+
541+
with common.chdir(temp_dir):
542+
self.run_process([EMCC, '--em-config', custom_config_filename] + MINIMAL_HELLO_WORLD + ['-O2'])
543+
result = self.run_js('a.out.js')
544+
545+
self.assertContained('hello, world!', result)
527546

528-
self.run_process([EMCC, '--em-config', 'custom_config'] + MINIMAL_HELLO_WORLD)
529-
self.assertContained('hello, world!', self.run_js('a.out.js'))
547+
# Clean up created temp files.
548+
os.remove(custom_config_filename)
549+
shutil.rmtree(temp_dir)
530550

531551
def test_emcc_ports(self):
532552
restore_and_set_up()

0 commit comments

Comments
 (0)