Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add testing.FailNow and related function to unreachable check #710

Closed
Abirdcfly opened this issue Jul 20, 2022 · 0 comments · Fixed by #711
Closed

add testing.FailNow and related function to unreachable check #710

Abirdcfly opened this issue Jul 20, 2022 · 0 comments · Fixed by #711

Comments

@Abirdcfly
Copy link
Contributor

Abirdcfly commented Jul 20, 2022

Is your feature request related to a problem? Please describe.

A simplified code is as follows:

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
		}
		/*  Skip is used to temporarily skip tests. The code following it is intentionally unreachable.
			if i == 3 {
				t.Skip("i == 3") // MATCH /unreachable code after this statement/
				println("unreachable")
				continue
			}
			if i == 4 {
				t.Skipf("i:%d", i) // MATCH /unreachable code after this statement/
				println("unreachable")
				continue
			}
			if i == 5 {
				t.SkipNow() // MATCH /unreachable code after this statement/
				println("unreachable")
				continue
			}
		*/
	}
}

The actual code can be seen in k8s https://github.com/kubernetes/kubernetes/pull/111228/files#diff-b5b428649cab55e247eddbd00bc278c628c40ed524814ffe9dede44af19ee3b5R1899 and etcd etcd-io/etcd#14235

Describe the solution you'd like
I wish there was a way to detect them

Describe alternatives you've considered
Goland can detect them, but has bug in some situation, see https://youtrack.jetbrains.com/issue/GO-13383

go vet cant detect this. Some discussions are here golang/go#53968

Additional context
None

@Abirdcfly Abirdcfly changed the title add testing.FailNow testing.SkipNow and related function to unreachable check add testing.FailNow and related function to unreachable check Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant