1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-24 08:32:22 +02:00
revive/testdata/unreachable-code.go
Abirdcfly fcc59adb72
add testing.FailNow and related function to unreachable check (#711)
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
2022-07-20 15:41:31 -07:00

61 lines
1.1 KiB
Go

package fixtures
import (
"fmt"
"log"
"os"
"testing"
)
func foo() int {
log.Fatalf("%s", "About to fail") // ignore
return 0 // MATCH /unreachable code after this statement/
return 1
Println("unreachable")
}
func f() {
fmt.Println("Hello, playground")
if true {
return // MATCH /unreachable code after this statement/
Println("unreachable")
os.Exit(2) // ignore
Println("also unreachable")
}
return // MATCH /unreachable code after this statement/
fmt.Println("Bye, playground")
}
func g() {
fmt.Println("Hello, playground")
if true {
return // ignore if next stmt is labeled
label:
os.Exit(2) // ignore
}
fmt.Println("Bye, playground")
}
func TestA(t *testing.T) {
tests := make([]int, 100)
for i := range tests {
println("i: ", i)
if i == 0 {
t.Fatal("i == 0") // MATCH /unreachable code after this statement/
println("unreachable")
continue
}
if i == 1 {
t.Fatalf("i:%d", i) // MATCH /unreachable code after this statement/
println("unreachable")
continue
}
if i == 2 {
t.FailNow() // MATCH /unreachable code after this statement/
println("unreachable")
continue
}
}
}