forked from mirror/gorm
fix bug in windows (#5844)
* fix bug in windows * fix file name bug * test in unix like platform
This commit is contained in:
parent
cef3de694d
commit
b6836c2d3e
|
@ -27,7 +27,7 @@ func sourceDir(file string) string {
|
||||||
if filepath.Base(s) != "gorm.io" {
|
if filepath.Base(s) != "gorm.io" {
|
||||||
s = dir
|
s = dir
|
||||||
}
|
}
|
||||||
return s + string(filepath.Separator)
|
return filepath.ToSlash(s) + "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileWithLineNum return the file name and line number of the current file
|
// FileWithLineNum return the file name and line number of the current file
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
|
//go:build unix
|
||||||
|
// +build unix
|
||||||
|
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestSourceDir(t *testing.T) {
|
func TestSourceDir(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestSourceDir(t *testing.T) {
|
func TestSourceDir(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
|
@ -8,20 +10,20 @@ func TestSourceDir(t *testing.T) {
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
file: `C:\Users\name\go\pkg\mod\gorm.io\gorm@v1.20.8\utils\utils.go`,
|
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`,
|
want: `C:/Users/name/go/pkg/mod/gorm.io/`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
file: `C:\go\work\proj\gorm\utils\utils.go`,
|
file: `C:/go/work/proj/gorm/utils/utils.go`,
|
||||||
want: `C:\go\work\proj\gorm`,
|
want: `C:/go/work/proj/gorm/`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
file: `C:\go\work\proj\gorm_alias\utils\utils.go`,
|
file: `C:/go/work/proj/gorm_alias/utils/utils.go`,
|
||||||
want: `C:\go\work\proj\gorm_alias`,
|
want: `C:/go/work/proj/gorm_alias/`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
file: `C:\go\work\proj\my.gorm.io\gorm\utils\utils.go`,
|
file: `C:/go/work/proj/my.gorm.io/gorm@v1.2.3/utils/utils.go`,
|
||||||
want: `C:\go\work\proj\my.gorm.io\gorm`,
|
want: `C:/go/work/proj/my.gorm.io/gorm@v1.2.3/`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
|
Loading…
Reference in New Issue