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

path/filepath: TestEvalSymlinks tests with "/" prefix fail in Windows #24846

Open
JoshVarga opened this Issue Apr 13, 2018 · 5 comments

Comments

Projects
None yet
6 participants
@JoshVarga

JoshVarga commented Apr 13, 2018

What version of Go are you using (go version)?

go version go1.10.1 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows

What did you do?

Built go using "all.bat"

What did you expect to see?

while running tests
ok path/filepath x.xxxs

What did you see instead?

--- FAIL: TestEvalSymlinks (0.04s)
path_test.go:798: EvalSymlinks("C:\Users\varga\AppData\Local\Temp\evalsymlink400713581\test/linkabs") returns "C:\", want "/"
FAIL
FAIL path/filepath 1.552s

I have a code fix for this if this. Essentially just prepending the expected result with the volume name if we are on Windows and the path has a prefix of "/".

Does that sound reasonable?

@ALTree ALTree added this to the Go1.11 milestone Apr 13, 2018

@agnivade

This comment has been minimized.

Member

agnivade commented Apr 13, 2018

@JoshVarga JoshVarga changed the title from path/filepath: TestEvalSymlinks tests fail in Windows with "/" prefix to path/filepath: TestEvalSymlinks tests with "/" prefix fail in Windows Apr 13, 2018

@gopherbot

This comment has been minimized.

gopherbot commented Apr 13, 2018

Change https://golang.org/cl/106975 mentions this issue: path/filepath: TestEvalSymlinks tests with "/" prefix fail in Windows

@alexbrainman

This comment has been minimized.

Member

alexbrainman commented Apr 14, 2018

@JoshVarga I cannot reproduce this. How do I reproduce this?

You say you are using go1.10.1. But you error message

--- FAIL: TestEvalSymlinks (0.04s)
path_test.go:798: EvalSymlinks("C:\Users\varga\AppData\Local\Temp\evalsymlink400713581\test/linkabs") returns "C:", want "/"
FAIL
FAIL path/filepath 1.552s

does not match the code https://github.com/golang/go/blob/go1.10.1/src/path/filepath/path_test.go#L798 Why?

Please provide more details about your environment so I can try and reproduce it here: go env output, Windows version, value of %TMP% and everything else you think might be useful.

Thank you.

Alex

@JoshVarga

This comment has been minimized.

JoshVarga commented Apr 14, 2018

I don't think there is a bug in Go just in the test. I believe it is because filepath.Clean reduces the root for a Windows path to C:\ for example but it will not add a volume name onto a path like "/" (that was used in the test).

1.10.1 is my bootstrap compiler to build tip source. I boiled down the code from path_test.go so that it reproduces the issue compiling in 1.10.1 as simple as possible.

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
)

func simpleJoin(dir, path string) string {
	return dir + string(filepath.Separator) + path
}

func testEvalSymlinks(path, want string) {
	have, err := filepath.EvalSymlinks(path)
	if err != nil {
		panic(fmt.Sprintf("EvalSymlinks(%q) error: %v", path, err))
		return
	}
	if filepath.Clean(have) != filepath.Clean(want) {
		panic(fmt.Sprintf("EvalSymlinks(%q) returns %q, want %q", path, have, want))
	}
}

func main() {
	tmpDir, err := ioutil.TempDir("", "evalsymlink")
	if err != nil {
		panic(fmt.Sprintf("creating temp dir:", err))
	}
	defer os.RemoveAll(tmpDir)
	tmpDir, err = filepath.EvalSymlinks(tmpDir)
	if err != nil {
		panic(fmt.Sprintf("eval symlink for tmp dir:", err))
	}
	path := simpleJoin(tmpDir, "test")
	err = os.Mkdir(path, 0755)
	if err != nil {
		panic(err)
	}
	path = simpleJoin(tmpDir, "test/linkabs")
	err = os.Symlink("/", path)
	if err != nil {
		panic(err)
	}
	testEvalSymlinks(path, "/")
}

This is my full go env

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\varga\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\GoCode\
set GORACE=
set GOROOT=E:\go
set GOTMPDIR=
set GOTOOLDIR=E:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\varga\AppData\Local\Temp\go-build005706398=/tmp/go-build -gno-record-gcc-switches

When run the above code on my Windows 10 Pro machine I get:

panic: EvalSymlinks("C:\\Users\\varga\\AppData\\Local\\Temp\\evalsymlink097815331\\test/linkabs") returns "C:\\", want "/"

goroutine 1 [running]:
main.testEvalSymlinks(0xc04209c0f0, 0x43, 0x4d7e78, 0x1)
        E:/GoCode/src/github.com/JoshVarga/evalsym/main.go:21 +0x2ce
main.main()
        E:/GoCode/src/github.com/JoshVarga/evalsym/main.go:45 +0x23a

As requested here is my %TMP%

E:\gocode\src\github.com\JoshVarga\evalsym>ECHO %TMP%
C:\Users\varga\AppData\Local\Temp
@alexbrainman

This comment has been minimized.

Member

alexbrainman commented Apr 15, 2018

@JoshVarga thank you for providing your environment details. I can reproduce your problem now. The important difference between your setup and mine is that your GOROOT directory lives on the different drive from your TMP directory.

I think we need to adjust the test to accommodate for that scenario. I have not decided what to do yet. I will think about this when I have free time.

Alex

@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jun 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment