Skip to content

Commit

Permalink
Merge pull request #35 from codecrafters-io/move-error-from-stage-4-t…
Browse files Browse the repository at this point in the history
…o-10

Update error handling in parsing tests and adjust test case outputs.
  • Loading branch information
rohitpaulk authored Aug 24, 2024
2 parents 83adcf1 + b1bf86b commit 5c5b28c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
14 changes: 12 additions & 2 deletions internal/stage_p10.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ func testParseErrors(stageHarness *test_case_harness.TestCaseHarness) error {

logger := stageHarness.Logger

// Unterminated string
error1 := fmt.Sprintf("\"%s", random.RandomElementFromArray(STRINGS))
error2 := fmt.Sprintf("(%d +)", getRandInt())
error3 := "+"

// Unbalanced parentheses
error2 := "(foo"

// Missing operand
error3 := fmt.Sprintf("(%d +)", getRandInt())

// Missing operands
error4 := "+"

parseTestCase := testcases.MultiParseTestCase{
TestCases: []testcases.ParseTestCase{
{FileContents: error1, ExpectsError: true},
{FileContents: error2, ExpectsError: true},
{FileContents: error3, ExpectsError: true},
{FileContents: error4, ExpectsError: true},
},
}
return parseTestCase.RunAll(b, logger)
Expand Down
6 changes: 4 additions & 2 deletions internal/stage_p4.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package internal

import (
"fmt"

"github.com/codecrafters-io/interpreter-tester/internal/interpreter_executable"
testcases "github.com/codecrafters-io/interpreter-tester/internal/test_cases"
"github.com/codecrafters-io/tester-utils/test_case_harness"
Expand All @@ -14,13 +16,13 @@ func testParseParens(stageHarness *test_case_harness.TestCaseHarness) error {
parens1 := "(\"foo\")"
parens2 := "((true))"
parens3 := "(nil)"
parens4 := "(\"foo\""
parens4 := fmt.Sprintf("(%d.%d)", getRandInt(), getRandInt())
parseTestCase := testcases.MultiParseTestCase{
TestCases: []testcases.ParseTestCase{
{FileContents: parens1, ExpectsError: false},
{FileContents: parens2, ExpectsError: false},
{FileContents: parens3, ExpectsError: false},
{FileContents: parens4, ExpectsError: true},
{FileContents: parens4, ExpectsError: false},
},
}
return parseTestCase.RunAll(b, logger)
Expand Down
45 changes: 26 additions & 19 deletions internal/test_helpers/fixtures/pass_parsing
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@ Debug = true
[stage-10] [test-1] ✓ Received exit code 65.
[stage-10] [test-2] Running test case: 2
[stage-10] [test-2] Writing contents to ./test.lox:
[stage-10] [test-2] [test.lox] (49 +)
[stage-10] [test-2] [test.lox] (foo
[stage-10] [test-2] $ ./your_program.sh parse test.lox
[your_program] [line 1] Error at ')': Expect expression.
[your_program] [line 1] Error at 'foo': Expect expression.
[stage-10] [test-2] ✓ 1 line(s) match on stdout
[stage-10] [test-2] ✓ Received exit code 65.
[stage-10] [test-3] Running test case: 3
[stage-10] [test-3] Writing contents to ./test.lox:
[stage-10] [test-3] [test.lox] +
[stage-10] [test-3] [test.lox] (49 +)
[stage-10] [test-3] $ ./your_program.sh parse test.lox
[your_program] [line 1] Error at '+': Expect expression.
[your_program] [line 1] Error at ')': Expect expression.
[stage-10] [test-3] ✓ 1 line(s) match on stdout
[stage-10] [test-3] ✓ Received exit code 65.
[stage-10] [test-4] Running test case: 4
[stage-10] [test-4] Writing contents to ./test.lox:
[stage-10] [test-4] [test.lox] +
[stage-10] [test-4] $ ./your_program.sh parse test.lox
[your_program] [line 1] Error at '+': Expect expression.
[stage-10] [test-4] ✓ 1 line(s) match on stdout
[stage-10] [test-4] ✓ Received exit code 65.
[stage-10] Test passed.

[stage-9] Running tests for Stage #9: ht8
Expand Down Expand Up @@ -204,50 +211,50 @@ Debug = true
[stage-4] [test-3] ✓ Received exit code 0.
[stage-4] [test-4] Running test case: 4
[stage-4] [test-4] Writing contents to ./test.lox:
[stage-4] [test-4] [test.lox] ("foo"
[stage-4] [test-4] [test.lox] (11.95)
[stage-4] [test-4] $ ./your_program.sh parse test.lox
[your_program] [line 1] Error at end: Expect ')' after expression.
[your_program] (group 11.95)
[stage-4] [test-4] ✓ 1 line(s) match on stdout
[stage-4] [test-4] ✓ Received exit code 65.
[stage-4] [test-4] ✓ Received exit code 0.
[stage-4] Test passed.

[stage-3] Running tests for Stage #3: th5
[stage-3] [test-1] Running test case: 1
[stage-3] [test-1] Writing contents to ./test.lox:
[stage-3] [test-1] [test.lox] "baz bar"
[stage-3] [test-1] [test.lox] "quz foo"
[stage-3] [test-1] $ ./your_program.sh parse test.lox
[your_program] baz bar
[your_program] quz foo
[stage-3] [test-1] ✓ 1 line(s) match on stdout
[stage-3] [test-1] ✓ Received exit code 0.
[stage-3] [test-2] Running test case: 2
[stage-3] [test-2] Writing contents to ./test.lox:
[stage-3] [test-2] [test.lox] "'bar'"
[stage-3] [test-2] [test.lox] "'foo'"
[stage-3] [test-2] $ ./your_program.sh parse test.lox
[your_program] 'bar'
[your_program] 'foo'
[stage-3] [test-2] ✓ 1 line(s) match on stdout
[stage-3] [test-2] ✓ Received exit code 0.
[stage-3] [test-3] Running test case: 3
[stage-3] [test-3] Writing contents to ./test.lox:
[stage-3] [test-3] [test.lox] "// baz"
[stage-3] [test-3] [test.lox] "// quz"
[stage-3] [test-3] $ ./your_program.sh parse test.lox
[your_program] // baz
[your_program] // quz
[stage-3] [test-3] ✓ 1 line(s) match on stdout
[stage-3] [test-3] ✓ Received exit code 0.
[stage-3] [test-4] Running test case: 4
[stage-3] [test-4] Writing contents to ./test.lox:
[stage-3] [test-4] [test.lox] "72"
[stage-3] [test-4] [test.lox] "90"
[stage-3] [test-4] $ ./your_program.sh parse test.lox
[your_program] 72
[your_program] 90
[stage-3] [test-4] ✓ 1 line(s) match on stdout
[stage-3] [test-4] ✓ Received exit code 0.
[stage-3] Test passed.

[stage-2] Running tests for Stage #2: ra8
[stage-2] [test-1] Running test case: 1
[stage-2] [test-1] Writing contents to ./test.lox:
[stage-2] [test-1] [test.lox] 83
[stage-2] [test-1] [test.lox] 91
[stage-2] [test-1] $ ./your_program.sh parse test.lox
[your_program] 83.0
[your_program] 91.0
[stage-2] [test-1] ✓ 1 line(s) match on stdout
[stage-2] [test-1] ✓ Received exit code 0.
[stage-2] [test-2] Running test case: 2
Expand All @@ -259,9 +266,9 @@ Debug = true
[stage-2] [test-2] ✓ Received exit code 0.
[stage-2] [test-3] Running test case: 3
[stage-2] [test-3] Writing contents to ./test.lox:
[stage-2] [test-3] [test.lox] 90.91
[stage-2] [test-3] [test.lox] 12.52
[stage-2] [test-3] $ ./your_program.sh parse test.lox
[your_program] 90.91
[your_program] 12.52
[stage-2] [test-3] ✓ 1 line(s) match on stdout
[stage-2] [test-3] ✓ Received exit code 0.
[stage-2] Test passed.
Expand Down

0 comments on commit 5c5b28c

Please sign in to comment.