guards

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package guards provides source-level regression checks. Consumers run these from their own test suite to prevent a known bug class from silently coming back through a refactor.

Each guard reads files under a directory, applies a regex (or absence check), and reports a failure via the testing.TB so the failure is attributable to the call site.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitBoxDedupOrder

func BitBoxDedupOrder(t TB, root, include string)

BitBoxDedupOrder fails if any source file under root reverses the `seenPackets.contains/has/includes` → `seenPackets.clear/removeAll/delete` ordering. Thin wrapper around quirk P2.

func MustMatchAtLeast

func MustMatchAtLeast(t TB, root, include string, pattern *regexp.Regexp, min int, reason string)

MustMatchAtLeast fails t if pattern does not match at least min times. Useful for "every exported func must call recoverPanic" style checks when paired with a tight pattern.

func MustNotMatch

func MustNotMatch(t TB, root, include string, pattern *regexp.Regexp, reason string)

MustNotMatch fails t if pattern matches any line in any file under root matching include (a doublestar-free glob, e.g. "*.go"). reason is shown alongside the failure to explain the rule.

func MustOrderPaired

func MustOrderPaired(t TB, root, include string, first, second *regexp.Regexp, reason string)

MustOrderPaired fails t if any file contains `second` on a line that precedes the first occurrence of `first`. The classic motivating bug: `seenPackets.removeAll(...)` called before `seenPackets.contains(...)` in a BLE packet de-dup check.

func NoHardcoded10sTransportTimeout

func NoHardcoded10sTransportTimeout(t TB, root, include string)

NoHardcoded10sTransportTimeout fails if any source file contains a hard-coded 10-second timeout pattern in a BitBox transport context. Thin wrapper around quirk A2.

func NoNonAsciiInEIP712Literals

func NoNonAsciiInEIP712Literals(t TB, root, include string)

NoNonAsciiInEIP712Literals fails if any file in an EIP-712 context contains string literals with non-ASCII bytes. Thin wrapper around quirk E1.

func RunQuirk

func RunQuirk(t TB, root, include, quirkID string) int

RunQuirk applies every detect rule of the named quirk to source files under `root` matching `include` (a single glob like "*.go"). Each finding becomes a t.Errorf so the failure is attributable to the call site.

Returns the number of findings emitted; usually you discard the value and rely on the test framework's failure tracking.

Types

type Match

type Match struct {
	Path string
	Line int
	Text string
}

Match is the location of a regex hit inside a file.

type TB

type TB interface {
	Helper()
	Errorf(format string, args ...any)
	Logf(format string, args ...any)
}

TB is the minimal subset of testing.TB the guards need. Tests substitute a custom implementation to verify a guard correctly fires.

Jump to

Keyboard shortcuts

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