Skip to content

Commit a49e046

Browse files
committed
Properly expand environment variables in execution modes
1 parent 257adfe commit a49e046

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
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'"
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(

0 commit comments

Comments
 (0)