asserting

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2020 License: MIT Imports: 0 Imported by: 0

README

Asserting

Output verification library for asserting in go test

Usage

package my_test

import (
	"testing"

	. "github.com/Fire-Dragon-DoL/lab/asserting"
)

func TestAssert(t *testing.T) {
	Assert(t, 1 == 1) // Test is successful
}

func TestAssertPanic(t *testing.T) {
	Assert.Panic(t, func() {
		panic("A panic")
	}) // Test is successful
}

func TestAssertPanicMsg(t *testing.T) {
	panicFn := func() { panic("A panic") }
	Assert.Panic(t, panicFn, func(msg interface{}) bool {
		prose, ok := msg.(string)
		return ok && prose == "A panic"
	}) // Test is successful
}

func TestAssertDifferentPanicMsg(t *testing.T) {
	panicFn := func() { panic("A panic") }
	Assert.Panic(t, panicFn, func(msg interface{}) bool {
		prose, ok := msg.(string)
		return ok && prose == "Other panic"
	}) // Test fails
}

Documentation

Overview

Package asserting provides macros to verify output, well-suited for use in `go test`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assertion

type Assertion func(TestController, bool, ...interface{})

Assertion provides a function to assert results and recover from functions triggering panic

var Assert Assertion = Assertion(assertf)

Assert tests if the result is true

func (Assertion) Panic

func (assert Assertion) Panic(t TestController, do func())

Panic asserts that the provided function triggers panic

func (Assertion) PanicMsg

func (assert Assertion) PanicMsg(t TestController, do func(), assertMsg func(interface{}) bool)

PanicMsg asserts that the provided function triggers panic with the provided message

type TestController

type TestController interface {
	Helper()
	Errorf(format string, args ...interface{})
}

TestController provides functionality to interrupt and log during a test execution. It's usually `testing.T`

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL