package runner import ( "strings" "testing" ) func TestStatusString(t *testing.T) { cases := []struct { s Status want string }{ {StatusPass, "PASS"}, {StatusFail, "FAIL"}, {StatusTLE, "TLE"}, {StatusMLE, "MLE"}, {StatusBuildError, "BUILD_ERROR"}, {StatusRuntimeError, "RE"}, {Status(999), "UNKNOWN"}, } for _, c := range cases { if got := c.s.String(); got != c.want { t.Errorf("Status(%d).String() = %q, want %q", c.s, got, c.want) } } } func TestAddFailureAppends(t *testing.T) { r := &TestResult{} r.addFailure("first %s", "msg") r.addFailure("second %d", 2) if len(r.Failures) != 2 { t.Fatalf("Failures len = %d, want 2", len(r.Failures)) } if r.Failures[0] != "first msg" { t.Errorf("Failures[0] = %q", r.Failures[0]) } if !strings.Contains(r.Failures[1], "second 2") { t.Errorf("Failures[1] = %q", r.Failures[1]) } } func TestAggregateScoreEmpty(t *testing.T) { r := &SuiteResult{} if got := r.AggregateScore(); got != 0 { t.Errorf("empty aggregate = %v, want 0", got) } } func TestAggregateScoreSingleBuild(t *testing.T) { r := &SuiteResult{ Builds: []*BuildRun{{Name: "release", TotalScore: 0.75}}, } if got := r.AggregateScore(); got != 0.75 { t.Errorf("single build aggregate = %v, want 0.75", got) } } func TestAggregateScoreTakesMinimum(t *testing.T) { r := &SuiteResult{ Builds: []*BuildRun{ {Name: "release", TotalScore: 1.0}, {Name: "debug", TotalScore: 0.9}, {Name: "sanitized", TotalScore: 0.95}, }, } if got := r.AggregateScore(); got != 0.9 { t.Errorf("aggregate = %v, want 0.9 (minimum)", got) } } func TestAggregateScoreIgnoresSkipped(t *testing.T) { r := &SuiteResult{ Builds: []*BuildRun{ {Name: "release", TotalScore: 1.0}, {Name: "sanitized", Skipped: true, SkipReason: "platforms=linux"}, {Name: "debug", TotalScore: 0.8}, }, } if got := r.AggregateScore(); got != 0.8 { t.Errorf("aggregate with skipped = %v, want 0.8", got) } } func TestAggregateScoreAllSkipped(t *testing.T) { r := &SuiteResult{ Builds: []*BuildRun{ {Name: "a", Skipped: true}, {Name: "b", Skipped: true}, }, } if got := r.AggregateScore(); got != 1.0 { t.Errorf("all-skipped aggregate = %v, want 1.0", got) } }