Skip to content

Commit a9e3df3

Browse files
committed
Cleanup stacktrace properly
1 parent 0b1a7ff commit a9e3df3

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

tested/languages/cpp/config.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,17 @@ def linter(self, remaining: float) -> tuple[list[Message], list[AnnotateCode]]:
144144
return linter.run_cppcheck(self.config.dodona, remaining, "c++")
145145

146146
def cleanup_stacktrace(self, stacktrace: str) -> str:
147-
included_regex = rf"from ({EXECUTION_PREFIX}|selector)"
148147
result = ""
148+
in_student_file = False
149149
for line in stacktrace.splitlines(keepends=True):
150-
if re.search(included_regex, line):
151-
continue
152-
153-
# Once we hit the three dots, skip.
154-
if "..." in line:
155-
break
156-
157-
line = line.replace(submission_file(self), "<code>")
158-
result += line
150+
if submission_file(self) in line:
151+
in_student_file = True
152+
elif "|" not in line:
153+
in_student_file = False
154+
155+
if in_student_file:
156+
line = line.replace(submission_file(self), "<code>")
157+
result += line
159158
return result
160159

161160
def is_source_file(self, file: Path) -> bool:

tested/manual.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from tested.main import run
1414
from tested.testsuite import SupportedLanguage
1515

16-
exercise_dir = "/IdeaProjects/universal-judge/tests/exercises/echo-function"
16+
exercise_dir = "/IdeaProjects/universal-judge/tests/exercises/echo"
1717

1818

1919
def read_config() -> DodonaConfig:
@@ -24,10 +24,10 @@ def read_config() -> DodonaConfig:
2424
programming_language=SupportedLanguage("cpp"),
2525
natural_language="nl",
2626
resources=Path(exercise_dir, "evaluation"),
27-
source=Path(exercise_dir, "solution/correct.cpp"),
27+
source=Path(exercise_dir, "solution/comp-error.cpp"),
2828
judge=Path("."),
2929
workdir=Path("workdir"),
30-
test_suite="two-specific.tson",
30+
test_suite="one.tson",
3131
options=Options(
3232
linter=False,
3333
),

tests/test_stacktrace_cleaners.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,44 @@ def test_c_compilation_error():
305305
assert actual == expected
306306

307307

308+
def test_cpp_compilation_error():
309+
original = """In file included from execution_0.cpp:3,
310+
from selector.cpp:5:
311+
submission.cpp:3:1: error: ‘mfzej’ does not name a type
312+
3 | mfzej àryhg çyh aiogharuio ghqgh
313+
| ^~~~~
314+
In file included from selector.cpp:5:
315+
execution_0.cpp: In function ‘void execution_0_write_separator()’:
316+
execution_0.cpp:9:5: error: ‘execution_0_value_file’ was not declared in this scope; did you mean ‘execution_0_exception_file’?
317+
9 | execution_0_value_file << "--Nh9YaHPGI-- SEP";
318+
| ^~~~~~~~~~~~~~~~~~~~~~
319+
| execution_0_exception_file
320+
execution_0.cpp: In function ‘void execution_0_write_context_separator()’:
321+
execution_0.cpp:16:5: error: ‘execution_0_value_file’ was not declared in this scope; did you mean ‘execution_0_exception_file’?
322+
16 | execution_0_value_file << "--xxWjFpcXw-- SEP";
323+
| ^~~~~~~~~~~~~~~~~~~~~~
324+
| execution_0_exception_file
325+
execution_0.cpp: In function ‘int execution_0_context_0()’:
326+
execution_0.cpp:39:25: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
327+
39 | char* args[] = {"submission", };
328+
| ^~~~~~~~~~~~
329+
execution_0.cpp:40:21: error: ‘solution_main’ was not declared in this scope
330+
40 | exit_code = solution_main(1, args);
331+
| ^~~~~~~~~~~~~
332+
execution_0.cpp: In function ‘int execution_0()’:
333+
execution_0.cpp:52:5: error: ‘execution_0_value_file’ was not declared in this scope
334+
52 | execution_0_value_file.open("Nh9YaHPGI_values.txt", std::ios::out);
335+
| ^~~~~~~~~~~~~~~~~~~~~~
336+
"""
337+
language_config = get_language("test", "cpp")
338+
expected = """<code>:3:1: error: ‘mfzej’ does not name a type
339+
3 | mfzej àryhg çyh aiogharuio ghqgh
340+
| ^~~~~
341+
"""
342+
actual = language_config.cleanup_stacktrace(original)
343+
assert actual == expected
344+
345+
308346
def test_haskell_compilation_error():
309347
original = """Submission.hs:3:1: error:
310348
Parse error: module header, import declaration

0 commit comments

Comments
 (0)