Documentation

Overview

Package skip provides functions for skipping a test and printing the source code of the condition used to skip the test.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func If

func If(t skipT, condition BoolOrCheckFunc, msgAndArgs ...interface{})

If the condition expression evaluates to true, or the condition function returns true, skip the test. The skip message will contain the source code of the expression. Extra message text can be passed as a format string with args

Example
package main

import (
	"testing"

	"gotest.tools/skip"
)

func MissingFeature() bool { return false }

var t = &testing.T{}

func main() {
	//   --- SKIP: TestName (0.00s)
	//           skip.go:19: MissingFeature
	skip.If(t, MissingFeature)

	//   --- SKIP: TestName (0.00s)
	//           skip.go:19: MissingFeature: coming soon
	skip.If(t, MissingFeature, "coming soon")
}
Output:

Example (WithExpression)
package main

import (
	"testing"

	"gotest.tools/skip"
)

var apiVersion = ""

type env struct{}

func (e env) hasFeature(_ string) bool { return false }

var testEnv = env{}

var t = &testing.T{}

func main() {
	//   --- SKIP: TestName (0.00s)
	//           skip.go:19: apiVersion < version("v1.24")
	skip.If(t, apiVersion < version("v1.24"))

	//   --- SKIP: TestName (0.00s)
	//           skip.go:19: !textenv.hasFeature("build"): coming soon
	skip.If(t, !testEnv.hasFeature("build"), "coming soon")
}

func version(v string) string {
	return v
}
Output:

Types

type BoolOrCheckFunc

type BoolOrCheckFunc interface{}

BoolOrCheckFunc can be a bool or func() bool, other types will panic

Source Files