Skip to content

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.
*/

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.

2 participants