Skip to content

Commit 1bb24b1

Browse files
committed
Support quotes around exit code
1 parent d5c2419 commit 1bb24b1

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎test/conftest_lite.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
STDERR_FILE = "stderr.txt"
3333

3434
# Command line that writes the exit code of the previous command line and the shell's cwd to the
35-
# terminal, as lines such as '?=0' and 'PWD=/drive'.
35+
# terminal, as lines such as '?=0' and 'PWD=/drive'. Some versions of coreutils env quote the
36+
# '?' name as in "'?'=0", so allow an optional character either side of it.
3637
# Quote the grep pattern as cockle treats an unquoted '?' as a glob wildcard.
37-
EXIT_CODE_AND_PWD_LINE = "env | grep -E '^(\\?|PWD)='"
38+
EXIT_CODE_AND_PWD_LINE = "env | grep -E '^(.?\\?.?|PWD)='"
3839

3940
# Collect the output of the open terminal so that we can tell when a command line has finished.
4041
COLLECT_OUTPUT_JS = """
@@ -230,7 +231,8 @@ def read_exit_code_and_pwd(page: Page) -> tuple[int | None, str]:
230231
output = run_line(page, EXIT_CODE_AND_PWD_LINE)
231232
# Remove ANSI escape sequences such as colours, as grep is aliased to 'grep --color=auto'.
232233
output = re.sub(r"\x1b\[[0-9;]*[A-Za-z]", "", output)
233-
returncode = re.search(r"^\?=(-?\d+)\s*$", output, re.MULTILINE)
234+
# The '?' name may or may not be quoted, depending on the version of coreutils env.
235+
returncode = re.search(r"^'?\?'?=(-?\d+)\s*$", output, re.MULTILINE)
234236
pwd = re.search(r"^PWD=(.*?)\s*$", output, re.MULTILINE)
235237
if pwd is None:
236238
raise RuntimeError(f"Unable to read PWD from terminal output: {output!r}")

0 commit comments

Comments
 (0)