testsupport

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package testsupport holds the small helpers shared by test packages across the repo: the toolchain-presence skip (RequireTool) and the one-rule RuleSet builder (OneRuleSet).

It lives outside internal/rules on purpose: OneRuleSet must fill RuleSet.DefaultPropagators from the shipped `_default-propagators.yaml` fragment, which only internal/rules/loader can read — and loader imports rules, so the builder cannot live in rules without a cycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPropagators

func DefaultPropagators(t testing.TB) []string

DefaultPropagators returns the shipped `_default-propagators.yaml` list. A test that builds its own RuleSet must set RuleSet.DefaultPropagators from this to behave like a real scan: the defaults are loader-supplied data, so a bare RuleSet literal legitimately has none and taint dies at the first stdlib transform (fmt.Sprintf, strings.ToLower, ...).

func OneRuleSet

func OneRuleSet(t testing.TB, id, lang, cwe string, sources, sinks []string, opts ...RuleOpt) *rules.RuleSet

OneRuleSet builds a single-rule RuleSet — the shape almost every engine and converter test wants — with RuleSet.DefaultPropagators always populated (see DefaultPropagators). Sink patterns may carry the usual "#idx" suffix.

func RequireNoFallbackIntrinsic

func RequireNoFallbackIntrinsic(t testing.TB, prog *ir.Program, intrinsic, what string)

RequireNoFallbackIntrinsic asserts that no instruction in prog lowered to a frontend's fallback intrinsic ("js.unsupported", "py.unsupported", …).

A fallback marks a construct the lowering does not model, and it is SILENT: the file still converts and the language still reports coverage=ok, so a dropped construct costs findings with nothing failing. Call this over a whole tree rather than a named file list — the constructs that trip it are the ones nobody thought to name.

func RequireTool

func RequireTool(t testing.TB, name string)

RequireTool skips the test when the named executable (python3, ruby, java, rustc, ...) is not on PATH — the standard guard for converter tests whose frontend shells out to an external toolchain.

Types

type RuleOpt

type RuleOpt func(*rules.Rule)

RuleOpt adjusts the rule OneRuleSet builds.

func Message

func Message(msg string) RuleOpt

Message overrides the rule's finding message (OneRuleSet defaults to the rule id).

func Propagators

func Propagators(globs ...string) RuleOpt

Propagators sets the rule's own propagator globs (on top of the set-wide defaults OneRuleSet always carries).

func Severity

func Severity(s rules.Severity) RuleOpt

Severity overrides the rule's severity (OneRuleSet defaults to High).

func Sinks

func Sinks(sinks ...rules.Sink) RuleOpt

Sinks replaces the sink list built from OneRuleSet's bare patterns — for a rule whose sinks need a dynamic `when:` guard (e.g. `not hostFixed()`).

func Validators

func Validators(globs ...string) RuleOpt

Validators sets the rule's guard/barrier validator globs.

Jump to

Keyboard shortcuts

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