File tree 6 files changed +60
-0
lines changed 6 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 5
5
"fmt"
6
6
"strings"
7
7
8
+ "github.com/codecrafters-io/shell-tester/internal/condition_reader"
8
9
"github.com/codecrafters-io/shell-tester/internal/logged_shell_asserter"
9
10
"github.com/codecrafters-io/shell-tester/internal/shell_executable"
10
11
"github.com/codecrafters-io/shell-tester/internal/test_cases"
@@ -43,9 +44,14 @@ func testExit(stageHarness *test_case_harness.TestCaseHarness) error {
43
44
readErr := shell .ReadUntilConditionOrTimeout (utils .AsBool (assertFn ), logged_shell_asserter .SUBSEQUENT_READ_TIMEOUT )
44
45
output := virtual_terminal .BuildCleanedRow (shell .GetScreenState ()[asserter .GetLastLoggedRowIndex ()+ 1 ])
45
46
47
+ asserter .LogRemainingOutput ()
48
+
46
49
// We're expecting EOF since the program should've terminated
47
50
if ! errors .Is (readErr , shell_executable .ErrProgramExited ) {
48
51
if readErr == nil {
52
+ return fmt .Errorf ("Expected program to exit with 0 exit code, program is still running." )
53
+ } else if errors .Is (readErr , condition_reader .ErrConditionNotMet ) {
54
+
49
55
return fmt .Errorf ("Expected program to exit with 0 exit code, program is still running." )
50
56
} else {
51
57
// TODO: Other than ErrProgramExited, what other errors could we get? Are they user errors or internal errors?
Original file line number Diff line number Diff line change @@ -33,6 +33,13 @@ func TestStages(t *testing.T) {
33
33
StdoutFixturePath : "./test_helpers/fixtures/escape_codes" ,
34
34
NormalizeOutputFunc : normalizeTesterOutput ,
35
35
},
36
+ "exit_error_fail" : {
37
+ UntilStageSlug : "pn5" ,
38
+ CodePath : "./test_helpers/scenarios/exit_error" ,
39
+ ExpectedExitCode : 1 ,
40
+ StdoutFixturePath : "./test_helpers/fixtures/exit_error" ,
41
+ NormalizeOutputFunc : normalizeTesterOutput ,
42
+ },
36
43
"base_pass_bash" : {
37
44
UntilStageSlug : "ip1" ,
38
45
CodePath : "./test_helpers/bash" ,
Original file line number Diff line number Diff line change
1
+ Debug = true
2
+
3
+ [33m[stage-4] [0m[94mRunning tests for Stage #4: pn5[0m
4
+ [33m[stage-4] [0m[94mRunning ./your_shell.sh[0m
5
+ [33m[your-program] [0m$ invalid_apple_command
6
+ [33m[your-program] [0minvalid_apple_command: command not found
7
+ [33m[stage-4] [0m[92m✓ Received command not found message[0m
8
+ [33m[your-program] [0m$ exit 0
9
+ [33m[your-program] [0mexit: command not found
10
+ [33m[your-program] [0m$
11
+ [33m[stage-4] [0m[91mExpected program to exit with 0 exit code, program is still running.[0m
12
+ [33m[stage-4] [0m[91mTest failed[0m
Original file line number Diff line number Diff line change
1
+ # Set this to true if you want debug logs.
2
+ #
3
+ # These can be VERY verbose, so we suggest turning them off
4
+ # unless you really need them.
5
+ debug : true
Original file line number Diff line number Diff line change
1
+ import sys
2
+
3
+
4
+ def main ():
5
+ while True :
6
+ sys .stdout .write ("$ " )
7
+ sys .stdout .flush ()
8
+
9
+ command = input ().strip ()
10
+ parts = command .split (" " )
11
+ cmd = parts [0 ]
12
+ args = parts [1 :]
13
+
14
+ if cmd == "exitt" :
15
+ sys .exit (0 )
16
+ else :
17
+ sys .stdout .write (f"{ cmd } : command not found\n " )
18
+ sys .stdout .flush ()
19
+
20
+
21
+ if __name__ == "__main__" :
22
+ main ()
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ #
3
+ # DON'T EDIT THIS!
4
+ #
5
+ # CodeCrafters uses this file to test your code. Don't make any changes here!
6
+ #
7
+ # DON'T EDIT THIS!
8
+ exec python3 $( dirname " $0 " ) /main.py " $@ "
You can’t perform that action at this time.
0 commit comments