fix bug in windows

This commit is contained in:
kvii 2022-11-05 12:32:56 +08:00
parent 9cf6c1be43
commit c90cafd05f
2 changed files with 9 additions and 9 deletions

View File

@ -27,7 +27,7 @@ func sourceDir(file string) string {
if filepath.Base(s) != "gorm.io" {
s = dir
}
return s + string(filepath.Separator)
return filepath.ToSlash(s) + "/"
}
// FileWithLineNum return the file name and line number of the current file

View File

@ -11,20 +11,20 @@ func TestSourceDir(t *testing.T) {
want string
}{
{
file: `C:\Users\name\go\pkg\mod\gorm.io\gorm@v1.2.3\utils\utils.go`,
want: `C:\Users\name\go\pkg\mod\gorm.io\`,
file: `C:/Users/name/go/pkg/mod/gorm.io/gorm@v1.2.3/utils/utils.go`,
want: `C:/Users/name/go/pkg/mod/gorm.io/`,
},
{
file: `C:\go\work\proj\gorm\utils\utils.go`,
want: `C:\go\work\proj\gorm\`,
file: `C:/go/work/proj/gorm/utils/utils.go`,
want: `C:/go/work/proj/gorm/`,
},
{
file: `C:\go\work\proj\gorm_alias\utils\utils.go`,
want: `C:\go\work\proj\gorm_alias\`,
file: `C:/go/work/proj/gorm_alias/utils/utils.go`,
want: `C:/go/work/proj/gorm_alias/`,
},
{
file: `C:\go\work\proj\my.gorm.io\gorm@v1.2.3\utils\utils.go`,
want: `C:\go\work\proj\my.gorm.io\gorm@v1.2.3\`,
file: `C:/go/work/proj/my.gorm.io/gorm@v1.2.3/utils/utils.go`,
want: `C:/go/work/proj/my.gorm.io/gorm@v1.2.3/`,
},
}
for _, c := range cases {