Skip to content

Commit

Permalink
enhance test_toy_sanity_check_commands to check on working directory …
Browse files Browse the repository at this point in the history
…for sanity check commands
  • Loading branch information
boegel committed Dec 18, 2024
1 parent 65512fe commit 2389fc6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3741,14 +3741,14 @@ def xs2str(xs):

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

# run sanity check commands
for cmd in commands:

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

res = run_shell_cmd(cmd, work_dir=sanity_work_dir, fail_on_error=False, hidden=True)
res = run_shell_cmd(cmd, work_dir=sanity_check_work_dir, fail_on_error=False, hidden=True)
if res.exit_code != EasyBuildExit.SUCCESS:
fail_msg = f"sanity check command {cmd} failed with exit code {res.exit_code} (output: {res.output})"
self.sanity_check_fail_msgs.append(fail_msg)
Expand Down
11 changes: 11 additions & 0 deletions test/framework/toy_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,8 @@ def test_toy_sanity_check_commands(self):
test_easyconfigs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
toy_ec_txt = read_file(os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0.eb'))

out_file = os.path.join(self.test_prefix, 'out.txt')

toy_ec_txt = '\n'.join([
toy_ec_txt,
"toolchain = {'name': 'foss', 'version': '2018a'}",
Expand All @@ -2388,6 +2390,8 @@ def test_toy_sanity_check_commands(self):
" True,",
# test command to make sure that '-h' is not passed to commands specified as string ('env -h' fails)
" 'env',"
# print current working directory, should *not* be software install directory, but empty dir
f" '(pwd && ls | wc -l) > {out_file}',",
"]",
])

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

self.assertExists(toy_modfile)

# check contents of output file created by sanity check commands
self.assertExists(out_file)
out_txt = read_file(out_file)
# working dir for sanity check command should be an empty custom temporary directory
regex = re.compile('^.*/eb-[^/]+/eb-sanity-check-[^/]+\n[ ]*0$')
self.assertTrue(regex.match(out_txt), f"Pattern '{regex.pattern}' should match in: {out_txt}")

def test_sanity_check_paths_lib64(self):
"""Test whether fallback in sanity check for lib64/ equivalents of library files works."""
test_ecs_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs')
Expand Down

0 comments on commit 2389fc6

Please sign in to comment.