params

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 3 Imported by: 0

README

params

Build Status Coverage Status Go Reference MIT License

This package provides a simple way to run parameterized tests:

import (
    "math"
    "testing"

    "github.com/nitroshare/compare"
    "github.com/nitroshare/params"
)

func TestSquareRoot(t *testing.T) {
    type V struct {
		Name   string
        Number float64
        Root   float64
	}
	Run(
		t,
		func(t *testing.T, v *V) {
            if math.Sqrt(v.Number) != v.Root {
                t.Fatal("root doesn't match!")
            }
        },
		&V{
            Name:   "square root of nine",
            Number: 9,
            Root:   3,
        },
	)
}

This package works extremely well in conjunction with the compare package

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run[T any](
	t *testing.T,
	fn func(t *testing.T, v *T),
	values ...*T,
)

Run simplifies the process of running parameterized tests. The second parameter is a function that will be invoked once for each of the provided values (the remaining parameters).

It is highly recommended to include a string field named "Name" which is used to identify the test when it is run.

Types

This section is empty.

Jump to

Keyboard shortcuts

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