Skip to content

Commit

Permalink
Merge pull request #77 from codecrafters-io/alpha-fix-alpine
Browse files Browse the repository at this point in the history
Fix `cat` error message on alpine
  • Loading branch information
ryan-gang authored Dec 21, 2024
2 parents 9b8cc3d + 6d15efc commit caa1360
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ test_bash:
make test_quoting_w_bash


test_vt: build
test_redirection_w_bash: build
CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/bash \
CODECRAFTERS_TEST_CASES_JSON="[ \
{\"slug\":\"ff0\",\"tester_log_prefix\":\"tester::#ff0\",\"title\":\"Stage #3: REPL\"}, \
{\"slug\":\"oo8\",\"tester_log_prefix\":\"tester::#oo8\",\"title\":\"Stage #1: Init\"}, \
{\"slug\":\"cz2\",\"tester_log_prefix\":\"tester::#cz2\",\"title\":\"Stage #2: Missing Command\"} \
{\"slug\":\"jv1\",\"tester_log_prefix\":\"tester::#jv1\",\"title\":\"Stage #13: Redirect stdout\"}, \
{\"slug\":\"vz4\",\"tester_log_prefix\":\"tester::#vz4\",\"title\":\"Stage #14: Redirect stderr\"}, \
{\"slug\":\"el9\",\"tester_log_prefix\":\"tester::#el9\",\"title\":\"Stage #15: Append stdout\"}, \
{\"slug\":\"un3\",\"tester_log_prefix\":\"tester::#un3\",\"title\":\"Stage #16: Append stderr\"} \
]" \
dist/main.out
3 changes: 2 additions & 1 deletion internal/stage_r1.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path"
"regexp"
"slices"

"github.com/codecrafters-io/shell-tester/internal/logged_shell_asserter"
Expand Down Expand Up @@ -109,7 +110,7 @@ func testR1(stageHarness *test_case_harness.TestCaseHarness) error {
responseTestCase = test_cases.CommandResponseTestCase{
Command: command5,
ExpectedOutput: fmt.Sprintf("cat: %s: No such file or directory", "nonexistent"),
FallbackPatterns: nil,
FallbackPatterns: []*regexp.Regexp{regexp.MustCompile(fmt.Sprintf("cat: can't open '%s': No such file or directory", "nonexistent"))},
SuccessMessage: "✓ Received error message",
}
if err := responseTestCase.Run(asserter, shell, logger); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/stage_r2.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func testR2(stageHarness *test_case_harness.TestCaseHarness) error {
responseTestCase = test_cases.CommandResponseTestCase{
Command: command6,
ExpectedOutput: fmt.Sprintf("cat: %s: No such file or directory", "nonexistent"),
FallbackPatterns: nil,
FallbackPatterns: []*regexp.Regexp{regexp.MustCompile(fmt.Sprintf("cat: can't open '%s': No such file or directory", "nonexistent"))},
SuccessMessage: "✓ Received redirected error message",
}
if err := responseTestCase.Run(asserter, shell, logger); err != nil {
Expand Down
9 changes: 6 additions & 3 deletions internal/stage_r4.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ func testR4(stageHarness *test_case_harness.TestCaseHarness) error {
"cat: nonexistent: No such file or directory",
"ls: nonexistent: No such file or directory",
}
linuxErrorMessage := "ls: cannot access 'nonexistent': No such file or directory"
essorMessagesInFileRegex := []*regexp.Regexp{regexp.MustCompile(fmt.Sprintf("^%s\n%s$", errorMessagesInFile[0], linuxErrorMessage))}

linuxLSErrorMessage := "ls: cannot access 'nonexistent': No such file or directory"
alpineCatErrorMessage := "cat: can't open 'nonexistent': No such file or directory"
essorMessagesInFileRegex := []*regexp.Regexp{
regexp.MustCompile(fmt.Sprintf("^%s\n%s$", errorMessagesInFile[0], linuxLSErrorMessage)),
regexp.MustCompile(fmt.Sprintf("^%s\n%s$", alpineCatErrorMessage, errorMessagesInFile[1])),
}
multiLineResponseTestCase := test_cases.CommandWithMultilineResponseTestCase{
Command: command7,
ExpectedOutput: errorMessagesInFile,
Expand Down

0 comments on commit caa1360

Please sign in to comment.