From 1b7e9ec34f791f062649738a87098db49eee7a46 Mon Sep 17 00:00:00 2001 From: xhd2015 Date: Tue, 28 May 2024 17:35:21 +0800 Subject: [PATCH] fix test -args processing --- cmd/xgo/main.go | 6 +++++- cmd/xgo/option.go | 11 ++++++++++- cmd/xgo/runtime_gen/core/version.go | 4 ++-- cmd/xgo/version.go | 4 ++-- runtime/core/version.go | 4 ++-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/cmd/xgo/main.go b/cmd/xgo/main.go index 034b5590..d14b4a72 100644 --- a/cmd/xgo/main.go +++ b/cmd/xgo/main.go @@ -113,11 +113,12 @@ func handleBuild(cmd string, args []string) error { cmdBuild := cmd == "build" cmdTest := cmd == "test" cmdExec := cmd == "exec" - opts, err := parseOptions(args) + opts, err := parseOptions(cmd, args) if err != nil { return err } remainArgs := opts.remainArgs + testArgs := opts.testArgs flagA := opts.flagA projectDir := opts.projectDir output := opts.output @@ -442,6 +443,9 @@ func handleBuild(cmd string, args []string) error { } } buildCmdArgs = append(buildCmdArgs, remainArgs...) + if cmdTest && len(testArgs) > 0 { + buildCmdArgs = append(buildCmdArgs, testArgs...) + } logDebug("command: %s %v", instrumentGo, buildCmdArgs) execCmd = exec.Command(instrumentGo, buildCmdArgs...) } else { diff --git a/cmd/xgo/option.go b/cmd/xgo/option.go index b1eceb92..2f084143 100644 --- a/cmd/xgo/option.go +++ b/cmd/xgo/option.go @@ -61,9 +61,11 @@ type options struct { stackTrace string remainArgs []string + + testArgs []string } -func parseOptions(args []string) (*options, error) { +func parseOptions(cmd string, args []string) (*options, error) { var flagA bool var flagV bool var flagX bool @@ -103,6 +105,7 @@ func parseOptions(args []string) (*options, error) { var trapStdlib bool var remainArgs []string + var testArgs []string nArg := len(args) type FlagValue struct { @@ -191,6 +194,11 @@ func parseOptions(args []string) (*options, error) { remainArgs = append(remainArgs, arg) continue } + if cmd == "test" && arg == "-args" { + // pass everything after -args to test binary + testArgs = append(testArgs, args[i:]...) + break + } if arg == "--" { remainArgs = append(remainArgs, args[i+1:]...) break @@ -352,6 +360,7 @@ func parseOptions(args []string) (*options, error) { trapStdlib: trapStdlib, remainArgs: remainArgs, + testArgs: testArgs, }, nil } diff --git a/cmd/xgo/runtime_gen/core/version.go b/cmd/xgo/runtime_gen/core/version.go index 4f249e53..d16a31f1 100755 --- a/cmd/xgo/runtime_gen/core/version.go +++ b/cmd/xgo/runtime_gen/core/version.go @@ -7,8 +7,8 @@ import ( ) const VERSION = "1.0.37" -const REVISION = "62c6c037c1f57c371e227dd1bb8b8e141367f1c6+1" -const NUMBER = 239 +const REVISION = "6f9a355d360e70a797c4ca0903fb5a6bdd1aa5db+1" +const NUMBER = 240 // these fields will be filled by compiler const XGO_VERSION = "" diff --git a/cmd/xgo/version.go b/cmd/xgo/version.go index ba561652..f27f3186 100644 --- a/cmd/xgo/version.go +++ b/cmd/xgo/version.go @@ -3,8 +3,8 @@ package main import "fmt" const VERSION = "1.0.37" -const REVISION = "62c6c037c1f57c371e227dd1bb8b8e141367f1c6+1" -const NUMBER = 239 +const REVISION = "6f9a355d360e70a797c4ca0903fb5a6bdd1aa5db+1" +const NUMBER = 240 func getRevision() string { revSuffix := "" diff --git a/runtime/core/version.go b/runtime/core/version.go index 4f249e53..d16a31f1 100644 --- a/runtime/core/version.go +++ b/runtime/core/version.go @@ -7,8 +7,8 @@ import ( ) const VERSION = "1.0.37" -const REVISION = "62c6c037c1f57c371e227dd1bb8b8e141367f1c6+1" -const NUMBER = 239 +const REVISION = "6f9a355d360e70a797c4ca0903fb5a6bdd1aa5db+1" +const NUMBER = 240 // these fields will be filled by compiler const XGO_VERSION = ""