Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit ce5ef7c

Browse files
committed
making it Windows compatible
1 parent 85964b7 commit ce5ef7c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

mockgen/parse.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ func parsePackageImport(srcDir string) (string, error) {
562562
for {
563563
dat, err := ioutil.ReadFile(filepath.Join(currentDir, "go.mod"))
564564
if os.IsNotExist(err) {
565-
if currentDir == "/" {
565+
if currentDir == filepath.Dir(currentDir) {
566+
// at the root
566567
break
567568
}
568569
currentDir = filepath.Dir(currentDir)
@@ -571,17 +572,17 @@ func parsePackageImport(srcDir string) (string, error) {
571572
return "", err
572573
}
573574
modulePath := modfile.ModulePath(dat)
574-
return filepath.Join(modulePath, strings.TrimPrefix(srcDir, currentDir)), nil
575+
return filepath.ToSlash(filepath.Join(modulePath, strings.TrimPrefix(srcDir, currentDir))), nil
575576
}
576577
}
577578
// fall back to GOPATH mode
578579
goPath := os.Getenv("GOPATH")
579580
if goPath == "" {
580581
return "", fmt.Errorf("GOPATH is not set")
581582
}
582-
sourceRoot := filepath.Join(goPath, "src") + "/"
583+
sourceRoot := filepath.Join(goPath, "src") + string(os.PathSeparator)
583584
if !strings.HasPrefix(srcDir, sourceRoot) {
584585
return "", errOutsideGoPath
585586
}
586-
return strings.TrimPrefix(srcDir, sourceRoot), nil
587+
return filepath.ToSlash(strings.TrimPrefix(srcDir, sourceRoot)), nil
587588
}

mockgen/parse_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func TestParsePackageImport(t *testing.T) {
148148
for key, value := range testCase.envs {
149149
os.Setenv(key, value)
150150
}
151-
pkgPath, err := parsePackageImport(testCase.dir)
151+
pkgPath, err := parsePackageImport(filepath.Clean(testCase.dir))
152152
if err != testCase.err {
153153
t.Errorf("expect %v, got %v", testCase.err, err)
154154
}

0 commit comments

Comments
 (0)