tests

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: BSD-3-Clause Imports: 6 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.

Documentation

Overview

Package tests implements auxiliary tools for testing package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EquateFloat64

func EquateFloat64(relchg float64) cmp.Option

EquateFloat64 compares two float64 numbers and reports them equal if their relative change is less than or equal to relchg. See: https://en.wikipedia.org/wiki/Relative_change

Example (Fail)
package main

import (
	"fmt"

	"github.com/google/go-cmp/cmp"
	"github.com/skhal/lab/go/tests"
)

func main() {
	diff := cmp.Diff(3.4, 3.1, tests.EquateFloat64(0.01))
	if diff != "" {
		fmt.Print("3.4 !~= 3.1")
		return
	}
	fmt.Print("3.4 ~= 3.1")
}
Output:
3.4 !~= 3.1
Example (Pass)
package main

import (
	"fmt"

	"github.com/google/go-cmp/cmp"
	"github.com/skhal/lab/go/tests"
)

func main() {
	diff := cmp.Diff(3.4, 3.1, tests.EquateFloat64(0.1))
	if diff != "" {
		fmt.Print("3.4 !~= 3.1")
		return
	}
	fmt.Print("3.4 ~= 3.1")
}
Output:
3.4 ~= 3.1

Types

type GoldenFile

type GoldenFile string

GoldenFile holds baseline data for regression tests.

func (GoldenFile) Diff

func (f GoldenFile) Diff(t *testing.T, buf string) string

Diff generates a difference between buf and contents of the golden file. It fails the test if it can't read the file.

func (GoldenFile) Write

func (f GoldenFile) Write(t *testing.T, data string)

Write updates contents of the golden file with data. It fails the test if it fails to write data.

Jump to

Keyboard shortcuts

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