package skip

import "gotest.tools/v3/skip"

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

Index

Examples

Functions

func If

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

If the condition expression evaluates to true, skip the test.

The condition argument may be one of three types: bool, func() bool, or func() SkipResult. When called with a bool, the test will be skip if the condition evaluates to true. When called with a func() bool, the test will be skip if the function returns true. When called with a func() Result, the test will be skip if the Skip method of the result returns true. The skip message will contain the source code of the expression. Extra message text can be passed as a format string with args.

Example

Code:play 

package main

import (
	"testing"

	"gotest.tools/v3/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")
}
Example (WithExpression)

Code:play 

package main

import (
	"testing"

	"gotest.tools/v3/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
}

Types

type BoolOrCheckFunc

type BoolOrCheckFunc interface{}

BoolOrCheckFunc can be a bool, func() bool, or func() Result. Other types will panic

type Result

type Result interface {
	Skip() bool
	Message() string
}

Result of skip function

Source Files

skip.go

Version
v3.5.2 (latest)
Published
Sep 5, 2024
Platform
linux/amd64
Imports
7 packages
Last checked
2 months ago

Tools for package owners.