Skip to content

Commit 834e207

Browse files
committed
Match testcheck logic
1 parent 4e0feab commit 834e207

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

‎mypy/test/testcmdline.py‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_python_cmdline(testcase: DataDrivenTestCase, step: int) -> None:
5858
with open(program_path, "w", encoding="utf8") as file:
5959
for s in testcase.input:
6060
file.write(f"{s}\n")
61-
args = parse_args(normalize_devnull(testcase.input[step - 1]), step)
61+
args = parse_args(normalize_devnull("\n".join(testcase.input)), step)
6262
custom_cwd = parse_cwd(testcase.input[1]) if len(testcase.input) > 1 else None
6363
args.append("--show-traceback")
6464
if "--error-summary" not in args:
@@ -122,19 +122,22 @@ def test_python_cmdline(testcase: DataDrivenTestCase, step: int) -> None:
122122
)
123123

124124

125-
def parse_args(line: str, step: int) -> list[str]:
126-
"""Parse the first line of the program for the command line.
125+
def parse_args(text: str, step: int) -> list[str]:
126+
"""Parse the program for the command line.
127127
128128
This should have the form
129129
130-
# cmd: mypy <options>
130+
# cmd[N]: mypy <options>
131131
132132
For example:
133133
134-
# cmd: mypy pkg/
134+
# cmd: mypy pkg/ or # cmd2: mypy pkg/
135135
"""
136-
step_str = "" if step == 1 else str(step)
137-
m = re.match(f"# cmd{step_str}: mypy (.*)$", line)
136+
m = re.search("# cmd: mypy (.*)$", text, flags=re.MULTILINE)
137+
if step > 1:
138+
alt_m = re.search(f"# cmd{step}: mypy (.*)$", text, flags=re.MULTILINE)
139+
if alt_m is not None:
140+
m = alt_m
138141
if not m:
139142
return [] # No args; mypy will spit out an error.
140143
return shlex.split(m.group(1))

0 commit comments

Comments
 (0)