-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
kitgen: tests fail on Windows #740
Labels
Comments
I find it. Line 207 in 8a8a1bb
I run
fix it, as follows
|
@runner-mei solution works for me |
PR happily accepted. |
peterbourgon
pushed a commit
that referenced
this issue
Feb 1, 2019
add filepath.ToSlash() to convert backSlashes to forward slashes in path fixes: #740
I don't think this fixed everything. I still get test failures on the latest code:
|
diff --git a/cmd/kitgen/main_test.go b/cmd/kitgen/main_test.go
index 4ef5013..6b134a1 100644
--- a/cmd/kitgen/main_test.go
+++ b/cmd/kitgen/main_test.go
@@ -1,15 +1,16 @@
package main
import (
+ "bufio"
"bytes"
"flag"
"fmt"
- "io"
"io/ioutil"
"os/exec"
"path/filepath"
- "strings"
"testing"
+
+ "github.com/aryann/difflib"
)
var update = flag.Bool("update", false, "update golden files")
@@ -54,19 +55,13 @@ func TestProcess(t *testing.T) {
}
if !bytes.Equal(expected, actual) {
- name := kind + filename
- name = strings.Replace(name, "/", "-", -1)
-
- errfile, err := ioutil.TempFile("", name)
- if err != nil {
- t.Fatal("opening tempfile for output", err)
+ results := difflib.Diff(splitLines(expected), splitLines(actual))
+ for _, result := range results {
+ if result.Delta == difflib.Common {
+ continue
+ }
+ t.Error(result)
}
- io.WriteString(errfile, string(actual))
-
- diffCmd := exec.Command("diff", outpath, errfile.Name())
- diffOut, _ := diffCmd.Output()
- t.Log(string(diffOut))
- t.Errorf("Processing output didn't match %q. Results recorded in %q.", outpath, errfile.Name())
}
}
@@ -111,3 +106,13 @@ func TestTemplatesBuild(t *testing.T) {
t.Fatal(err, "\n", string(out))
}
}
+
+func splitLines(txt []byte) []string {
+ //r := bufio.NewReader(strings.NewReader(s))
+ s := bufio.NewScanner(bytes.NewReader(txt))
+ var ss []string
+ for s.Scan() {
+ ss = append(ss, s.Text())
+ }
+ return ss
+}
diff --git a/cmd/kitgen/path_test.go b/cmd/kitgen/path_test.go
index 371ded1..7a7b928 100644
--- a/cmd/kitgen/path_test.go
+++ b/cmd/kitgen/path_test.go
@@ -2,6 +2,7 @@ package main
import (
"fmt"
+ "runtime"
"strings"
"testing"
)
@@ -19,10 +20,17 @@ func TestImportPath(t *testing.T) {
})
}
- testcase("/gopath/", "/gopath/src/somewhere", "somewhere")
- testcase("/gopath", "/gopath/src/somewhere", "somewhere")
- testcase("/gopath:/other", "/gopath/src/somewhere", "somewhere")
- testcase("/other:/gopath/", "/gopath/src/somewhere", "somewhere")
+ if runtime.GOOS == "windows" {
+ testcase("c:\\gopath\\", "c:\\gopath\\src\\somewhere", "somewhere")
+ testcase("c:\\gopath", "c:\\gopath\\src\\somewhere", "somewhere")
+ testcase("c:\\gopath;\\other", "c:\\gopath\\src\\somewhere", "somewhere")
+ testcase("c:\\other;c:\\gopath\\", "c:\\gopath\\src\\somewhere", "somewhere")
+ } else {
+ testcase("/gopath/", "/gopath/src/somewhere", "somewhere")
+ testcase("/gopath", "/gopath/src/somewhere", "somewhere")
+ testcase("/gopath:/other", "/gopath/src/somewhere", "somewhere")
+ testcase("/other:/gopath/", "/gopath/src/somewhere", "somewhere")
+ }
}
func TestImportPathSadpath(t *testing.T) {
@@ -38,6 +46,10 @@ func TestImportPathSadpath(t *testing.T) {
})
}
- testcase("", "/gopath/src/somewhere", "is not in")
+ if runtime.GOOS == "windows" {
+ testcase("", "c:\\gopath\\src\\somewhere", "is not in")
+ } else {
+ testcase("", "/gopath/src/somewhere", "is not in")
+ }
testcase("", "./somewhere", "not an absolute")
}
diff --git a/cmd/kitgen/transform.go b/cmd/kitgen/transform.go
index 362398c..a66ff96 100644
--- a/cmd/kitgen/transform.go
+++ b/cmd/kitgen/transform.go
@@ -178,7 +178,7 @@ func addImport(root *ast.File, path string) {
for _, d := range root.Decls {
if imp, is := d.(*ast.GenDecl); is && imp.Tok == token.IMPORT {
for _, s := range imp.Specs {
- if s.(*ast.ImportSpec).Path.Value == `"`+path+`"` {
+ if s.(*ast.ImportSpec).Path.Value == `"`+filepath.ToSlash(path)+`"` {
return // already have one
// xxx aliased imports?
} |
That patch looks helpful @runner-mei . Would you mind opening a PR with those changes? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A quick peek at what the first failing test is doing reveals it is relying on *nix style tools and not checking error returns. https://github.com/go-kit/kit/blob/master/cmd/kitgen/main_test.go#L66
I didn't dig any deeper.
Full test output below.
The text was updated successfully, but these errors were encountered: