mirror of
https://github.com/golang/go
synced 2024-11-18 14:54:40 -07:00
82bb89366a
On case-insensitive file systems, the editor may send us a path that works but doesn't match the actual file's case. Then when we run go list, we'll get mismatching paths and everything will break. We can't reliably fix this problem: tracking what case the editor expects is too difficult to be worth it. Instead, check the workspace path and bail if it's mismatched. Possibly we should also check files on DidOpen or such, but we can start with this. Updates golang/go#36904. Change-Id: I7635c8136bf9400db4143a0f2fde25c39b5abc44 Reviewed-on: https://go-review.googlesource.com/c/tools/+/225239 Reviewed-by: Ian Cottrell <iancottrell@google.com>
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
// Copyright 2020 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
package cache
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCaseInsensitiveFilesystem(t *testing.T) {
|
|
base, err := ioutil.TempDir("", t.Name())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
inner := filepath.Join(base, "a/B/c/DEFgh")
|
|
if err := os.MkdirAll(inner, 0777); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
file := filepath.Join(inner, "f.go")
|
|
if err := ioutil.WriteFile(file, []byte("hi"), 0777); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(inner, "F.go")); err != nil {
|
|
t.Skip("filesystem is case-sensitive")
|
|
}
|
|
|
|
tests := []struct {
|
|
path string
|
|
err bool
|
|
}{
|
|
{file, false},
|
|
{filepath.Join(inner, "F.go"), true},
|
|
{filepath.Join(base, "a/b/c/defgh/f.go"), true},
|
|
}
|
|
for _, tt := range tests {
|
|
err := checkPathCase(tt.path)
|
|
if err != nil != tt.err {
|
|
t.Errorf("checkPathCase(%q) = %v, wanted error: %v", tt.path, err, tt.err)
|
|
}
|
|
}
|
|
}
|