Documentation
¶
Overview ¶
Package testutil provides shared test fixtures and harness helpers:
- Materialize copies testdata/fixture-repo into a temp dir and turns it into a git repository with tracked, untracked, ignored, vendored and oversized files.
- Synth generates deterministic synthetic repositories for benchmarks.
- CanonicalDump renders graph.db as sorted text keyed by stable identities (path, qname, kind) instead of row ids, so an incremental build can be compared with a from-scratch build.
Index ¶
- Constants
- func CanonicalDump(db *sql.DB) string
- func CanonicalDumpE(db *sql.DB) (string, error)
- func ExpectedEdgesPath() string
- func FixtureDir() string
- func FixturePaths() ([]string, error)
- func Git(t testing.TB, dir string, args ...string) string
- func IgnoredPaths() []string
- func Materialize(t testing.TB) string
- func MaterializeSynth(t testing.TB, seed int64, files, locPerFile int, langs []model.Lang) string
- func MaterializeTo(root string) error
- func UntrackedPaths() []string
- func VendorPaths() []string
- type ExpectedEdge
- type SynthFile
- type SynthRepo
Constants ¶
const ( // BigFilePath is a >1 MiB source file created by Materialize and // committed in the second commit (so it is tracked but oversized). BigFilePath = "python/shop/catalog_big.py" // GeneratedPath carries a "Code generated ... DO NOT EDIT." header. GeneratedPath = "go/internal/gen/status_string.go" // MinifiedPath is a minified JavaScript bundle. The default *.min.* // config exclude drops it before the content filters run. MinifiedPath = "js/public/widgets.min.js" )
Well-known paths inside a materialized fixture (repo-relative, slash form).
Variables ¶
This section is empty.
Functions ¶
func CanonicalDump ¶
CanonicalDump renders the graph stored in db as sorted text that does not depend on row ids or stat data, so two databases describing the same graph produce identical dumps. It panics on query errors; use CanonicalDumpE to handle them.
func CanonicalDumpE ¶
CanonicalDumpE is CanonicalDump returning errors instead of panicking. Missing tables are reported as "(absent)" sections rather than errors.
func ExpectedEdgesPath ¶
func ExpectedEdgesPath() string
ExpectedEdgesPath is the location of the fixture's edge expectations.
func FixtureDir ¶
func FixtureDir() string
FixtureDir returns the absolute path of testdata/fixture-repo.
func FixturePaths ¶
FixturePaths returns the sorted repo-relative paths of the committed fixture files, i.e. what Materialize puts in the first commit.
func Git ¶
Git runs git in dir with an isolated environment (no global or system config) and returns stdout with trailing newlines trimmed. It fails the test on error.
func IgnoredPaths ¶
func IgnoredPaths() []string
IgnoredPaths returns the sorted files ignored via .gitignore rules.
func Materialize ¶
Materialize builds a git repository from the fixture in t.TempDir() and returns its root. The resulting layout is:
- commit 1: every file of testdata/fixture-repo
- commit 2: VendorPaths() and BigFilePath
- untracked (not ignored): UntrackedPaths()
- ignored: IgnoredPaths()
Commits use a fixed identity and date, so HEAD is identical across runs.
func MaterializeSynth ¶
MaterializeSynth writes Synth(seed, files, locPerFile, langs) into t.TempDir(), commits everything to a fresh git repository and returns its root.
func MaterializeTo ¶
MaterializeTo builds the same repository as Materialize in root, which must be empty or missing (benchmarks and manual end-to-end runs).
func UntrackedPaths ¶
func UntrackedPaths() []string
UntrackedPaths returns the sorted untracked, non-ignored files.
func VendorPaths ¶
func VendorPaths() []string
VendorPaths returns the sorted vendored files tracked by Materialize.
Types ¶
type ExpectedEdge ¶
type ExpectedEdge struct {
Section string // "[lang]" header the line belongs to
Line int // 1-based line number in the file
Optional bool // "?" prefix: desirable, logged when missing
Negative bool // "!" prefix: must not exist
Kind model.EdgeKind
Src, Dst string
MinConf int
}
ExpectedEdge is one line of testdata/fixture-repo/expected_edges.txt:
[prefix]<kind> <src> -> <dst> [conf>=N]
Src and Dst are "path::Chain" (container chain joined with "."), a bare path (imports/includes) or "external:<qual.name>".
func LoadExpectedEdges ¶
func LoadExpectedEdges(section string) ([]ExpectedEdge, error)
LoadExpectedEdges parses the expectations of one section, or of every section when section is "".
func ParseExpectedEdge ¶
func ParseExpectedEdge(line string) (ExpectedEdge, error)
ParseExpectedEdge parses one expectation line (without section or line number).
func (ExpectedEdge) External ¶
func (e ExpectedEdge) External() (name string, ok bool)
External reports whether Dst names a target outside the indexed code and returns its simple name (the part after the last "." or ":").
func (ExpectedEdge) String ¶
func (e ExpectedEdge) String() string
type SynthRepo ¶
type SynthRepo struct {
// contains filtered or unexported fields
}
SynthRepo describes a deterministic synthetic repository. Content is generated on demand: file contents depend only on (seed, parameters, language, file index), never on generation order.
func Synth ¶
Synth describes a synthetic repository of `files` source files spread round-robin over langs, each about locPerFile lines long (never shorter; longer only when locPerFile is below the size of one function plus header). Every function calls a function in another file of its package, one in a lower-numbered package (or its own package for package 0) and one in its own file, using each language's real import mechanism.
Manifests and package-init files (go.mod, __init__.py, mod.rs, C headers, ...) are emitted in addition to the source files. Synth panics on invalid arguments, since it is a test helper.
func (*SynthRepo) Files ¶
Files returns sources plus support files (manifests, headers, package init files), sorted by path.
func (*SynthRepo) SourceCount ¶
SourceCount returns the number of generated source files.