Skip to content

Commit 7c11c23

Browse files
committed
Reland "Remove tempfile usage from test_sanity.py. NFC"
This was originally landed in emscripten-core#25617, but reverted because the tests were failing. In both cases the tempfile usage was not necessary. test_emconfig: In this case we can just create a new config file in the CWD. Because the test corrupts the main config file there is no risk that the test is accidentally finding the config file via CWD alone so there is no need to change directory into an external temp dir. test_firstrun: We an just create the fake `bin` files in a subdirectory of the current directory where the test runs. No need for an external temp dir here. This change also makes 3 of the imports in this file no longer needed!
1 parent 5ca9e3c commit 7c11c23

File tree

2 files changed

+27
-96
lines changed

2 files changed

+27
-96
lines changed

.circleci/config.yml

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,14 @@ jobs:
563563
test-sanity:
564564
executor: focal
565565
steps:
566-
- run-tests-linux:
567-
frozen_cache: false
568-
test_targets: "sanity"
566+
- checkout
567+
- run:
568+
name: submodule update
569+
command: git submodule update --init
570+
- pip-install
571+
- install-emsdk
572+
- run-tests:
573+
test_targets: "sanity.test_emconfig"
569574
build-linux:
570575
executor: focal
571576
# xlarge has 4x the cores of the default medium, costs 4x as much, and runs
@@ -1298,61 +1303,3 @@ workflows:
12981303
- test-sanity:
12991304
requires:
13001305
- build-linux
1301-
- test-posixtest:
1302-
requires:
1303-
- build-linux
1304-
- test-core0:
1305-
requires:
1306-
- build-linux
1307-
- test-core2:
1308-
requires:
1309-
- build-linux
1310-
- test-core3:
1311-
requires:
1312-
- build-linux
1313-
- test-wasm64-misc:
1314-
requires:
1315-
- build-linux
1316-
- test-wasm64-4gb:
1317-
requires:
1318-
- build-linux
1319-
- test-wasm2js1:
1320-
requires:
1321-
- build-linux
1322-
- test-other:
1323-
requires:
1324-
- build-linux
1325-
- test-modularize-instance:
1326-
requires:
1327-
- build-linux
1328-
- test-esm-integration:
1329-
requires:
1330-
- build-linux
1331-
- test-stress:
1332-
requires:
1333-
- build-linux
1334-
- test-browser-chrome
1335-
- test-browser-chrome-2gb:
1336-
requires:
1337-
- build-linux
1338-
- test-browser-chrome-wasm64:
1339-
requires:
1340-
- build-linux
1341-
- test-browser-chrome-wasm64-4gb:
1342-
requires:
1343-
- build-linux
1344-
- test-browser-firefox:
1345-
requires:
1346-
- build-linux
1347-
- test-browser-firefox-wasm64
1348-
- test-sockets-chrome:
1349-
requires:
1350-
- build-linux
1351-
- test-jsc
1352-
- test-spidermonkey
1353-
- test-node-compat
1354-
- test-windows
1355-
- test-windows-browser-firefox
1356-
- test-mac-arm64:
1357-
requires:
1358-
- build-linux

test/test_sanity.py

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

66
import glob
77
import os
8-
import platform
98
import re
109
import shutil
1110
import stat
12-
import tempfile
1311
import time
1412
from pathlib import Path
1513
from subprocess import PIPE, STDOUT
1614

17-
import common
1815
from common import (
1916
EMBUILDER,
2017
RunnerCore,
@@ -184,28 +181,27 @@ def test_firstrun(self):
184181
output = self.do([EMCC, '-v'])
185182
self.assertContained('emcc: warning: config file not found: %s. You can create one by hand or run `emcc --generate-config`' % default_config, output)
186183

187-
try:
188-
temp_bin = tempfile.mkdtemp()
184+
temp_bin = os.path.abspath('bin')
185+
os.mkdir(temp_bin)
189186

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))
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))
193190

194-
make_new_executable('wasm-ld')
195-
make_new_executable('node')
191+
make_new_executable('wasm-ld')
192+
make_new_executable('node')
196193

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)
194+
with env_modify({'PATH': temp_bin + os.pathsep + os.environ['PATH']}):
195+
output = self.do([EMCC, '--generate-config'])
196+
197+
config_data = utils.read_file(default_config)
202198

203199
self.assertContained('An Emscripten settings file has been generated at:', output)
204200
self.assertContained(default_config, output)
205201
self.assertContained('It contains our best guesses for the important paths, which are:', output)
206202
self.assertContained('LLVM_ROOT', output)
207203
self.assertContained('NODE_JS', output)
208-
if platform.system() != 'Windows':
204+
if not utils.WINDOWS:
209205
# os.chmod can't make files executable on Windows
210206
self.assertIdentical(temp_bin, re.search("^ *LLVM_ROOT *= (.*)$", output, re.M).group(1))
211207
possible_nodes = [os.path.join(temp_bin, 'node')]
@@ -524,29 +520,17 @@ def test_emcc_cache_flag(self, use_response_files, relative):
524520

525521
def test_emconfig(self):
526522
restore_and_set_up()
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())
523+
create_file('custom_config', get_basic_config())
535524

536525
# Make a syntax error in the original config file so that attempting to access it would fail.
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')
526+
utils.write_file(EM_CONFIG, 'asdfasdfasdfasdf\n')
544527

545-
self.assertContained('hello, world!', result)
528+
# Test both relative and absolute paths to the config
529+
self.run_process([EMCC, '--em-config', os.path.abspath('custom_config')] + MINIMAL_HELLO_WORLD)
530+
self.assertContained('hello, world!', self.run_js('a.out.js'))
546531

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

551535
def test_emcc_ports(self):
552536
restore_and_set_up()

0 commit comments

Comments
 (0)