From 0f1eeb7f140d0d9bc407c9179e8b909712aa7af1 Mon Sep 17 00:00:00 2001 From: husharp Date: Tue, 6 Aug 2024 17:40:30 +0800 Subject: [PATCH] replace Signed-off-by: husharp --- tools/pd-ut/ut.go | 27 ++++++++++++++------------- tools/pd-ut/xprog.go | 4 ++-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tools/pd-ut/ut.go b/tools/pd-ut/ut.go index e0312272310a..c9e6ae2463e8 100644 --- a/tools/pd-ut/ut.go +++ b/tools/pd-ut/ut.go @@ -92,7 +92,7 @@ go tool cover --func=xxx` } var ( - modulePath = "github.com/tikv/pd" + modulePath = filepath.Join("github.com", "tikv", "pd") integrationsTestPath = filepath.Join("tests", "integrations") ) @@ -414,7 +414,7 @@ func runExistingTestCases(pkgs []string) (tasks []task, err error) { wg := &sync.WaitGroup{} tasksChannel := make(chan []task, len(pkgs)) for _, pkg := range pkgs { - _, ok := existPkgs[fmt.Sprintf("%s/%s", modulePath, pkg)] + _, ok := existPkgs[filepath.Join(modulePath, pkg)] if !ok { fmt.Println("no test case in ", pkg) continue @@ -528,7 +528,7 @@ func filterTestCases(tasks []task, arg1 string) ([]task, error) { } func listPackages() ([]string, error) { - cmd := exec.Command("go", "list", "./...") + cmd := exec.Command("go", "list", strings.Join([]string{".", "..."}, string(filepath.Separator))) cmd.Dir = workDir ss, err := cmdToLines(cmd) if err != nil { @@ -677,7 +677,7 @@ func (*numa) testCommand(pkg string, fn string) *exec.Cmd { args = append(args, "-test.v") exe := strings.Join([]string{".", testFileName(pkg)}, string(filepath.Separator)) if coverProfile != "" { - fileName := strings.ReplaceAll(pkg, "/", "_") + "." + fn + fileName := strings.ReplaceAll(pkg, string(filepath.Separator), "_") + "." + fn tmpFile := filepath.Join(coverFileTempDir, fileName) args = append(args, "-test.coverprofile", tmpFile) } @@ -720,12 +720,12 @@ func generateBuildCache() error { fmt.Println("generate build cache") // cd cmd/pd-server && go test -tags=tso_function_test,deadlock -exec-=true -vet=off -toolexec=go-compile-without-link cmd := exec.Command("go", "test", "-exec=true", "-vet", "off", "--tags=tso_function_test,deadlock") - goCompileWithoutLink := fmt.Sprintf("-toolexec=%s/tools/pd-ut/go-compile-without-link.sh", workDir) - cmd.Dir = fmt.Sprintf("%s/cmd/pd-server", workDir) + goCompileWithoutLink := fmt.Sprintf("-toolexec=%s", filepath.Join(workDir, "tools", "pd-ut", "go-compile-without-link.sh")) + cmd.Dir = filepath.Join(workDir, "cmd", "pd-server") if strings.Contains(workDir, integrationsTestPath) { - cmd.Dir = fmt.Sprintf("%s/cmd/pd-server", workDir[:strings.LastIndex(workDir, integrationsTestPath)]) - goCompileWithoutLink = fmt.Sprintf("-toolexec=%s/tools/pd-ut/go-compile-without-link.sh", - workDir[:strings.LastIndex(workDir, integrationsTestPath)]) + cmd.Dir = filepath.Join(workDir[:strings.LastIndex(workDir, integrationsTestPath)], "cmd", "pd-server") + goCompileWithoutLink = fmt.Sprintf("-toolexec=%s", filepath.Join(workDir[:strings.LastIndex(workDir, integrationsTestPath)], + "tools", "pd-ut", "go-compile-without-link.sh")) } cmd.Args = append(cmd.Args, goCompileWithoutLink) cmd.Stdout = os.Stdout @@ -759,11 +759,11 @@ func buildTestBinaryMulti(pkgs []string) ([]byte, error) { p := strconv.Itoa(parallel * 2) cmd := exec.Command("go", "test", "-p", p, "--exec", xprogPath, "-vet", "off", "--tags=tso_function_test,deadlock") if coverProfile != "" { - coverpkg := "./..." + coverPkg := strings.Join([]string{".", "..."}, string(filepath.Separator)) if strings.Contains(workDir, integrationsTestPath) { - coverpkg = "../../..." + coverPkg = filepath.Join("..", "..", "...") } - cmd.Args = append(cmd.Args, "-cover", fmt.Sprintf("-coverpkg=%s", coverpkg)) + cmd.Args = append(cmd.Args, "-cover", fmt.Sprintf("-coverpkg=%s", coverPkg)) } cmd.Args = append(cmd.Args, packages...) if race { @@ -794,7 +794,8 @@ func buildTestBinary(pkg string) error { //nolint:gosec cmd := exec.Command("go", "test", "-c", "-vet", "off", "--tags=tso_function_test,deadlock", "-o", testFileName(pkg), "-v") if coverProfile != "" { - cmd.Args = append(cmd.Args, "-cover", "-coverpkg=./...") + coverPkg := strings.Join([]string{".", "..."}, string(filepath.Separator)) + cmd.Args = append(cmd.Args, "-cover", fmt.Sprintf("-coverpkg=%s", coverPkg)) } if race { cmd.Args = append(cmd.Args, "-race") diff --git a/tools/pd-ut/xprog.go b/tools/pd-ut/xprog.go index cf3e9b295e29..23db83278815 100644 --- a/tools/pd-ut/xprog.go +++ b/tools/pd-ut/xprog.go @@ -34,7 +34,7 @@ func main() { // Extract the current work directory cwd := os.Args[0] - cwd = cwd[:len(cwd)-len("bin/xprog")] + cwd = cwd[:len(cwd)-len(filepath.Join("bin", "xprog"))] testBinaryPath := os.Args[1] dir, _ := filepath.Split(testBinaryPath) @@ -42,7 +42,7 @@ func main() { // Extract the package info from /tmp/go-build2662369829/b1382/importcfg.link pkg := getPackageInfo(dir) - const prefix = "github.com/tikv/pd/" + const prefix = filepath.Join("github.com", "tikv", "pd") if !strings.HasPrefix(pkg, prefix) { os.Exit(-3) }