...
1
2
3
4
5
6
7
8
9 package main
10
11 import (
12 "fmt"
13 "os"
14 )
15
16 func main() {
17 testAll()
18 verify()
19 }
20
21 type block struct {
22 count uint32
23 line uint32
24 }
25
26 var counters = make(map[block]bool)
27
28
29 var coverTest = &thisNameMustBeVeryLongToCauseOverflowOfCounterIncrementStatementOntoNextLineForTest
30
31
32 func check(line, count uint32) {
33 b := block{
34 count,
35 line,
36 }
37 counters[b] = true
38 }
39
40
41
42 func checkVal(line, count uint32, val int) int {
43 b := block{
44 count,
45 line,
46 }
47 counters[b] = true
48 return val
49 }
50
51 var PASS = true
52
53
54 func verify() {
55 for b := range counters {
56 got, index := count(b.line)
57 if b.count == anything && got != 0 {
58 got = anything
59 }
60 if got != b.count {
61 fmt.Fprintf(os.Stderr, "test_go:%d expected count %d got %d [counter %d]\n", b.line, b.count, got, index)
62 PASS = false
63 }
64 }
65 verifyPanic()
66 if !PASS {
67 fmt.Fprintf(os.Stderr, "FAIL\n")
68 os.Exit(2)
69 }
70 }
71
72
73
74 func verifyPanic() {
75 if coverTest.Count[panicIndex-1] != 1 {
76
77 fmt.Fprintf(os.Stderr, "bad before panic")
78 PASS = false
79 }
80 if coverTest.Count[panicIndex] != 0 {
81 fmt.Fprintf(os.Stderr, "bad at panic: %d should be 0\n", coverTest.Count[panicIndex])
82 PASS = false
83 }
84 if coverTest.Count[panicIndex+1] != 1 {
85 fmt.Fprintf(os.Stderr, "bad after panic")
86 PASS = false
87 }
88 }
89
90
91 func count(line uint32) (uint32, int) {
92
93
94
95
96
97 index := -1
98 indexLo := uint32(1e9)
99 for i := range coverTest.Count {
100 lo, hi := coverTest.Pos[3*i], coverTest.Pos[3*i+1]
101 if lo == line && line == hi {
102 return coverTest.Count[i], i
103 }
104
105 if lo <= line && line <= hi && indexLo > lo {
106 index = i
107 indexLo = lo
108 }
109 }
110 if index == -1 {
111 fmt.Fprintln(os.Stderr, "cover_test: no counter for line", line)
112 PASS = false
113 return 0, 0
114 }
115 return coverTest.Count[index], index
116 }
117
View as plain text