Skip to content

Commit

Permalink
fix: add error names check to be sure
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Feb 1, 2024
1 parent e714a8e commit 424404f
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions server/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ import (
"github.com/nedpals/bugbuddy/server/executor"
"github.com/nedpals/bugbuddy/server/helpers"
"github.com/nedpals/errgoengine"
"github.com/nedpals/errgoengine/error_templates/python"
)

type TestCollector struct {
Engine *errgoengine.ErrgoEngine
ExitCode int
Outputs []string
Engine *errgoengine.ErrgoEngine
ExitCode int
ErrorNames []string
Outputs []string
}

func (tc *TestCollector) Collect(exitCode int, args, workingDir, stderr string) (int, int, error) {
tc.ExitCode = exitCode
result := helpers.AnalyzeError(tc.Engine, workingDir, stderr)
r, p, err := result.Stats()
if r > 0 {
tc.ErrorNames = append(tc.ErrorNames, result.Template.Name)
tc.Outputs = append(tc.Outputs, stderr)
}
return r, p, err
Expand All @@ -32,13 +35,17 @@ var cases = []struct {
Inputs [][]string
AfterInput [][]string
ErrorCounts []int
ErrorNames []string
Outputs []string
}{
{
Inputs: [][]string{
{"python3", "./test_programs/simple.py"},
},
ErrorCounts: []int{1},
ErrorNames: []string{
python.NameError.Name,
},
Outputs: []string{
`
Traceback (most recent call last):
Expand All @@ -54,6 +61,10 @@ NameError: name 'name' is not defined
{"python3", "./test_programs/complex.py"},
},
ErrorCounts: []int{2},
ErrorNames: []string{
python.NameError.Name,
python.ZeroDivisionError.Name,
},
Outputs: []string{
`
Traceback (most recent call last):
Expand All @@ -75,6 +86,9 @@ ZeroDivisionError: division by zero`,
{"python3", "./test_programs/dangling.py"},
},
ErrorCounts: []int{1},
ErrorNames: []string{
python.NameError.Name,
},
Outputs: []string{
`
Ooops I have been included in error
Expand Down Expand Up @@ -115,18 +129,28 @@ func TestExecute(t *testing.T) {
t.Fatalf("expected %d outputs, got %d", len(c.Outputs), len(collector.Outputs))
}

if len(collector.ErrorNames) != len(c.ErrorNames) {
t.Fatalf("expected %d error names, got %d", len(c.ErrorNames), len(collector.ErrorNames))
}

for i, errorNames := range collector.ErrorNames {
if errorNames != c.ErrorNames[i] {
t.Fatalf("expected %s, got %s", c.ErrorNames[i], errorNames)
}
}

for i, output := range collector.Outputs {
trimmedOut := strings.TrimSpace(output)
trimmedExp := strings.TrimSpace(c.Outputs[i])

if trimmedOut != trimmedExp {
fmt.Println([]byte(trimmedOut), []byte(trimmedExp))

t.Fatalf("expected %s, got %s", trimmedExp, trimmedOut)
}
}
})

collector.ErrorNames = []string{}
collector.Outputs = []string{}
}

Expand Down

0 comments on commit 424404f

Please sign in to comment.