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

fix minor unreachable code caused by t.Fatalf #530

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

Abirdcfly
Copy link
Contributor

@Abirdcfly Abirdcfly commented Aug 9, 2022

https://pkg.go.dev/testing#T.Fatalf

Fatalf is equivalent to Logf followed by FailNow.

https://pkg.go.dev/testing#T.FailNow

FailNow marks the function as having failed and stops its execution by calling runtime.Goexit (which then runs all deferred calls in the current goroutine).

see https://go.dev/play/p/LkLbybLy_oi for example

package main

import (
	"testing"
)

func TestLastIndex(t *testing.T) {
	t.Fatalf("this line will print and exit")
	t.Fatalf("this line cant print")
}

/* output:
=== RUN   TestLastIndex
    prog.go:8: this line will print and exit
--- FAIL: TestLastIndex (0.00s)
FAIL

Program exited.
*/

Signed-off-by: Abirdcfly <fp544037857@gmail.com>
Copy link
Member

@tonyghita tonyghita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tonyghita tonyghita merged commit 4878856 into graph-gophers:master Aug 9, 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 this pull request may close these issues.

None yet

2 participants