1
2
3
4
5
6
7 package cfile
8
9 import "testing"
10
11 var funcInvoked bool
12
13
14 func thisFunctionOnlyCalledFromSnapshotTest(n int) int {
15 if funcInvoked {
16 panic("bad")
17 }
18 funcInvoked = true
19
20
21
22 t := 0
23 for i := 0; i < n; i++ {
24 for j := 0; j < i; j++ {
25 t += i ^ j
26 }
27 }
28 return t
29 }
30
31
32
33
34 func TestCoverageSnapshotImpl(t *testing.T) {
35 C1 := Snapshot()
36 thisFunctionOnlyCalledFromSnapshotTest(15)
37 C2 := Snapshot()
38 cond := "C1 > C2"
39 val := C1 > C2
40 if testing.CoverMode() != "" {
41 cond = "C1 >= C2"
42 val = C1 >= C2
43 }
44 t.Logf("%f %f\n", C1, C2)
45 if val {
46 t.Errorf("erroneous snapshots, %s = true C1=%f C2=%f",
47 cond, C1, C2)
48 }
49 }
50
View as plain text