modresolve

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoTestFlagsBeforeArgs

func GoTestFlagsBeforeArgs(args []string) []string

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

func NearestModuleRoot(dir, stopAt string) (string, error)

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

func PackagePatternsFromEnd(args []string) []string

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.

Jump to

Keyboard shortcuts

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