Help us shape the future of Go! Take the 2026 Go Developer Survey

harness

package
v0.4.0-flanksource.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package harness verifies the port against the Python reference.

testdata/expected holds one JSON file per statement: the SQL, its dialect, and the tree the reference produced (serde.dump format). The port parses the same SQL, dumps its own tree the same way, and the two are diffed. A mismatch is a failing test; the reference is the oracle.

Coverage is reported as a number per dialect -- what fraction of the reference corpus the port reproduces identically -- and written to testdata/coverage.json so the README can show it and CI can refuse a regression. A statement the port cannot parse counts against coverage; it never counts as a silent divergence.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(want, got []map[string]any) string

Diff returns a human-readable description of the first disagreement between two normalised dumps, or "" if they match.

func Load

func Load(dir string) (*Index, []Expectation, error)

Load reads every expectation under dir.

func Normalise

func Normalise(tree []map[string]any) []map[string]any

Normalise strips what the port does not reproduce and the comparison must not care about: source positions ("m") and comments ("o"). Everything else -- class, parent index, arg key, list flag, leaf value -- is structure, and must match exactly.

Types

type Coverage

type Coverage struct {
	Reference string                     `json:"reference"`
	Total     int                        `json:"total"`
	Matched   int                        `json:"matched"`
	ByDialect map[string]DialectCoverage `json:"by_dialect"`
}

Coverage is the per-dialect tally a run produces.

func (*Coverage) Dialects

func (c *Coverage) Dialects() []string

Dialects lists the tally's dialect names, sorted, "neutral" for "".

func (*Coverage) Write

func (c *Coverage) Write(path string) error

Write persists the tally, with dialects in a stable order.

type DialectCoverage

type DialectCoverage struct {
	Total      int `json:"total"`
	Matched    int `json:"matched"`
	Unparsed   int `json:"unparsed"`   // the port refused or errored
	Mismatched int `json:"mismatched"` // parsed, but a different tree
}

DialectCoverage counts one dialect's outcomes.

func (DialectCoverage) Percent

func (c DialectCoverage) Percent() float64

Percent is matched/total, to one decimal.

type Expectation

type Expectation struct {
	Key     string `json:"-"`
	Dialect string `json:"dialect"`
	SQL     string `json:"sql"`
	// Rendered is what the reference writes this statement back out as. The
	// guard rewrites a tree and hands SQL to the engine, so the port needs a
	// generator, and it is held to this string rather than to "something that
	// parses".
	Rendered string           `json:"rendered"`
	Tokens   []RefToken       `json:"tokens"`
	Tree     []map[string]any `json:"tree"`
}

Expectation is one reference statement, its token stream and its tree.

type Index

type Index struct {
	Reference  string `json:"reference"`
	Count      int    `json:"count"`
	Statements []struct {
		Key     string `json:"key"`
		Dialect string `json:"dialect"`
		SQL     string `json:"sql"`
	} `json:"statements"`
}

Index lists every expectation and the reference commit they came from.

type RefToken

type RefToken struct {
	Type     string   `json:"t"`
	Text     string   `json:"x"`
	Line     int      `json:"l"`
	Col      int      `json:"c"`
	Start    int      `json:"s"`
	End      int      `json:"e"`
	Comments []string `json:"o,omitempty"`
}

RefToken is one token as the reference produced it. The short field names are the oracle's, kept short because there are a few hundred thousand of them.

func (RefToken) String

func (t RefToken) String() string

Jump to

Keyboard shortcuts

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