diff options
author | Joe Chen <jc@unknwon.io> | 2023-02-19 18:10:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-19 18:10:34 +0800 |
commit | 3e3d6eda1247eae8225af2de10e40c0f47d59626 (patch) | |
tree | 2c0e2a0e12fb7e85996eadbb5ccff56c9330bdde /internal | |
parent | 91100597978b0902b7a6cd81723cab139341f4ef (diff) |
chore: update Go versions in CI (#7346)
Diffstat (limited to 'internal')
-rw-r--r-- | internal/testutil/exec.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/internal/testutil/exec.go b/internal/testutil/exec.go index 45f08315..3600537d 100644 --- a/internal/testutil/exec.go +++ b/internal/testutil/exec.go @@ -20,24 +20,27 @@ import ( // 2. Call fmt.Fprintln(os.Stdout, ...) to print results for the main test to collect. func Exec(helper string, envs ...string) (string, error) { cmd := exec.Command(os.Args[0], "-test.run="+helper, "--") - cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"} + cmd.Env = []string{ + "GO_WANT_HELPER_PROCESS=1", + "GOCOVERDIR=" + os.TempDir(), + } cmd.Env = append(cmd.Env, envs...) out, err := cmd.CombinedOutput() str := string(out) - if err != nil { - return "", fmt.Errorf("%v - %s", err, str) - } + // The error is quite confusing even when tests passed, so let's check whether + // it is passed first. if strings.Contains(str, "no tests to run") { return "", errors.New("no tests to run") - } else if !strings.Contains(str, "PASS") { - return "", errors.New(str) + } else if i := strings.Index(str, "PASS"); i >= 0 { + // Collect helper result + return strings.TrimSpace(str[:i]), nil } - // Collect helper result - result := str[:strings.Index(str, "PASS")] - result = strings.TrimSpace(result) - return result, nil + if err != nil { + return "", fmt.Errorf("%v - %s", err, str) + } + return "", errors.New(str) } // WantHelperProcess returns true if current process is in helper mode. |