-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
test.go
73 lines (63 loc) · 1.4 KB
/
test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package runn
import (
"context"
"fmt"
"github.com/k1LoW/runn/exprtrace"
)
const testRunnerKey = "test"
type testRunner struct{}
type condFalseError struct {
cond string
tree string
}
func newCondFalseError(cond, tree string) *condFalseError {
return &condFalseError{
cond: cond,
tree: tree,
}
}
func (fe *condFalseError) Error() string {
tree := sprintMultilinef(" %s\n", "%s", fe.tree)
return fmt.Sprintf("condition is not true\n\nCondition:\n%s", tree)
}
func newTestRunner() *testRunner {
return &testRunner{}
}
func (rnr *testRunner) Run(ctx context.Context, s *step, first bool) error {
o := s.parent
cond := s.testCond
store := exprtrace.EvalEnv(o.store.toMap())
store[storeRootKeyIncluded] = o.included
if first {
if !s.deferred {
store[storeRootKeyPrevious] = o.store.latest()
}
} else {
if !s.deferred {
store[storeRootKeyPrevious] = o.store.previous()
}
store[storeRootKeyCurrent] = o.store.latest()
}
if err := rnr.run(ctx, cond, store, s, first); err != nil {
return err
}
return nil
}
func (rnr *testRunner) run(_ context.Context, cond string, store exprtrace.EvalEnv, s *step, first bool) error {
o := s.parent
tf, err := EvalWithTrace(cond, store)
if err != nil {
return err
}
if !tf.OutputAsBool() {
t, err := tf.FormatTraceTree()
if err != nil {
return err
}
return newCondFalseError(cond, t)
}
if first {
o.record(s.idx, nil)
}
return nil
}