Skip to content

You could use os.Exit() in Go tests

License

Notifications You must be signed in to change notification settings

corebreaker/texit

Repository files navigation

texit

Report Build Status Coverage Status GoDoc GitHub license Release

Yes, you can use os.Exit() in Go tests.

Inspired by https://talks.golang.org/2014/testing.slide#23

Example in a testing function

import (
	"os"

	"github.com/corebreaker/texit"
)

func TestWithExitDirectCall(t *testing.T) {
	stdout, stderr, status, err := DoTestWithExit(func() {
		// Something to do

		os.Exit(0)
	})

	// …
}