Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in windows #5844

Merged
merged 4 commits into from Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion utils/utils.go
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion utils/utils_unix_test.go
@@ -1,6 +1,11 @@
//go:build unix
kvii marked this conversation as resolved.
Show resolved Hide resolved
// +build unix

package utils

import "testing"
import (
"testing"
)

func TestSourceDir(t *testing.T) {
cases := []struct {
Expand Down
20 changes: 11 additions & 9 deletions utils/utils_windows_test.go
@@ -1,27 +1,29 @@
package utils

import "testing"
import (
"testing"
)

func TestSourceDir(t *testing.T) {
cases := []struct {
file string
want string
}{
{
file: `C:\Users\name\go\pkg\mod\gorm.io\gorm@v1.20.8\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\utils\utils.go`,
want: `C:\go\work\proj\my.gorm.io\gorm`,
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 {
Expand Down