Skip to content

Commit 7ff5e29

Browse files
authored
Merge pull request #3390 from vkarak/bugfix/expandvars-modes
[bugfix] Properly expand environment variables in execution modes
2 parents 257adfe + af7e467 commit 7ff5e29

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

reframe/frontend/cli.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,9 +941,12 @@ def restrict_logging():
941941
# We lexically split the mode options, because otherwise spaces
942942
# will be treated as part of the option argument;
943943
# see GH bug #1554
944-
mode_args = list(
945-
itertools.chain.from_iterable(shlex.split(m)
946-
for m in mode_args))
944+
mode_args = list(itertools.chain.from_iterable(
945+
shlex.split(osext.expandvars(arg)) for arg in mode_args)
946+
)
947+
printer.debug(f'Expanding execution mode {options.mode!r}: '
948+
f'{" ".join(mode_args)}')
949+
947950
# Parse the mode's options and reparse the command-line
948951
options = argparser.parse_args(mode_args,
949952
suppress_required=True)

unittests/resources/config/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ def hostname():
275275
'-p builtin',
276276
'-S local=1'
277277
]
278+
},
279+
{
280+
'name': 'env_vars',
281+
'options': ['-n', '${TEST_NAME_PATTERN}',
282+
'-S', '${VAR}=${VAL}']
278283
}
279284
],
280285
'logging': [

unittests/test_cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,20 @@ def test_execution_modes(run_reframe, run_action):
542542
assert 'Ran 1/1 test case' in stdout
543543

544544

545+
def test_execution_modes_envvar_expansion(run_reframe, monkeypatch):
546+
monkeypatch.setenv('TEST_NAME_PATTERN', '^HelloTest$')
547+
monkeypatch.setenv('VAR', 'x')
548+
monkeypatch.setenv('VAL', '1')
549+
returncode, stdout, stderr = run_reframe(
550+
mode='env_vars', action='list'
551+
)
552+
assert returncode == 0
553+
assert 'Traceback' not in stdout
554+
assert 'Traceback' not in stderr
555+
assert "the following variables were not set: 'x'" in stdout
556+
assert 'Found 1 check(s)' in stdout
557+
558+
545559
def test_invalid_mode_error(run_reframe):
546560
mode = 'invalid'
547561
returncode, stdout, stderr = run_reframe(

unittests/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def test_select_subconfig(site_config):
225225
site_config.select_subconfig('testsys')
226226
assert len(site_config['systems']) == 1
227227
assert len(site_config['systems'][0]['partitions']) == 2
228-
assert len(site_config['modes']) == 1
228+
assert len(site_config['modes']) == 2
229229
assert site_config.get('systems/0/name') == 'testsys'
230230
assert site_config.get('systems/0/descr') == 'Fake system for unit tests'
231231
assert site_config.get('systems/0/hostnames') == ['testsys']

0 commit comments

Comments
 (0)