Skip to content

Commit

Permalink
refactor: update test cases to use MultiLineAssertion
Browse files Browse the repository at this point in the history
- Replaced ExpectedOutput and FallbackPatterns with MultiLineAssertion in CommandWithMultilineResponseTestCase for stages R1 and R3.
- Enhanced test case structure for improved assertion handling and consistency across tests.
  • Loading branch information
ryan-gang committed Dec 27, 2024
1 parent 0a20218 commit 3ec77e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
10 changes: 6 additions & 4 deletions internal/stage_r1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"regexp"
"slices"

"github.com/codecrafters-io/shell-tester/internal/assertions"
"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 @@ -65,11 +66,12 @@ func testR1(stageHarness *test_case_harness.TestCaseHarness) error {
return err
}

fmt.Println(randomWords)

multiLineTestCase := test_cases.CommandWithMultilineResponseTestCase{
Command: command2,
ExpectedOutput: randomWords,
FallbackPatterns: nil,
SuccessMessage: "✓ Received redirected file content",
Command: command2,
MultiLineAssertion: assertions.NewMultiLineAssertion(randomWords),
SuccessMessage: "✓ Received redirected file content",
}
if err := multiLineTestCase.Run(asserter, shell, logger); err != nil {
return err
Expand Down
22 changes: 10 additions & 12 deletions internal/stage_r3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path"
"slices"

"github.com/codecrafters-io/shell-tester/internal/assertions"
"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 @@ -64,10 +65,9 @@ func testR3(stageHarness *test_case_harness.TestCaseHarness) error {
}

responseTestCase := test_cases.CommandWithMultilineResponseTestCase{
Command: command2,
ExpectedOutput: randomWords,
FallbackPatterns: nil,
SuccessMessage: "✓ Received redirected file content",
Command: command2,
MultiLineAssertion: assertions.NewMultiLineAssertion(randomWords),
SuccessMessage: "✓ Received redirected file content",
}

if err := responseTestCase.Run(asserter, shell, logger); err != nil {
Expand Down Expand Up @@ -98,10 +98,9 @@ func testR3(stageHarness *test_case_harness.TestCaseHarness) error {
}

responseTestCase = test_cases.CommandWithMultilineResponseTestCase{
Command: command6,
ExpectedOutput: []string{message1, message2},
FallbackPatterns: nil,
SuccessMessage: "✓ Received redirected file content",
Command: command6,
MultiLineAssertion: assertions.NewMultiLineAssertion([]string{message1, message2}),
SuccessMessage: "✓ Received redirected file content",
}
if err := responseTestCase.Run(asserter, shell, logger); err != nil {
return err
Expand Down Expand Up @@ -129,10 +128,9 @@ func testR3(stageHarness *test_case_harness.TestCaseHarness) error {
}

responseTestCase = test_cases.CommandWithMultilineResponseTestCase{
Command: command9,
ExpectedOutput: append([]string{"List of files:"}, randomWords...),
FallbackPatterns: nil,
SuccessMessage: "✓ Received redirected file content",
Command: command9,
MultiLineAssertion: assertions.NewMultiLineAssertion(append([]string{"List of files:"}, randomWords...)),
SuccessMessage: "✓ Received redirected file content",
}
if err := responseTestCase.Run(asserter, shell, logger); err != nil {
return err
Expand Down

0 comments on commit 3ec77e8

Please sign in to comment.