Skip to content

Commit 0d8a00e

Browse files
authored
Merge pull request #10 from gdt-dev/issue-8
call t.Error() from sub-tests not Scenario.Run()
2 parents e14a1af + eea5de6 commit 0d8a00e

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

errors/failure.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ var (
3131
)
3232

3333
// TimeoutExceeded returns an ErrTimeoutExceeded when a test's execution
34-
// exceeds a timeout length.
35-
func TimeoutExceeded(duration string) error {
34+
// exceeds a timeout length. The optional failure parameter indicates a failed
35+
// assertion that occurred before a timeout was reached.
36+
func TimeoutExceeded(duration string, failure error) error {
37+
if failure != nil {
38+
return fmt.Errorf(
39+
"%w: timed out waiting for assertion to succeed (%s)",
40+
failure, duration,
41+
)
42+
}
3643
return fmt.Errorf("%s (%s)", ErrTimeoutExceeded, duration)
3744
}
3845

plugin/exec/eval.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ func (s *Spec) Eval(ctx context.Context, t *testing.T) *result.Result {
7171
eerr, _ := err.(*exec.ExitError)
7272
ec = eerr.ExitCode()
7373
}
74-
assertions := newAssertions(s.Assert, ec, outbuf, errbuf)
75-
return result.New(result.WithFailures(assertions.Failures()...))
74+
a := newAssertions(s.Assert, ec, outbuf, errbuf)
75+
if !a.OK() {
76+
for _, fail := range a.Failures() {
77+
t.Error(fail)
78+
}
79+
}
80+
return result.New(result.WithFailures(a.Failures()...))
7681
}

scenario/run.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
8383
res := spec.Eval(specCtx, t)
8484
if res.HasRuntimeError() {
8585
rterr = res.RuntimeError()
86+
t.Fatal(rterr)
8687
break
8788
}
8889
// Results can have arbitrary run data stored in them and we
@@ -91,15 +92,6 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
9192
if res.HasData() {
9293
ctx = gdtcontext.StorePriorRun(ctx, res.Data())
9394
}
94-
for _, failure := range res.Failures() {
95-
if gdtcontext.TimedOut(specCtx, failure) {
96-
if to != nil && !to.Expected {
97-
t.Fatal(gdterrors.TimeoutExceeded(to.After))
98-
}
99-
} else {
100-
t.Fatal(failure)
101-
}
102-
}
10395
if wait != nil && wait.After != "" {
10496
debug.Println(ctx, t, "wait: %s after", wait.After)
10597
time.Sleep(wait.AfterDuration())

0 commit comments

Comments
 (0)