gocheckext

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2018 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gocheckext

GoDoc CircleCI Coverage Status Go Report Card

Extensions to the go-check unittest framework.

Provides statistics about executed checks so you can see how many real tests you've implemented so far.

Provides variant of DeepEqual checker which pretty-print differences.

... see godoc for full list of features.

Installation

go get github.com/powerman/gocheckext

Documentation

Overview

Package gocheckext provides extensions for github.com/go-check/check.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DeepLogErrors is a value for github.com/go-test/deep.LogErrors
	// while DeepEqualsPP.
	// In tests it's better to know when your DeepEqual check skip to
	// compare something.
	DeepLogErrors = true
	// DeepCompareUnexportedFields is a value for
	// github.com/go-test/deep.CompareUnexportedFields while DeepEqualsPP.
	// In tests it's usual to compare unexported fields.
	DeepCompareUnexportedFields = true
)
View Source
var DeepEqualsPP = NewCountingChecker(
	"DeepEqualsPP", []string{"obtained", "expected"}, deepEquals,
)

DeepEqualsPP works like gocheck's DeepEquals but also pretty-print a list of differences.

You can easily make all your current tests use DeepEqualsPP with:

func init() {
    DeepEquals = gocheckext.DeepEqualsPP
}

Functions

func CountChecker

func CountChecker(f check.Checker) check.Checker

CountChecker wrap usual Checker to count it calls. You should use it to wrap all your custom (not gocheck's ones) checkers. Example:

import . "github.com/dropbox/godropbox/gocheck2"
// wrap custom checker
var myChecker = gocheckext.CountChecker(myCheckerType{…})
func init() {
    // wrap checkers imported from godropbox
    AlmostEqual = gocheckext.CountChecker(AlmostEqual)
    BytesEquals = gocheckext.CountChecker(BytesEquals)
    GreaterThan = gocheckext.CountChecker(GreaterThan)
    ...
}

func CountingTestingT

func CountingTestingT(t *testing.T)

CountingTestingT should be called instead of gocheck's TestingT. It will report count of executed checks (like DeepEquals or IsNil) after usual TestingT report of passed/failed tests - so you can see how many real tests you've implemented so far.

func Test(t *testing.T) { gocheckext.CountingTestingT(t) }

Then run `go test` as usually and you'll see count of checks after count of tests, for ex.:

OK: 21 passed, 3 skipped
Checks: 197
--- PASS: Test (0.49s)

func NewChecker

func NewChecker(name string, params []string, code CheckFunc) check.Checker

NewChecker makes it easier to define your own checkers.

func NewCountingChecker

func NewCountingChecker(name string, params []string, code CheckFunc) check.Checker

NewCountingChecker is just a convenient shortcut for CountChecker(NewChecker(…)).

Types

type CheckFunc

type CheckFunc func([]interface{}, []string) (bool, string)

CheckFunc is a gocheck's Checker.Check function.

Jump to

Keyboard shortcuts

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