Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/stage4.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

"github.com/codecrafters-io/shell-tester/internal/condition_reader"
"github.com/codecrafters-io/shell-tester/internal/logged_shell_asserter"
"github.com/codecrafters-io/shell-tester/internal/shell_executable"
"github.com/codecrafters-io/shell-tester/internal/test_cases"
Expand Down Expand Up @@ -47,6 +48,9 @@ func testExit(stageHarness *test_case_harness.TestCaseHarness) error {
if !errors.Is(readErr, shell_executable.ErrProgramExited) {
if readErr == nil {
return fmt.Errorf("Expected program to exit with 0 exit code, program is still running.")
} else if errors.Is(readErr, condition_reader.ErrConditionNotMet) {
asserter.LogRemainingOutput()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Arpan-206 thought we talked about this - we should be logging this no matter what, not only when a specific error type is found

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I thought I changed it back, lemme do that!

return fmt.Errorf("Expected program to exit with 0 exit code, program is still running.")
} else {
// TODO: Other than ErrProgramExited, what other errors could we get? Are they user errors or internal errors?
return fmt.Errorf("Error reading output: %v", readErr)
Expand Down
7 changes: 7 additions & 0 deletions internal/stages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ func TestStages(t *testing.T) {
StdoutFixturePath: "./test_helpers/fixtures/escape_codes",
NormalizeOutputFunc: normalizeTesterOutput,
},
"exit_error_fail": {
UntilStageSlug: "pn5",
CodePath: "./test_helpers/scenarios/exit_error",
ExpectedExitCode: 1,
StdoutFixturePath: "./test_helpers/fixtures/exit_error",
NormalizeOutputFunc: normalizeTesterOutput,
},
"base_pass_bash": {
UntilStageSlug: "ip1",
CodePath: "./test_helpers/bash",
Expand Down
6 changes: 3 additions & 3 deletions internal/test_helpers/fixtures/bash/base/pass
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Debug = true
[stage-7] [setup] - my_exe
[stage-7] Running ./your_shell.sh
[your-program] $ type cat
[your-program] cat is /bin/cat
[your-program] cat is /usr/bin/cat
[stage-7] ✓ Received expected response
[your-program] $ type cp
[your-program] cp is /bin/cp
[your-program] cp is /usr/bin/cp
[stage-7] ✓ Received expected response
[your-program] $ type mkdir
[your-program] mkdir is /bin/mkdir
[your-program] mkdir is /usr/bin/mkdir
[stage-7] ✓ Received expected response
[your-program] $ type my_exe
[your-program] my_exe is /tmp/foo/my_exe
Expand Down
6 changes: 3 additions & 3 deletions internal/test_helpers/fixtures/bash/navigation/pass
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ Debug = true
[stage-7] [setup] - my_exe
[stage-7] Running ./your_shell.sh
[your-program] $ type cat
[your-program] cat is /bin/cat
[your-program] cat is /usr/bin/cat
[stage-7] ✓ Received expected response
[your-program] $ type cp
[your-program] cp is /bin/cp
[your-program] cp is /usr/bin/cp
[stage-7] ✓ Received expected response
[your-program] $ type mkdir
[your-program] mkdir is /bin/mkdir
[your-program] mkdir is /usr/bin/mkdir
[stage-7] ✓ Received expected response
[your-program] $ type my_exe
[your-program] my_exe is /tmp/quz/my_exe
Expand Down
12 changes: 12 additions & 0 deletions internal/test_helpers/fixtures/exit_error
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Debug = true

[stage-4] Running tests for Stage #4: pn5
[stage-4] Running ./your_shell.sh
[your-program] $ invalid_apple_command
[your-program] invalid_apple_command: command not found
[stage-4] ✓ Received command not found message
[your-program] $ exit 0
[your-program] exit: command not found
[your-program] $
[stage-4] Expected program to exit with 0 exit code, program is still running.
[stage-4] Test failed
5 changes: 5 additions & 0 deletions internal/test_helpers/scenarios/exit_error/codecrafters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Set this to true if you want debug logs.
#
# These can be VERY verbose, so we suggest turning them off
# unless you really need them.
debug: true
22 changes: 22 additions & 0 deletions internal/test_helpers/scenarios/exit_error/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys


def main():
while True:
sys.stdout.write("$ ")
sys.stdout.flush()

command = input().strip()
parts = command.split(" ")
cmd = parts[0]
args = parts[1:]

if cmd == "exitt":
sys.exit(0)
else:
sys.stdout.write(f"{cmd}: command not found\n")
sys.stdout.flush()


if __name__ == "__main__":
main()
8 changes: 8 additions & 0 deletions internal/test_helpers/scenarios/exit_error/your_shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
#
# DON'T EDIT THIS!
#
# CodeCrafters uses this file to test your code. Don't make any changes here!
#
# DON'T EDIT THIS!
exec python3 $(dirname "$0")/main.py "$@"