diff --git a/cmd/xgo/test-explorer/config.go b/cmd/xgo/test-explorer/config.go index 8ae2e6be..b66c0284 100644 --- a/cmd/xgo/test-explorer/config.go +++ b/cmd/xgo/test-explorer/config.go @@ -27,7 +27,12 @@ type TestConfig struct { Flags []string `json:"flags"` Args []string `json:"args"` - MockRules []string `json:"mock_rules"` + MockRules []string `json:"mock_rules"` + Xgo *XgoConfig `json:"xgo,omitempty"` +} + +type XgoConfig struct { + AutoUpdate bool `json:"auto_update"` } func (c *TestConfig) CmdEnv() []string { @@ -141,10 +146,27 @@ func parseTestConfig(config string) (*TestConfig, error) { } conf.MockRules = list } + if e, ok := m["xgo"]; ok { + err := copyViaJSON(e, &conf.Xgo) + if err != nil { + return nil, fmt.Errorf("xgo: %w", err) + } + } return conf, nil } +func copyViaJSON(src interface{}, dst interface{}) error { + if src == nil { + return nil + } + data, err := json.Marshal(src) + if err != nil { + return err + } + return json.Unmarshal(data, dst) +} + func parseConfigAndMergeOptions(configFile string, opts *Options, configFileRequired bool) (*TestConfig, error) { var data []byte if configFile != "" { diff --git a/cmd/xgo/test-explorer/main.go b/cmd/xgo/test-explorer/main.go index bf9df4a3..a1eb4dfd 100644 --- a/cmd/xgo/test-explorer/main.go +++ b/cmd/xgo/test-explorer/main.go @@ -10,6 +10,7 @@ import ( "io/fs" "io/ioutil" "net/http" + "os" "path/filepath" "runtime" "sort" @@ -335,13 +336,15 @@ func handle(opts *Options, args []string) error { } return conf, nil } - + // headless mode + conf, err := getTestConfig() + if err != nil { + return err + } + if conf.Xgo != nil && conf.Xgo.AutoUpdate && os.Getenv("XGO_AUTO_UPDATE") != "never" { + autoUpdateXgo() + } if len(args) > 0 && args[0] == "test" { - // headless mode - conf, err := getTestConfig() - if err != nil { - return err - } root, err := scanTests(projectRoot, subPath, true, conf.Exclude) if err != nil { return err @@ -430,6 +433,20 @@ func handle(opts *Options, args []string) error { }) } +func autoUpdateXgo() { + // auto update + done := make(chan struct{}) + go func() { + cmd.Debug().Run("go", "install", "github.com/xhd2015/xgo/cmd/xgo@latest") + close(done) + }() + // at most wait 2 second + select { + case <-done: + case <-time.After(2 * time.Second): + } +} + func openURL(url string) { openCmd := "open" if runtime.GOOS == "windows" { diff --git a/cmd/xgo/test-explorer/trace_record.go b/cmd/xgo/test-explorer/trace_record.go index 47acb124..a87c2fb1 100644 --- a/cmd/xgo/test-explorer/trace_record.go +++ b/cmd/xgo/test-explorer/trace_record.go @@ -34,10 +34,6 @@ type CallRecord struct { Children []*CallRecord `json:"children"` } -func convertTraceFileToCallRecords() []*CallRecord { - return nil -} - type traceConverter struct { } diff --git a/cmd/xgo/version.go b/cmd/xgo/version.go index 08c60418..579389de 100644 --- a/cmd/xgo/version.go +++ b/cmd/xgo/version.go @@ -4,8 +4,8 @@ import "fmt" // auto updated const VERSION = "1.0.47" -const REVISION = "324b023bc90dfb3c23fa9781cbb8f78e2830912b+1" -const NUMBER = 303 +const REVISION = "9999158f6ad9a59b8bb21a3f2cd7bef59bec11f7+1" +const NUMBER = 304 // manually updated const CORE_VERSION = "1.0.47" diff --git a/test.config.json b/test.config.json index 4adbb4cb..33081b42 100644 --- a/test.config.json +++ b/test.config.json @@ -7,5 +7,8 @@ "comment": "override not currently supported", "path": "test/xgo_test", "go_cmd": "xgo" + }, + "xgo": { + "auto_update": false } } \ No newline at end of file