eval

package
v1.45.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides static coverage estimation using call graph and CFG analysis.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides static coverage estimation using call graph and CFG analysis.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Package eval provides test recognition, outcome matching, and confidence scoring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzePackageCoverage

func AnalyzePackageCoverage(allPkgs []*packages.Package) map[string]*PackageCoverageResult

AnalyzePackageCoverage performs block-level coverage analysis using type-resolved call graph extraction, determining which source functions are called by each test and marking their blocks as covered via go/types resolution.

func AssertedPositionLabel added in v1.3.180

func AssertedPositionLabel(pos int) string

AssertedPositionLabel returns a human-readable label for an asserted return position.

func BindWantErrFromRecognizedCases added in v1.3.180

func BindWantErrFromRecognizedCases(cases []model.RecognizedCaseValue) (fieldName string, outcomes map[int]bool)

BindWantErrFromRecognizedCases scans recognized test cases for well-known error-expectation field names and returns per-row error-outcome expectations.

This is the bridge version of bindWantErrToOutcomes that works with the model.RecognizedCaseValue type used by scenario.ComputeCoverage.

Returns a map of row index -> bool (true = expects error) and the field name that was detected, or ("", nil) when no matching field is found.

func BindWantErrToOutcomes added in v1.3.180

func BindWantErrToOutcomes(tableInfo *TableInfoValue) map[int]bool

BindWantErrToOutcomes scans the table-driven test's struct fields for well-known error-expectation field names (wantErr, wantError, expectErr, expectsError) and binds each row's value to the SUT's error-return outcome partition.

Returns a map of row index -> bool (true = expects error, false = expects success). Returns nil when tableInfo is nil or has no matching field — callers distinguish "absent" from "present-but-empty" via the nil sentinel.

Exported because future fact-aware analysers consume this directly; the in-package tests pin every branch (see branches_internal_test.go).

func ClassifyTest

func ClassifyTest(testFunc *ast.FuncDecl) model.TestTierValue

ClassifyTest determines the support tier of a test function, returning Tier A for strict table-driven tests, Tier B for simple patterns, and SupportNone for unrecognizable patterns.

func ComputeConfidence

func ComputeConfidence(breakdown ComputeLeveller, reasons []string) model.ConfidenceValue

ComputeConfidence aggregates a ConfidenceBreakdownValue into a final ConfidenceValue. The overall level is the minimum of all dimensions. If any dimension is SupportNone, the result is SupportNone.

func ComputeGapScenarios

func ComputeGapScenarios(decisions []model.DecisionValue, match *OutcomeMatchValue) []model.MissingScenarioValue

ComputeGapScenarios identifies unexercised decision outcomes and builds missing scenario descriptions with parameter constraints. Only produces results for decisions with sufficient confidence.

func EvaluateFieldValue

func EvaluateFieldValue(expr ast.Expr) string

EvaluateFieldValue extracts a string value from a field expression.

Returned tokens are used by the matcher to detect *distinction* between table rows (two different tokens → potentially two different outcomes). They are NOT a proof of branch coverage on their own: callers MUST still require an explicit condition↔field match before crediting a decision outcome. See compositeStructuralFingerprint for the composite case.

func HasErrorOutcomeCoverage added in v1.3.180

func HasErrorOutcomeCoverage(cases []model.RecognizedCaseValue) bool

HasErrorOutcomeCoverage checks whether the test cases provide both error-expected and no-error-expected rows for the wantErr field. Returns true when both outcomes are represented, meaning the test covers both the error-return path and the success-return path.

func HighConfidence

func HighConfidence(reason string) model.ConfidenceValue

HighConfidence creates a high-confidence result with the given reason.

func NoneConfidence

func NoneConfidence(reason string) model.ConfidenceValue

NoneConfidence creates a none-confidence result with the given reason.

func WantErrOutcomesFor added in v1.3.180

func WantErrOutcomesFor(outcomes map[int]bool) []string

WantErrOutcomesFor returns display labels for the error-outcome partitions discovered by bindWantErrToOutcomes. It filters to rows that actually assert specific outcomes (true or false) and returns the distinct labels present.

Types

type AssertedReturnSet added in v1.3.180

type AssertedReturnSet map[int]bool

AssertedReturnSet records which return positions are verified by assertions in a test body. Position 0 is the first non-error return; position -1 is the error return (matching the receiverParamIdx sentinel).

A position present in the map means at least one assertion covers it.

func AssertionOutcomesFromBody added in v1.3.180

func AssertionOutcomesFromBody(body *ast.BlockStmt) AssertedReturnSet

AssertionOutcomesFromBody inspects a function body AST for assertion calls and returns the set of covered return positions. This is the exported bridge that ComputeCoverage can call when an AST body is available.

Position receiverParamIdx (-1) = error return. Position 0 = first value return.

type BoundaryValue

type BoundaryValue struct {
	// Label describes this value ("zero", "max", "nil", "empty").
	Label string
	// Value is the Go source code representation.
	Value string
	// Kind classifies the value ("boundary", "typical", "edge").
	Kind string
}

BoundaryValue represents a frontier test value for a Go type. It is used for boundary value operations.

func BoundaryValues

func BoundaryValues(t types.Type) []BoundaryValue

BoundaryValues returns frontier test values for a Go type. These are the values most likely to trigger different code paths.

type BranchDiagnosticValue added in v0.135.2

type BranchDiagnosticValue struct {
	// FuncName is the function key (e.g., "NewCoverageCheckerService")
	FuncName string
	// TotalBranches is the number of decision points in the function
	TotalBranches int
	// CoveredBranches is the number of branches proven covered by tests
	CoveredBranches int
	// MissingBranches is the number of branches proven NOT covered
	MissingBranches int
	// UnknownBranches is the number of branches that cannot be verified statically
	UnknownBranches int
	// MissingScenarios describes each uncovered or unverifiable branch
	MissingScenarios []string
}

BranchDiagnosticValue describes branch coverage analysis for a function. It counts total, covered, missing, and unknown branches with missing scenario descriptions.

Fields:

  • FuncName: function key (e.g., "NewCoverageCheckerService")
  • TotalBranches: number of decision points
  • CoveredBranches: branches proven covered by tests
  • MissingBranches: branches proven NOT covered
  • UnknownBranches: branches that cannot be verified statically
  • MissingScenarios: descriptions of each uncovered branch

func AnalyzeBranchCoverage

func AnalyzeBranchCoverage(fset *token.FileSet, fn *ast.FuncDecl, funcKey string, callArgs []CallArgValue) BranchDiagnosticValue

AnalyzeBranchCoverage examines a function's decision points (if/switch) and determines which branches are covered by the known test arguments. Returns a diagnostic with missing test scenarios.

type CallArgValue added in v0.135.2

type CallArgValue struct {
	// Args maps parameter index to the resolved constant value (nil if not a literal).
	Args map[int]constant.Value
	// NonNilArgs tracks parameter indices known to be non-nil but whose value is not a constant.
	// Used for nil-check resolution: if NonNilArgs[i] is true, param i is definitely non-nil.
	NonNilArgs map[int]bool
}

CallArgValue holds literal argument values for a specific function call site. It maps parameter indices to resolved constant values for branch resolution.

Fields:

  • Args: parameter index to resolved constant value (nil if not a constant)
  • NonNilArgs: parameter indices known to be non-nil but whose value is not a constant

func ResolveCallLiteralArgs

func ResolveCallLiteralArgs(call *ast.CallExpr, info *types.Info) CallArgValue

ResolveCallLiteralArgs extracts constant values from call arguments. Only resolves arguments that are compile-time constants or nil.

func ResolveTableDrivenCallArgs

func ResolveTableDrivenCallArgs(call *ast.CallExpr, tables []TableInfoValue) []CallArgValue

ResolveTableDrivenCallArgs resolves call arguments that reference table fields. Handles both direct calls F(tt.x, tt.y) and method calls tt.obj.Method(tt.x). For method calls, the receiver is tracked as parameter index receiverParamIdx (-1).

type ComputeLeveller

type ComputeLeveller interface {
	ComputeLevel() model.SupportLevel
}

ComputeLeveller is the minimal interface for computing the aggregate level.

type FileCoverageResult

type FileCoverageResult struct {
	// Name is the base filename
	Name string
	// TotalStmts is total in this file
	TotalStmts int
	// CoveredStmts is covered in this file
	CoveredStmts int
	// UncoveredFuncs lists functions not fully covered
	UncoveredFuncs []string
	// BranchDiagnostics lists missing test scenarios per function
	BranchDiagnostics []BranchDiagnosticValue
}

FileCoverageResult holds per-file coverage analysis results. It tracks statement counts and lists uncovered functions with branch diagnostics.

Fields:

  • Name: base filename
  • TotalStmts: total statements in this file
  • CoveredStmts: covered statements in this file
  • UncoveredFuncs: functions not fully covered
  • BranchDiagnostics: missing test scenarios per function

type FuncBlocksEntity added in v0.135.2

type FuncBlocksEntity struct {
	// Key is "ReceiverType.FuncName" or "FuncName"
	Key string
	// Blocks are the coverable blocks from pkg/cover
	Blocks []cover.BlockValue
	// TotalStmts is sum of NumStmt across all blocks
	TotalStmts int
}

FuncBlocksEntity maps a function identifier to its coverable blocks. It associates a function key with the blocks discovered by the cover package.

Fields:

  • Key: "ReceiverType.FuncName" or "FuncName"
  • Blocks: coverable blocks from pkg/cover
  • TotalStmts: sum of NumStmt across all blocks

type MatchedOutcomeValue added in v0.135.2

type MatchedOutcomeValue struct {
	// DecisionIdx is the index of the matched decision.
	DecisionIdx int
	// OutcomeIdx is the index of the matched outcome within the decision.
	OutcomeIdx int
	// CaseName is the test case that covers this outcome.
	CaseName string
	// ConfidenceValue is the match confidence.
	ConfidenceValue model.SupportLevel
}

MatchedOutcomeValue records a successful match between a test case and a decision outcome. It links the decision and outcome indices to the test case that covers them.

Fields:

  • DecisionIdx: index of the matched decision
  • OutcomeIdx: index of the matched outcome within the decision
  • CaseName: test case that covers this outcome
  • ConfidenceValue: match confidence level

type OutcomeMatchValue added in v0.135.2

type OutcomeMatchValue struct {
	// Matched lists all successfully matched outcomes.
	Matched []MatchedOutcomeValue
	// Unmatched lists decisions with missing coverage.
	Unmatched []UnmatchedDecisionValue
	// TotalOutcomes is the total outcome count.
	TotalOutcomes int
	// MatchedCount is the number of matched outcomes.
	MatchedCount int
	// ConfidenceValue is the overall match confidence.
	ConfidenceValue model.ConfidenceValue
}

OutcomeMatchValue is the result of matching test cases against function decisions. It aggregates matched and unmatched outcomes with overall confidence.

Fields:

  • Matched: successfully matched outcomes
  • Unmatched: decisions with missing coverage
  • TotalOutcomes: total outcome count
  • MatchedCount: number of matched outcomes
  • ConfidenceValue: overall match confidence

func MatchOutcomes

func MatchOutcomes(decisions []model.DecisionValue, tier model.TestTierValue) *OutcomeMatchValue

MatchOutcomes attempts to map test cases to decision outcomes. Only produces results when confidence >= SupportPartial. Returns nil when the test tier has SupportNone.

type PackageCoverageResult

type PackageCoverageResult struct {
	// PkgPath is the package import path
	PkgPath string
	// TotalStmts is the total coverable statements
	TotalStmts int
	// CoveredStmts is the number of statements covered by tests
	CoveredStmts int
	// PerFile maps filename to file-level stats
	PerFile map[string]*FileCoverageResult
}

PackageCoverageResult holds the coverage analysis for a source package. It aggregates per-file results and total statement counts.

Fields:

  • PkgPath: package import path
  • TotalStmts: total coverable statements
  • CoveredStmts: number of statements covered by tests
  • PerFile: filename to file-level stats mapping

type PathChoiceValue added in v0.135.2

type PathChoiceValue struct {
	// DecisionIdx is the index of the decision.
	DecisionIdx int
	// OutcomeIdx is the index of the chosen outcome.
	OutcomeIdx int
	// OutcomeLabel is the label of the chosen outcome.
	OutcomeLabel string
}

PathChoiceValue records which outcome was taken at a decision point during path enumeration. It links a decision index to the chosen outcome for a specific execution path.

Fields:

  • DecisionIdx: index of the decision
  • OutcomeIdx: index of the chosen outcome
  • OutcomeLabel: label of the chosen outcome

type PathEntity added in v0.135.2

type PathEntity struct {
	// ID is a sequential path identifier.
	ID int
	// Choices lists the branch choices taken on this path.
	Choices []PathChoiceValue
	// Statements is the total statements on this path.
	Statements int
}

PathEntity represents a single execution path through a function. It is used for path operations.

func EnumeratePaths

func EnumeratePaths(decisions []model.DecisionValue) (paths []PathEntity, confidence model.ConfidenceValue)

EnumeratePaths lists all execution paths through a function's decisions. Only works for small functions (≤ maxPathDecisions decisions, no loops with nested decisions). Returns nil with SupportNone confidence when the function is too complex.

type SubtestBindingValue added in v1.3.180

type SubtestBindingValue struct {
	// RowIdx is the zero-based index of the table row.
	RowIdx int
	// CallArgs holds the resolved literal and non-nil argument values for this row.
	CallArgs CallArgValue
}

SubtestBindingValue links a table-row index to the argument values used when the SUT is called inside a t.Run closure.

Fields:

  • RowIdx: zero-based index into the TableInfoValue.Cases slice
  • CallArgs: resolved call-argument info for the SUT call in that subtest

func WalkSubtests added in v1.3.180

func WalkSubtests(forStmt *ast.RangeStmt, tableInfo *TableInfoValue) []SubtestBindingValue

WalkSubtests walks the body of a for-range loop that calls t.Run with table-driven test cases. It returns a list of (rowIndex, sutCallArgs) pairs by linking inner-body references to the row's struct fields.

Falls back gracefully when the loop body is not a t.Run pattern, returning an empty (non-nil) slice.

Exported because future fact-aware analysers consume this directly; the in-package tests pin every branch (see branches_internal_test.go).

type TableCaseValue added in v0.135.2

type TableCaseValue struct {
	// Fields maps field name to constant value (nil value = nil literal).
	Fields map[string]constant.Value
	// NonNilFields tracks fields known to be non-nil but whose exact value is not a constant.
	// Examples: &Config{...}, []int{1,2,3}, map[string]int{}.
	NonNilFields map[string]bool
}

TableCaseValue holds constant field values from a single table test case. It captures both constant values and non-nil knowledge for branch resolution.

Fields:

  • Fields: field name to constant value mapping (nil value = nil literal)
  • NonNilFields: fields known to be non-nil but whose exact value is not a constant

type TableInfoValue added in v0.135.2

type TableInfoValue struct {
	VarName string
	Cases   []TableCaseValue
}

TableInfoValue holds the table variable name and its cases for table-driven test analysis. It links a variable declaration to the extracted test cases.

Fields:

  • VarName: name of the table variable in the test function
  • Cases: extracted test cases with constant field values

func ExtractTableDrivenCases

func ExtractTableDrivenCases(body *ast.BlockStmt) []TableInfoValue

ExtractTableDrivenCases finds table-driven test patterns in a function body. Detects: varName := []struct{...}{{...}, {...}} or []Type{{...}, {...}}

type UnmatchedDecisionValue added in v0.135.2

type UnmatchedDecisionValue struct {
	// DecisionValue is the unmatched decision.
	DecisionValue model.DecisionValue
	// DecisionIdx is the index in the function's decision list.
	DecisionIdx int
	// MissingOutcomes lists the labels of unmatched outcomes.
	MissingOutcomes []string
}

UnmatchedDecisionValue records a decision with outcomes not covered by any test. It identifies which outcomes are missing for a specific decision point.

Fields:

  • DecisionValue: the unmatched decision from the IR
  • DecisionIdx: index in the function's decision list
  • MissingOutcomes: labels of unmatched outcomes

Jump to

Keyboard shortcuts

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