@@ -266,20 +266,23 @@ def test_run_shell_cmd_basic(self):
266266 cmd_script = os .path .join (cmd_tmpdir , 'cmd.sh' )
267267 self .assertExists (cmd_script )
268268
269- cmd = f"{ cmd_script } -c 'echo pwd: $PWD; echo $FOOBAR; echo $EB_CMD_OUT_FILE; cat $EB_CMD_OUT_FILE'"
269+ cmd = f"{ cmd_script } -c '"
270+ cmd += 'echo pwd: $PWD; echo "bash_env: $BASH_ENV"; echo $FOOBAR; echo $EB_CMD_OUT_FILE; cat $EB_CMD_OUT_FILE'
271+ cmd += "'"
270272 with self .mocked_stdout_stderr ():
271273 res = run_shell_cmd (cmd , fail_on_error = False )
272274 self .assertEqual (res .exit_code , 0 )
273- regex = re .compile ("pwd: .*\n foobar\n .*/echo-.*/out.txt\n hello$" )
275+ regex = re .compile ("pwd: .*\n bash_env: .* \ n foobar\n .*/echo-.*/out.txt\n hello$" )
274276 self .assertTrue (regex .search (res .output ), f"Pattern '{ regex .pattern } ' should be found in { res .output } " )
275277
276278 # check whether working directory is what's expected
277- regex = re .compile ('^pwd: .*' , re .M )
278- res = regex .findall (res .output )
279- self .assertEqual (len (res ), 1 )
280- pwd = res [0 ].strip ()[5 :]
279+ matches = re .findall ('^pwd: (.*)' , res .output , re .M )
280+ self .assertEqual (len (matches ), 1 )
281+ pwd = matches [0 ]
281282 self .assertTrue (os .path .samefile (pwd , self .test_prefix ))
282283
284+ # BASH_ENV is that of the current shell, not the one set in the cmd.sh
285+ self .assertEqual (re .search ('^bash_env: (.*)' , res .output , re .M )[1 ], os .environ .get ('BASH_ENV' , '' ))
283286 cmd = f"{ cmd_script } -c 'module --version'"
284287 with self .mocked_stdout_stderr ():
285288 res = run_shell_cmd (cmd , fail_on_error = False )
0 commit comments