Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cli/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,19 @@ func discoverAvailableProfiles(tag, benchmarkName string) ([]string, error) {
}

func runTUI(_ *cobra.Command, _ []string) error {
benchNames, err := benchmark.DiscoverBenchmarks()
// Get current working directory for scope-aware benchmark discovery
currentDir, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to get current working directory: %w", err)
}

benchNames, err := benchmark.DiscoverBenchmarks(currentDir)
if err != nil {
return fmt.Errorf("failed to discover benchmarks: %w", err)
}

if len(benchNames) == 0 {
return errors.New("no benchmarks found in this module (look for func BenchmarkXxx(b *testing.B) in *_test.go)")
return errors.New("no benchmarks found in this directory or its subdirectories (look for func BenchmarkXxx(b *testing.B) in *_test.go)")
}

var selectedBenches []string
Expand Down
22 changes: 17 additions & 5 deletions engine/benchmark/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,23 @@ func RunBenchmarks(benchmarks, profiles []string, tag string, count int) error {
// A benchmark is identified by functions matching:
//
// func BenchmarkXxx(b *testing.B) { ... }
func DiscoverBenchmarks() ([]string, error) {
root, err := internal.FindGoModuleRoot()
if err != nil {
return nil, fmt.Errorf("failed to locate module root: %w", err)
//
// If scope is provided, only searches within that directory and its subdirectories.
// If scope is empty, searches the entire module from the root.
func DiscoverBenchmarks(scope string) ([]string, error) {
var searchRoot string
var err error

if scope != "" {
// Use the provided scope directory
searchRoot = scope
} else {
// Fall back to searching from module root
searchRoot, err = internal.FindGoModuleRoot()
if err != nil {
return nil, fmt.Errorf("failed to locate module root: %w", err)
}
}

return scanForBenchmarks(root)
return scanForBenchmarks(searchRoot)
}
Loading