Skip to content

Commit afaa973

Browse files
committed
Move print_test_errors inside stdout redirect region
- Moved Test.print_test_errors(ts) call inside the redirect_stdout block - This ensures test error details are captured in the test_output field - The errors are now part of the captured output rather than printed separately - Consolidated has_failures function definition to avoid duplication
1 parent 203c475 commit afaa973

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/tools/grade_problem.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,8 @@ function ClaudeMCPTools.execute(tool::GradeProblemTool, params::Dict)
6868
# finish throws an error if tests fail, but we still want the output
6969
end
7070

71-
# Restore stdout and close the write end
72-
redirect_stdout(old_stdout)
73-
close(wr)
74-
75-
# Read the captured output
76-
test_output_str = read(rd, String)
77-
close(rd)
78-
79-
# Check if any tests failed (including in nested testsets)
71+
# Check if any tests failed and print errors (while still redirected)
72+
# This ensures the errors are captured in the output
8073
function has_failures(testset)
8174
for r in testset.results
8275
if isa(r, Test.Fail) || isa(r, Test.Error)
@@ -90,13 +83,21 @@ function ClaudeMCPTools.execute(tool::GradeProblemTool, params::Dict)
9083
return false
9184
end
9285

93-
has_test_failures = has_failures(ts)
94-
95-
# Print test errors to stdout so they appear in the UI
96-
if has_test_failures
86+
if has_failures(ts)
9787
Test.print_test_errors(ts)
9888
end
9989

90+
# Restore stdout and close the write end
91+
redirect_stdout(old_stdout)
92+
close(wr)
93+
94+
# Read the captured output
95+
test_output_str = read(rd, String)
96+
close(rd)
97+
98+
# Check if any tests failed (reuse the has_failures function defined above)
99+
has_test_failures = has_failures(ts)
100+
100101
# Debug: Print the result type
101102
@debug "Grade function returned: $(typeof(result))"
102103

0 commit comments

Comments
 (0)