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

kitgen: tests fail on Windows #740

Closed
ChrisHines opened this issue Jul 31, 2018 · 6 comments · Fixed by #831 or #840
Closed

kitgen: tests fail on Windows #740

ChrisHines opened this issue Jul 31, 2018 · 6 comments · Fixed by #831 or #840
Labels

Comments

@ChrisHines
Copy link
Member

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

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())

I didn't dig any deeper.

Full test output below.

C:\Users\Chris\Go\src\github.com\go-kit\kit>go version
go version go1.10.3 windows/amd64

C:\Users\Chris\Go\src\github.com\go-kit\kit>go test ./cmd/kitgen
--- FAIL: TestProcess (0.13s)
    --- FAIL: TestProcess/anonfields (0.02s)
        --- FAIL: TestProcess/anonfields/flat (0.02s)
                main_test.go:68:
                main_test.go:69: Processing output didn't match "testdata\\anonfields\\flat\\gokit.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\flatgokit.go605583031".
        --- FAIL: TestProcess/anonfields/default (0.00s)
                main_test.go:28: testdata\anonfields\in.go endpoints/endpoints.go:9:20: unknown escape sequence (and 5 more errors)
                        formatNodes
                        github.com/go-kit/kit/cmd/kitgen.formatNodes
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/transform.go:153
                        github.com/go-kit/kit/cmd/kitgen.deflayout.transformAST
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/deflayout.go:62
                        github.com/go-kit/kit/cmd/kitgen.(*deflayout).transformAST
                                <autogenerated>:1
                        github.com/go-kit/kit/cmd/kitgen.process
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main.go:102
                        github.com/go-kit/kit/cmd/kitgen.TestProcess.func1.1
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main_test.go:26
                        testing.tRunner
                                C:/Go/src/testing/testing.go:777
                        runtime.goexit
                                C:/Go/src/runtime/asm_amd64.s:2361
                        generating AST
                        github.com/go-kit/kit/cmd/kitgen.process
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main.go:104
                        github.com/go-kit/kit/cmd/kitgen.TestProcess.func1.1
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main_test.go:26
                        testing.tRunner
                                C:/Go/src/testing/testing.go:777
                        runtime.goexit
                                C:/Go/src/runtime/asm_amd64.s:2361
    --- FAIL: TestProcess/foo (0.02s)
        --- FAIL: TestProcess/foo/flat (0.02s)
                main_test.go:68:
                main_test.go:69: Processing output didn't match "testdata\\foo\\flat\\gokit.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\flatgokit.go133078698".
        --- FAIL: TestProcess/foo/default (0.00s)
                main_test.go:28: testdata\foo\in.go http/http.go:9:20: unknown escape sequence (and 5 more errors)
                        formatNodes
                        github.com/go-kit/kit/cmd/kitgen.formatNodes
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/transform.go:153
                        github.com/go-kit/kit/cmd/kitgen.deflayout.transformAST
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/deflayout.go:62
                        github.com/go-kit/kit/cmd/kitgen.(*deflayout).transformAST
                                <autogenerated>:1
                        github.com/go-kit/kit/cmd/kitgen.process
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main.go:102
                        github.com/go-kit/kit/cmd/kitgen.TestProcess.func1.1
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main_test.go:26
                        testing.tRunner
                                C:/Go/src/testing/testing.go:777
                        runtime.goexit
                                C:/Go/src/runtime/asm_amd64.s:2361
                        generating AST
                        github.com/go-kit/kit/cmd/kitgen.process
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main.go:104
                        github.com/go-kit/kit/cmd/kitgen.TestProcess.func1.1
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main_test.go:26
                        testing.tRunner
                                C:/Go/src/testing/testing.go:777
                        runtime.goexit
                                C:/Go/src/runtime/asm_amd64.s:2361
    --- FAIL: TestProcess/profilesvc (0.04s)
        --- FAIL: TestProcess/profilesvc/flat (0.03s)
                main_test.go:68:
                main_test.go:69: Processing output didn't match "testdata\\profilesvc\\flat\\gokit.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\flatgokit.go729902081".
        --- FAIL: TestProcess/profilesvc/default (0.01s)
                main_test.go:28: testdata\profilesvc\in.go endpoints/endpoints.go:9:20: unknown escape sequence (and 6 more errors)
                        formatNodes
                        github.com/go-kit/kit/cmd/kitgen.formatNodes
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/transform.go:153
                        github.com/go-kit/kit/cmd/kitgen.deflayout.transformAST
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/deflayout.go:62
                        github.com/go-kit/kit/cmd/kitgen.(*deflayout).transformAST
                                <autogenerated>:1
                        github.com/go-kit/kit/cmd/kitgen.process
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main.go:102
                        github.com/go-kit/kit/cmd/kitgen.TestProcess.func1.1
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main_test.go:26
                        testing.tRunner
                                C:/Go/src/testing/testing.go:777
                        runtime.goexit
                                C:/Go/src/runtime/asm_amd64.s:2361
                        generating AST
                        github.com/go-kit/kit/cmd/kitgen.process
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main.go:104
                        github.com/go-kit/kit/cmd/kitgen.TestProcess.func1.1
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main_test.go:26
                        testing.tRunner
                                C:/Go/src/testing/testing.go:777
                        runtime.goexit
                                C:/Go/src/runtime/asm_amd64.s:2361
    --- FAIL: TestProcess/stringservice (0.02s)
        --- FAIL: TestProcess/stringservice/flat (0.02s)
                main_test.go:68:
                main_test.go:69: Processing output didn't match "testdata\\stringservice\\flat\\gokit.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\flatgokit.go775458668".
        --- FAIL: TestProcess/stringservice/default (0.00s)
                main_test.go:28: testdata\stringservice\in.go endpoints/endpoints.go:9:20: unknown escape sequence (and 6 more errors)
                        formatNodes
                        github.com/go-kit/kit/cmd/kitgen.formatNodes
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/transform.go:153
                        github.com/go-kit/kit/cmd/kitgen.deflayout.transformAST
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/deflayout.go:62
                        github.com/go-kit/kit/cmd/kitgen.(*deflayout).transformAST
                                <autogenerated>:1
                        github.com/go-kit/kit/cmd/kitgen.process
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main.go:102
                        github.com/go-kit/kit/cmd/kitgen.TestProcess.func1.1
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main_test.go:26
                        testing.tRunner
                                C:/Go/src/testing/testing.go:777
                        runtime.goexit
                                C:/Go/src/runtime/asm_amd64.s:2361
                        generating AST
                        github.com/go-kit/kit/cmd/kitgen.process
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main.go:104
                        github.com/go-kit/kit/cmd/kitgen.TestProcess.func1.1
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main_test.go:26
                        testing.tRunner
                                C:/Go/src/testing/testing.go:777
                        runtime.goexit
                                C:/Go/src/runtime/asm_amd64.s:2361
    --- FAIL: TestProcess/underscores (0.02s)
        --- FAIL: TestProcess/underscores/flat (0.02s)
                main_test.go:68:
                main_test.go:69: Processing output didn't match "testdata\\underscores\\flat\\gokit.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\flatgokit.go371323355".
        --- FAIL: TestProcess/underscores/default (0.00s)
                main_test.go:28: testdata\underscores\in.go endpoints/endpoints.go:9:20: unknown escape sequence (and 6 more errors)
                        formatNodes
                        github.com/go-kit/kit/cmd/kitgen.formatNodes
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/transform.go:153
                        github.com/go-kit/kit/cmd/kitgen.deflayout.transformAST
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/deflayout.go:62
                        github.com/go-kit/kit/cmd/kitgen.(*deflayout).transformAST
                                <autogenerated>:1
                        github.com/go-kit/kit/cmd/kitgen.process
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main.go:102
                        github.com/go-kit/kit/cmd/kitgen.TestProcess.func1.1
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main_test.go:26
                        testing.tRunner
                                C:/Go/src/testing/testing.go:777
                        runtime.goexit
                                C:/Go/src/runtime/asm_amd64.s:2361
                        generating AST
                        github.com/go-kit/kit/cmd/kitgen.process
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main.go:104
                        github.com/go-kit/kit/cmd/kitgen.TestProcess.func1.1
                                C:/Users/Chris/Go/src/github.com/go-kit/kit/cmd/kitgen/main_test.go:26
                        testing.tRunner
                                C:/Go/src/testing/testing.go:777
                        runtime.goexit
                                C:/Go/src/runtime/asm_amd64.s:2361
--- FAIL: TestImportPath (0.00s)
    --- FAIL: TestImportPath/"/gopath/"_+_"/gopath/src/somewhere" (0.00s)
        path_test.go:14: Expected no error, got "\"/gopath/src/somewhere\" is not an absolute path"
    --- FAIL: TestImportPath/"/gopath"_+_"/gopath/src/somewhere" (0.00s)
        path_test.go:14: Expected no error, got "\"/gopath/src/somewhere\" is not an absolute path"
    --- FAIL: TestImportPath/"/gopath:/other"_+_"/gopath/src/somewhere" (0.00s)
        path_test.go:14: Expected no error, got "\"/gopath/src/somewhere\" is not an absolute path"
    --- FAIL: TestImportPath/"/other:/gopath/"_+_"/gopath/src/somewhere" (0.00s)
        path_test.go:14: Expected no error, got "\"/gopath/src/somewhere\" is not an absolute path"
--- FAIL: TestImportPathSadpath (0.00s)
    --- FAIL: TestImportPathSadpath/""_+_"/gopath/src/somewhere" (0.00s)
        path_test.go:36: Expected "\"/gopath/src/somewhere\" is not an absolute path" to include "is not in"
FAIL
FAIL    github.com/go-kit/kit/cmd/kitgen        0.635s
@mei-rune
Copy link
Contributor

mei-rune commented Jan 22, 2019

I find it.

return &ast.ImportSpec{Path: &ast.BasicLit{Kind: token.STRING, Value: `"` + path + `"`}}

I run kitgen in.go in the profilesvc directory
it generate file endpoints/endpoints.go

package endpoints

import "context"
import "encoding/json"
import "errors"
import "net/http"
import "github.com/go-kit/kit/endpoint"
import httptransport "github.com/go-kit/kit/transport/http"
import "github.com\go-kit\kit\cmd\kitgen\testdata\profilesvc\service"
.....

fix it, as follows

return &ast.ImportSpec{Path: &ast.BasicLit{Kind: token.STRING, Value: `"` + filepath.ToSlash(path) + `"`}}

@obeyda
Copy link
Contributor

obeyda commented Jan 24, 2019

@runner-mei solution works for me

@peterbourgon
Copy link
Member

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
@ChrisHines
Copy link
Member Author

I don't think this fixed everything. I still get test failures on the latest code:

C:\Users\Chris\Go\src\github.com\go-kit\kit>go version
go version go1.11.5 windows/amd64

C:\Users\Chris\Go\src\github.com\go-kit\kit>go test ./cmd/kitgen
--- FAIL: TestProcess (0.28s)
    --- FAIL: TestProcess/anonfields (0.05s)
        --- FAIL: TestProcess/anonfields/flat (0.01s)
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\anonfields\\flat\\gokit.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\flatgokit.go938669143".
        --- FAIL: TestProcess/anonfields/default (0.04s)
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\anonfields\\default\\http\\http.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaulthttp-http.go181315530".
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\anonfields\\default\\service\\service.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaultservice-service.go398089377".
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\anonfields\\default\\endpoints\\endpoints.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaultendpoints-endpoints.go093295500".
    --- FAIL: TestProcess/foo (0.05s)
        --- FAIL: TestProcess/foo/flat (0.01s)
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\foo\\flat\\gokit.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\flatgokit.go573520251".
        --- FAIL: TestProcess/foo/default (0.04s)
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\foo\\default\\endpoints\\endpoints.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaultendpoints-endpoints.go723785374".
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\foo\\default\\http\\http.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaulthttp-http.go896697701".
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\foo\\default\\service\\service.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaultservice-service.go144390528".
    --- FAIL: TestProcess/profilesvc (0.07s)
        --- FAIL: TestProcess/profilesvc/flat (0.02s)
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\profilesvc\\flat\\gokit.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\flatgokit.go582606559".
        --- FAIL: TestProcess/profilesvc/default (0.05s)
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\profilesvc\\default\\endpoints\\endpoints.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaultendpoints-endpoints.go530759858".
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\profilesvc\\default\\http\\http.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaulthttp-http.go387190889".
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\profilesvc\\default\\service\\service.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaultservice-service.go229415604".
    --- FAIL: TestProcess/stringservice (0.06s)
        --- FAIL: TestProcess/stringservice/flat (0.01s)
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\stringservice\\flat\\gokit.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\flatgokit.go019398275".
        --- FAIL: TestProcess/stringservice/default (0.04s)
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\stringservice\\default\\http\\http.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaulthttp-http.go197967878".
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\stringservice\\default\\service\\service.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaultservice-service.go094215085".
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\stringservice\\default\\endpoints\\endpoints.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaultendpoints-endpoints.go237385000".
    --- FAIL: TestProcess/underscores (0.05s)
        --- FAIL: TestProcess/underscores/flat (0.01s)
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\underscores\\flat\\gokit.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\flatgokit.go958798439".
        --- FAIL: TestProcess/underscores/default (0.04s)
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\underscores\\default\\endpoints\\endpoints.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaultendpoints-endpoints.go857863834".
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\underscores\\default\\http\\http.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaulthttp-http.go128728369".
            main_test.go:68:
            main_test.go:69: Processing output didn't match "testdata\\underscores\\default\\service\\service.go". Results recorded in "C:\\Users\\Chris\\AppData\\Local\\Temp\\defaultservice-service.go187418332".
--- FAIL: TestImportPath (0.00s)
    --- FAIL: TestImportPath/"/gopath/"_+_"/gopath/src/somewhere" (0.00s)
        path_test.go:14: Expected no error, got "\"/gopath/src/somewhere\" is not an absolute path"
    --- FAIL: TestImportPath/"/gopath"_+_"/gopath/src/somewhere" (0.00s)
        path_test.go:14: Expected no error, got "\"/gopath/src/somewhere\" is not an absolute path"
    --- FAIL: TestImportPath/"/gopath:/other"_+_"/gopath/src/somewhere" (0.00s)
        path_test.go:14: Expected no error, got "\"/gopath/src/somewhere\" is not an absolute path"
    --- FAIL: TestImportPath/"/other:/gopath/"_+_"/gopath/src/somewhere" (0.00s)
        path_test.go:14: Expected no error, got "\"/gopath/src/somewhere\" is not an absolute path"
--- FAIL: TestImportPathSadpath (0.00s)
    --- FAIL: TestImportPathSadpath/""_+_"/gopath/src/somewhere" (0.00s)
        path_test.go:36: Expected "\"/gopath/src/somewhere\" is not an absolute path" to include "is not in"
FAIL
FAIL    github.com/go-kit/kit/cmd/kitgen        0.954s

@mei-rune
Copy link
Contributor

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?
 				}

@ChrisHines
Copy link
Member Author

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
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants