package dsl import ( "strings" "testing" ) func TestParserErrorCases(t *testing.T) { const prefix = `build "go build ."` + "\n" cases := []struct { name string body string want string }{ { name: "group missing lparen", body: `group "g" { weight = 1.0 test("t") { stdout = "" } }`, want: "expected", }, { name: "group name not string", body: `group(foo) { weight = 1.0 test("t") { stdout = "" } }`, want: "expected", }, { name: "group missing rparen", body: `group("g" { weight = 1.0 test("t") { stdout = "" } }`, want: "expected", }, { name: "group missing lbrace", body: `group("g") weight = 1.0`, want: "expected", }, { name: "group non-ident in body", body: `group("g") { 42 }`, want: "unexpected token", }, { name: "group weight missing assign", body: `group("g") { weight 1.0 test("t") { stdout = "" } }`, want: "expected", }, { name: "group weight non-number", body: `group("g") { weight = "bad" test("t") { stdout = "" } }`, want: "", }, { name: "group timeout missing assign", body: `group("g") { weight = 1.0 timeout 5s test("t") { stdout = "" } }`, want: "expected", }, { name: "group timeout non-duration", body: `group("g") { weight = 1.0 timeout = "5s" test("t") { stdout = "" } }`, want: "", }, { name: "group memory_limit missing assign", body: `group("g") { weight = 1.0 memory_limit 64MB test("t") { stdout = "" } }`, want: "expected", }, { name: "group memory_limit non-size", body: `group("g") { weight = 1.0 memory_limit = "64MB" test("t") { stdout = "" } }`, want: "", }, { name: "group scoring missing assign", body: `group("g") { weight = 1.0 scoring partial test("t") { stdout = "" } }`, want: "expected", }, { name: "group scoring non-ident", body: `group("g") { weight = 1.0 scoring = "partial" test("t") { stdout = "" } }`, want: "expected", }, { name: "group env missing lparen", body: `group("g") { weight = 1.0 env "K" = "v" test("t") { stdout = "" } }`, want: "expected", }, { name: "group env key not string", body: `group("g") { weight = 1.0 env(K) = "v" test("t") { stdout = "" } }`, want: "expected", }, { name: "group env missing rparen", body: `group("g") { weight = 1.0 env("K" = "v" test("t") { stdout = "" } }`, want: "expected", }, { name: "group env missing assign", body: `group("g") { weight = 1.0 env("K") "v" test("t") { stdout = "" } }`, want: "expected", }, { name: "group env value not string", body: `group("g") { weight = 1.0 env("K") = K test("t") { stdout = "" } }`, want: "expected", }, { name: "group wrapper missing assign", body: `group("g") { weight = 1.0 wrapper "x" test("t") { stdout = "" } }`, want: "expected", }, { name: "group wrapper not string", body: `group("g") { weight = 1.0 wrapper = X test("t") { stdout = "" } }`, want: "expected", }, { name: "group unclosed", body: `group("g") { weight = 1.0 test("t") { stdout = "" }`, want: "", }, { name: "group pattern error", body: `group("g") { weight = 1.0 pattern { bogus = 1 } }`, want: "", }, { name: "test missing lparen", body: `group("g") { weight = 1.0 test "t" { stdout = "" } }`, want: "expected", }, { name: "test name not string", body: `group("g") { weight = 1.0 test(t) { stdout = "" } }`, want: "expected", }, { name: "test missing rparen", body: `group("g") { weight = 1.0 test("t" { stdout = "" } }`, want: "expected", }, { name: "test missing lbrace", body: `group("g") { weight = 1.0 test("t") stdout = "" }`, want: "expected", }, { name: "test non-ident in body", body: `group("g") { weight = 1.0 test("t") { 42 } }`, want: "unexpected token", }, { name: "test stdin missing assign", body: `group("g") { weight = 1.0 test("t") { stdin "x" stdout = "" } }`, want: "expected", }, { name: "test stdin not string", body: `group("g") { weight = 1.0 test("t") { stdin = 1 stdout = "" } }`, want: "expected", }, { name: "test args missing assign", body: `group("g") { weight = 1.0 test("t") { args "x" stdout = "" } }`, want: "expected", }, { name: "test exitCode missing assign", body: `group("g") { weight = 1.0 test("t") { exitCode 0 stdout = "" } }`, want: "expected", }, { name: "test exitCode not int", body: `group("g") { weight = 1.0 test("t") { exitCode = "x" stdout = "" } }`, want: "", }, { name: "test timeout missing assign", body: `group("g") { weight = 1.0 test("t") { timeout 2s stdout = "" } }`, want: "expected", }, { name: "test timeout not duration", body: `group("g") { weight = 1.0 test("t") { timeout = "2s" stdout = "" } }`, want: "", }, { name: "test memory_limit missing assign", body: `group("g") { weight = 1.0 test("t") { memory_limit 64MB stdout = "" } }`, want: "expected", }, { name: "test memory_limit not size", body: `group("g") { weight = 1.0 test("t") { memory_limit = "64MB" stdout = "" } }`, want: "", }, { name: "test wrapper missing assign", body: `group("g") { weight = 1.0 test("t") { wrapper "x" stdout = "" } }`, want: "expected", }, { name: "test wrapper not string", body: `group("g") { weight = 1.0 test("t") { wrapper = X stdout = "" } }`, want: "expected", }, { name: "test env missing lparen", body: `group("g") { weight = 1.0 test("t") { env "K" = "v" stdout = "" } }`, want: "expected", }, { name: "test env key not string", body: `group("g") { weight = 1.0 test("t") { env(K) = "v" stdout = "" } }`, want: "expected", }, { name: "test env missing rparen", body: `group("g") { weight = 1.0 test("t") { env("K" = "v" stdout = "" } }`, want: "expected", }, { name: "test env missing assign", body: `group("g") { weight = 1.0 test("t") { env("K") "v" stdout = "" } }`, want: "expected", }, { name: "test env value not string", body: `group("g") { weight = 1.0 test("t") { env("K") = K stdout = "" } }`, want: "expected", }, { name: "test file missing lparen", body: `group("g") { weight = 1.0 test("t") { file "x" = "y" stdout = "" } }`, want: "expected", }, { name: "test file key not string", body: `group("g") { weight = 1.0 test("t") { file(x) = "y" stdout = "" } }`, want: "expected", }, { name: "test file missing rparen", body: `group("g") { weight = 1.0 test("t") { file("x" = "y" stdout = "" } }`, want: "expected", }, { name: "test file missing assign", body: `group("g") { weight = 1.0 test("t") { file("x") "y" stdout = "" } }`, want: "expected", }, { name: "test file value not string", body: `group("g") { weight = 1.0 test("t") { file("x") = y stdout = "" } }`, want: "expected", }, { name: "test outFile missing lparen", body: `group("g") { weight = 1.0 test("t") { outFile "x" = "y" stdout = "" } }`, want: "expected", }, { name: "test outFile key not string", body: `group("g") { weight = 1.0 test("t") { outFile(x) = "y" stdout = "" } }`, want: "expected", }, { name: "test outFile missing rparen", body: `group("g") { weight = 1.0 test("t") { outFile("x" = "y" stdout = "" } }`, want: "expected", }, { name: "test outFile missing assign", body: `group("g") { weight = 1.0 test("t") { outFile("x") "y" stdout = "" } }`, want: "expected", }, { name: "test outFile value not string", body: `group("g") { weight = 1.0 test("t") { outFile("x") = y stdout = "" } }`, want: "expected", }, { name: "test unclosed", body: `group("g") { weight = 1.0 test("t") { stdout = ""`, want: "", }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { _, _, err := Parse(prefix + c.body) if err == nil { t.Fatalf("expected error, got nil") } if c.want != "" && !strings.Contains(err.Error(), c.want) { t.Errorf("error = %q, want substring %q", err.Error(), c.want) } }) } }