1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This program is processed by the cover command, and then testAll is called.
6 // The test driver in main.go can then compare the coverage statistics with expectation.
8 // The word LINE is replaced by the line number in this file. When the file is executed,
9 // the coverage processing has changed the line numbers, so we can't use runtime.Caller.
13 const anything = 1e9 // Just some unlikely value that means "we got here, don't care how often"
29 // The indexes of the counters in testPanic are known to main.go
32 // This test appears first because the index of its counters is known to main.go
38 panic("should not get next line")
39 check(LINE, 0) // this is GoCover.Count[panicIndex]
40 // The next counter is in testSimple and it will be non-zero.
41 // If the panic above does not trigger a counter, the test will fail
42 // because GoCover.Count[panicIndex] will be the one in testSimple.
60 for i := 0; i < 3; i++ {
61 if checkVal(LINE, 3, i) <= 2 {
64 if checkVal(LINE, 3, i) <= 1 {
67 if checkVal(LINE, 3, i) <= 0 {
71 for i := 0; i < 3; i++ {
72 if checkVal(LINE, 3, i) <= 1 {
78 for i := 0; i < 3; i++ {
79 if checkVal(LINE, 3, i) <= 0 {
81 } else if checkVal(LINE, 2, i) <= 1 {
83 } else if checkVal(LINE, 1, i) <= 2 {
85 } else if checkVal(LINE, 0, i) <= 3 {
89 if func(a, b int) bool { return a < b }(3, 4) {
95 for i := 0; i < 10; func() { i++; check(LINE, 10) }() {
101 for _, f := range []func(){
102 func() { check(LINE, 1) },
109 func testBlockRun() {
128 for i := 0; i < 5; func() { i++; check(LINE, 5) }() {
142 func testTypeSwitch() {
143 var x = []interface{}{1, 2.0, "hi"}
144 for _, v := range x {
145 switch func() { check(LINE, 3) }(); v.(type) {
163 for i := 0; i < 1000; i++ {
170 check(LINE, anything)
172 check(LINE, anything)
181 c1 := make(chan int, 1000)
182 c2 := make(chan int, 1000)
183 for i := 0; i < 1000; i++ {
200 // Empty control statements created syntax errors. This function
201 // is here just to be sure that those are handled correctly now.
202 func testEmptySwitches() {
207 switch i := (interface{})(3).(int); i {