Skip to content

Commit c90760b

Browse files
committed
feat: Update error reporting to skip certain lines in stderr output
1 parent f75c9b9 commit c90760b

File tree

10 files changed

+29
-5
lines changed

10 files changed

+29
-5
lines changed

internal/test_helpers/fixtures/fail_scanning_lexical_errors/1_missing_line

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
[stage-5] [test-1] Writing contents to ./test.lox:
44
[stage-5] [test-1] [test.lox] @
55
[stage-5] [test-1] $ ./your_program.sh tokenize test.lox
6+
[your_program] This line will be skipped in stderr
67
[your_program] [line 1] Error: Unexpected character: @
78
[your_program] EOF null
8-
[your_program] This line will be skipped in stderr
99
[stage-5] [test-1] [stderr] Skipped 1 lines that didn't start with [line N]
1010
[stage-5] [test-1] 
1111
[stage-5] [test-1] [stderr] Missing line #1 from stderr: "[line 1] Error: Unexpected character: @"

internal/test_helpers/fixtures/fail_scanning_lexical_errors/2_mismatch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
[stage-5] [test-1] [test.lox] @
55
[stage-5] [test-1] $ ./your_program.sh tokenize test.lox
66
[your_program] EOF null
7+
[your_program] This line will be skipped in stderr
78
[your_program] [line 1] eRrOr: uNeXpEcTed cHaRaCtEr: @
9+
[stage-5] [test-1] [stderr] Skipped 1 lines that didn't start with [line N]
810
[stage-5] [test-1] 
911
[stage-5] [test-1] [stderr] Mismatch on line #1 of stderr:
1012
[stage-5] [test-1] [stderr] Expected: "[line 1] Error: Unexpected character: @"

internal/test_helpers/fixtures/fail_scanning_lexical_errors/3_extra_line

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
[stage-5] [test-1] Writing contents to ./test.lox:
44
[stage-5] [test-1] [test.lox] @
55
[stage-5] [test-1] $ ./your_program.sh tokenize test.lox
6+
[your_program] This line will be skipped in stderr
67
[your_program] EOF null
78
[your_program] [line 1] Error: Unexpected character: @
89
[your_program] [line 666] Extra line
910
[your_program] [line 888] Another extra line
11+
[stage-5] [test-1] [stderr] Skipped 1 lines that didn't start with [line N]
1012
[stage-5] [test-1] ✓ [line 1] Error: Unexpected character: @
1113
[stage-5] [test-1] 
1214
[stage-5] [test-1] 𐄂 [stderr] Extra unexpected line in stderr: "[line 666] Extra line"

internal/test_helpers/fixtures/fail_scanning_multiline_errors/1_missing_line

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
[stage-11] [test-1] Writing contents to ./test.lox:
44
[stage-11] [test-1] [test.lox] ()<|SPACE|><|TAB|>@
55
[stage-11] [test-1] $ ./your_program.sh tokenize test.lox
6+
[your_program] [line 2] Error: Unexpected character: @
67
[your_program] LEFT_PAREN ( null
78
[your_program] RIGHT_PAREN ) null
8-
[your_program] [line 2] Error: Unexpected character: @
99
[your_program] EOF null
1010
[stage-11] [test-1] ✓ 1 line(s) match on stderr
1111
[stage-11] [test-1] ✓ 3 line(s) match on stdout

internal/test_helpers/fixtures/fail_scanning_multiline_errors/2_mismatch

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
[stage-11] [test-1] Writing contents to ./test.lox:
44
[stage-11] [test-1] [test.lox] ()<|SPACE|><|TAB|>@
55
[stage-11] [test-1] $ ./your_program.sh tokenize test.lox
6-
[your_program] [line 2] Error: Unexpected character: @
76
[your_program] LEFT_PAREN ( null
87
[your_program] RIGHT_PAREN ) null
8+
[your_program] This line will be skipped in stderr
99
[your_program] EOF null
10+
[your_program] [line 2] Error: Unexpected character: @
11+
[stage-11] [test-1] [stderr] Skipped 1 lines that didn't start with [line N]
1012
[stage-11] [test-1] ✓ 1 line(s) match on stderr
1113
[stage-11] [test-1] ✓ 3 line(s) match on stdout
1214
[stage-11] [test-1] ✓ Received exit code 65.
@@ -16,8 +18,11 @@
1618
[stage-11] [test-2] [test.lox] <|SPACE|>
1719
[stage-11] [test-2] $ ./your_program.sh tokenize test.lox
1820
[your_program] EOF null
21+
[your_program] This line will be skipped in stderr
1922
[your_program] [line 1] Error: Unexpected character: @
23+
[your_program] This line will be skipped in stderr
2024
[your_program] [line 1] eRrRr: Unexpected character: #
25+
[stage-11] [test-2] [stderr] Skipped 2 lines that didn't start with [line N]
2126
[stage-11] [test-2] ✓ [line 1] Error: Unexpected character: @
2227
[stage-11] [test-2] 
2328
[stage-11] [test-2] [stderr] Mismatch on line #2 of stderr:

internal/test_helpers/fixtures/fail_scanning_multiline_errors/3_extra_line

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
[stage-11] [test-1] Writing contents to ./test.lox:
44
[stage-11] [test-1] [test.lox] ()<|SPACE|><|TAB|>@
55
[stage-11] [test-1] $ ./your_program.sh tokenize test.lox
6-
[your_program] [line 2] Error: Unexpected character: @
76
[your_program] LEFT_PAREN ( null
87
[your_program] RIGHT_PAREN ) null
8+
[your_program] This line will be skipped in stderr
9+
[your_program] [line 2] Error: Unexpected character: @
910
[your_program] EOF null
11+
[stage-11] [test-1] [stderr] Skipped 1 lines that didn't start with [line N]
1012
[stage-11] [test-1] ✓ 1 line(s) match on stderr
1113
[stage-11] [test-1] ✓ 3 line(s) match on stdout
1214
[stage-11] [test-1] ✓ Received exit code 65.
@@ -15,10 +17,13 @@
1517
[stage-11] [test-2] [test.lox] @#
1618
[stage-11] [test-2] [test.lox] <|SPACE|>
1719
[stage-11] [test-2] $ ./your_program.sh tokenize test.lox
18-
[your_program] [line 1] Error: Unexpected character: @
1920
[your_program] EOF null
21+
[your_program] This line will be skipped in stderr
22+
[your_program] [line 1] Error: Unexpected character: @
23+
[your_program] This line will be skipped in stderr
2024
[your_program] [line 1] Error: Unexpected character: #
2125
[your_program] [line 888] extra line
26+
[stage-11] [test-2] [stderr] Skipped 2 lines that didn't start with [line N]
2227
[stage-11] [test-2] ✓ [line 1] Error: Unexpected character: @
2328
[stage-11] [test-2] ✓ [line 1] Error: Unexpected character: #
2429
[stage-11] [test-2] 

internal/test_helpers/scenarios/fail_scanning_lexical_errors/2_mismatch/app/scanner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def scan_token(self):
5353
case char:
5454
self.has_errors = True
5555

56+
print("This line will be skipped in stderr", file=sys.stderr)
57+
5658
print(
5759
f"[line {self.current_line}] eRrOr: uNeXpEcTed cHaRaCtEr: {char}",
5860
file=sys.stderr,

internal/test_helpers/scenarios/fail_scanning_lexical_errors/3_extra_line/app/scanner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def scan_token(self):
5353
case char:
5454
self.has_errors = True
5555

56+
print("This line will be skipped in stderr", file=sys.stderr)
57+
5658
print(
5759
f"[line {self.current_line}] Error: Unexpected character: {char}",
5860
file=sys.stderr,

internal/test_helpers/scenarios/fail_scanning_multiline_errors/2_mismatch/lox/lox.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def _check_errror_exit(self):
5353

5454
def _error_report(self, line: int, where: str, message: str):
5555
self._had_error = True
56+
57+
print("This line will be skipped in stderr", file=sys.stderr)
58+
5659
if message.endswith("@"):
5760
output = f"[line {line}] Error{where}: {message}"
5861
print(output, file=sys.stderr)

internal/test_helpers/scenarios/fail_scanning_multiline_errors/3_extra_line/lox/lox.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def _check_errror_exit(self):
5353

5454
def _error_report(self, line: int, where: str, message: str):
5555
self._had_error = True
56+
57+
print("This line will be skipped in stderr", file=sys.stderr)
58+
5659
output = f"[line {line}] Error{where}: {message}"
5760
print(output, file=sys.stderr)
5861
if message.endswith("#"):

0 commit comments

Comments
 (0)