Skip to content

Commit 2389fc6

Browse files
committed
enhance test_toy_sanity_check_commands to check on working directory for sanity check commands
1 parent 65512fe commit 2389fc6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

easybuild/framework/easyblock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,14 +3741,14 @@ def xs2str(xs):
37413741

37423742
# run sanity checks from an empty temp directory
37433743
# using the build or installation directory can produce false positives and polute them with files
3744-
sanity_work_dir = tempfile.mkdtemp(prefix='eb-saniy-check-')
3744+
sanity_check_work_dir = tempfile.mkdtemp(prefix='eb-sanity-check-')
37453745

37463746
# run sanity check commands
37473747
for cmd in commands:
37483748

37493749
trace_msg(f"running command '{cmd}' ...")
37503750

3751-
res = run_shell_cmd(cmd, work_dir=sanity_work_dir, fail_on_error=False, hidden=True)
3751+
res = run_shell_cmd(cmd, work_dir=sanity_check_work_dir, fail_on_error=False, hidden=True)
37523752
if res.exit_code != EasyBuildExit.SUCCESS:
37533753
fail_msg = f"sanity check command {cmd} failed with exit code {res.exit_code} (output: {res.output})"
37543754
self.sanity_check_fail_msgs.append(fail_msg)

test/framework/toy_build.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,8 @@ def test_toy_sanity_check_commands(self):
23732373
test_easyconfigs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
23742374
toy_ec_txt = read_file(os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0.eb'))
23752375

2376+
out_file = os.path.join(self.test_prefix, 'out.txt')
2377+
23762378
toy_ec_txt = '\n'.join([
23772379
toy_ec_txt,
23782380
"toolchain = {'name': 'foss', 'version': '2018a'}",
@@ -2388,6 +2390,8 @@ def test_toy_sanity_check_commands(self):
23882390
" True,",
23892391
# test command to make sure that '-h' is not passed to commands specified as string ('env -h' fails)
23902392
" 'env',"
2393+
# print current working directory, should *not* be software install directory, but empty dir
2394+
f" '(pwd && ls | wc -l) > {out_file}',",
23912395
"]",
23922396
])
23932397

@@ -2412,6 +2416,13 @@ def test_toy_sanity_check_commands(self):
24122416

24132417
self.assertExists(toy_modfile)
24142418

2419+
# check contents of output file created by sanity check commands
2420+
self.assertExists(out_file)
2421+
out_txt = read_file(out_file)
2422+
# working dir for sanity check command should be an empty custom temporary directory
2423+
regex = re.compile('^.*/eb-[^/]+/eb-sanity-check-[^/]+\n[ ]*0$')
2424+
self.assertTrue(regex.match(out_txt), f"Pattern '{regex.pattern}' should match in: {out_txt}")
2425+
24152426
def test_sanity_check_paths_lib64(self):
24162427
"""Test whether fallback in sanity check for lib64/ equivalents of library files works."""
24172428
test_ecs_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs')

0 commit comments

Comments
 (0)