-
Notifications
You must be signed in to change notification settings - Fork 4
/
conclusion.go
58 lines (50 loc) · 1.7 KB
/
conclusion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2019-2024 Vasiliy Vasilyuk. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package golden
import "fmt"
// Conclusion interface wrapping conclusion.
type Conclusion interface {
// Failed reports whether the function has failed.
Failed() bool
// Fail marks the function as having failed but continues execution.
// Also accompanying messages will be printed in the output of the test.
// ATTENTION! executed only if expression is false `Failed() == true`.
Fail()
// FailNow marks the function as having failed and stops its execution
// by calling runtime.Goexit (which then runs all deferred calls in the
// current goroutine).
// ATTENTION! executed only if expression is false `Failed() == true`.
FailNow()
}
type conclusion struct {
successful bool
t TestingTB
diff fmt.Stringer
}
func newConclusion(test TestingTB) conclusion {
return conclusion{t: test}
}
// Failed reports whether the function has failed.
func (c conclusion) Failed() bool {
return !c.successful
}
// Fail marks the function as having failed but continues execution.
// Also accompanying messages will be printed in the output of the test.
// ATTENTION! executed only if expression is false `Failed() == true`.
func (c conclusion) Fail() {
if c.Failed() {
c.t.Logf("%s", c.diff)
c.t.Fail()
}
}
// FailNow marks the function as having failed and stops its execution
// by calling runtime.Goexit (which then runs all deferred calls in the
// current goroutine).
// ATTENTION! executed only if expression is false `Failed() == true`.
func (c conclusion) FailNow() {
if c.Failed() {
c.t.Logf("%s", c.diff)
c.t.FailNow()
}
}