Skip to content

Commit aec290e

Browse files
authored
Merge pull request #121 from codecrafters-io/CC-1655-1
Log unexpected output in testExit function before returning error
2 parents 7ac536e + 76ebd93 commit aec290e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

internal/stage4.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,18 @@ func testExit(stageHarness *test_case_harness.TestCaseHarness) error {
5858
return fmt.Errorf("Expected program to exit with 0 exit code, program is still running.")
5959
}
6060

61-
logger.Successf("✓ Program exited successfully")
62-
6361
if exitCode != 0 {
6462
return fmt.Errorf("Expected 0 as exit code, got %d", exitCode)
6563
}
6664

6765
// Most shells return nothing but bash returns the string "exit" when it exits, we allow both styles
6866
if len(output) > 0 && strings.TrimSpace(output) != "exit" {
67+
// If there is some unexpected output, we need to log it before returning an error
68+
asserter.LogRemainingOutput()
6969
return fmt.Errorf("Expected no output after exit command, got %q", output)
7070
}
7171

72+
logger.Successf("✓ Program exited successfully")
7273
logger.Successf("✓ No output after exit command")
7374

7475
return logAndQuit(asserter, nil)

0 commit comments

Comments
 (0)