Documentation
¶
Overview ¶
Package modresolve resolves Go module roots for package patterns in multi-module repositories. Given relative patterns like ./deployment/..., it walks up from the pattern's base directory to find the nearest go.mod (bounded at repoRoot), rewrites patterns relative to that module, and returns the directory to use as cmd.Dir for go test or go list.
Index ¶
- func GoTestFlagsBeforeArgs(args []string) []string
- func NearestModuleRoot(dir, stopAt string) (string, error)
- func PackagePatternsFromEnd(args []string) []string
- func ResolveArgs(repoRoot string, goTestArgs []string) (moduleDir string, rewrittenArgs []string, err error)
- func ResolvePatterns(repoRoot string, patterns []string) (moduleDir string, rewritten []string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoTestFlagsBeforeArgs ¶
GoTestFlagsBeforeArgs returns the portion of argv that belongs to `go test` itself, stopping before -args (flags after -args are passed to the test binary).
func NearestModuleRoot ¶
NearestModuleRoot walks up from dir toward stopAt looking for a go.mod. Returns an error if no intermediate or stopAt go.mod is found.
func PackagePatternsFromEnd ¶
PackagePatternsFromEnd returns trailing arguments that look like package patterns. It scans backward from the end of GoTestFlagsBeforeArgs(args), skipping standard test binary flags and their values so `./pkg -run TestName` still yields `./pkg`.
func ResolveArgs ¶
func ResolveArgs(repoRoot string, goTestArgs []string) (moduleDir string, rewrittenArgs []string, err error)
ResolveArgs extracts trailing package patterns from go test arguments (see PackagePatternsFromEnd), resolves the module directory from those patterns, and rewrites all relative package-pattern arguments in the full slice. Module resolution uses only trailing patterns; rewriting applies to every relative pattern argument, not only trailing ones. Flags and non-pattern args are preserved.
func ResolvePatterns ¶
func ResolvePatterns(repoRoot string, patterns []string) (moduleDir string, rewritten []string, err error)
ResolvePatterns returns the Go module root for relative package patterns and rewrites those patterns relative to the module directory. When all patterns belong to repoRoot's module, repoRoot is returned with patterns unchanged. Returns an error when patterns span more than one module.
Types ¶
This section is empty.