Back to godoc.org
gotest.tools / skip

Package skip

v1.4.0
Latest Go to latest

The latest major version is v3.

Published: Mar 21, 2018 | License: Apache-2.0 | Module: gotest.tools

Overview

Package skip provides functions for skipping based on a condition.

Index

Examples

func If

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

If skips the test if the check function returns true. The skip message will contain the name of the check function. Extra message text can be passed as a format string with args

Example

Code:

package main

import (
	"github.com/gotestyourself/gotestyourself/skip"
	"testing"
)

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")
}

func IfCondition

func IfCondition(t skipT, condition bool, msgAndArgs ...interface{})

IfCondition skips the test if the condition is true. The skip message will contain the source of the expression passed as the condition. Extra message text can be passed as a format string with args.

Deprecated: Use If() which now accepts bool arguments

Example

Code:

package main

import (
	"github.com/gotestyourself/gotestyourself/skip"
	"testing"
)

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.IfCondition(t, apiVersion < version("v1.24"))

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

func version(v string) string {
	return v
}

type BoolOrCheckFunc

type BoolOrCheckFunc interface{}

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

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier