Skip to content

Commit

Permalink
Fix possible hanging while comparing regex (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delgan committed Jun 19, 2022
1 parent 30f82bd commit e3ce0bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 15 additions & 1 deletion pytest_mypy_plugins/tests/test-regex_assertions.yml
Expand Up @@ -15,6 +15,20 @@
out: |
main:2: note: .*str.*
- case: regex_with_out_does_not_hang
expect_fail: yes
regex: yes
main: |
'abc'.split(4)
out: |
main:1: error: Argument 1 to "split" of "str" has incompatible type "int"; expected "Optional[str]"
- case: regex_with_comment_does_not_hang
expect_fail: yes
regex: yes
main: |
a = 'abc'.split(4) # E: Argument 1 to "split" of "str" has incompatible type "int"; expected "Optional[str]"
- case: expected_single_message_regex
regex: no
main: |
Expand All @@ -34,7 +48,7 @@
a = 'hello'
reveal_type(a) # N: .*str.*
- case: regext_does_not_match
- case: regex_does_not_match
expect_fail: yes
regex: no
main: |
Expand Down
6 changes: 5 additions & 1 deletion pytest_mypy_plugins/utils.py
Expand Up @@ -144,6 +144,8 @@ def _add_aligned_message(s1: str, s2: str, error_message: str) -> str:

error_message += "Alignment of first line difference:\n"

assert s1 != s2

trunc = False
while s1[:30] == s2[:30]:
s1 = s1[10:]
Expand Down Expand Up @@ -260,7 +262,9 @@ def format_error_lines(lines: List[str]) -> str:
format_error_lines(actual_message_lines), format_error_lines(expected_message_lines)
)

if (
if expected_line and expected_line.regex:
error_message += "The actual output does not match the expected regex."
elif (
first_diff_actual is not None
and first_diff_expected is not None
and (
Expand Down

0 comments on commit e3ce0bf

Please sign in to comment.