Skip to content

Commit 9679b30

Browse files
committed
cmd/go/testdata/script: make list_case_collision's behavior more clear
Implementing the suggestion made by bcmills on a comment on golang.org/cl/228783. Change-Id: I314a24a002c65b582ea51610dcc1a54a69afbb8c Reviewed-on: https://go-review.googlesource.com/c/go/+/229705 Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 8535008 commit 9679b30

File tree

3 files changed

+48
-16
lines changed

3 files changed

+48
-16
lines changed

src/cmd/go/script_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"runtime"
2323
"strconv"
2424
"strings"
25+
"sync"
2526
"testing"
2627
"time"
2728

@@ -296,6 +297,8 @@ Script:
296297
ok = os.Geteuid() == 0
297298
case "symlink":
298299
ok = testenv.HasSymlink()
300+
case "case-sensitive":
301+
ok = isCaseSensitive(ts.t)
299302
default:
300303
if strings.HasPrefix(cond.tag, "exec:") {
301304
prog := cond.tag[len("exec:"):]
@@ -364,6 +367,41 @@ Script:
364367
}
365368
}
366369

370+
var (
371+
onceCaseSensitive sync.Once
372+
caseSensitive bool
373+
)
374+
375+
func isCaseSensitive(t *testing.T) bool {
376+
onceCaseSensitive.Do(func() {
377+
tmpdir, err := ioutil.TempDir("", "case-sensitive")
378+
if err != nil {
379+
t.Fatal("failed to create directory to determine case-sensitivity:", err)
380+
}
381+
defer os.RemoveAll(tmpdir)
382+
383+
fcap := filepath.Join(tmpdir, "FILE")
384+
if err := ioutil.WriteFile(fcap, []byte{}, 0644); err != nil {
385+
t.Fatal("error writing file to determine case-sensitivity:", err)
386+
}
387+
388+
flow := filepath.Join(tmpdir, "file")
389+
_, err = ioutil.ReadFile(flow)
390+
switch {
391+
case err == nil:
392+
caseSensitive = false
393+
return
394+
case os.IsNotExist(err):
395+
caseSensitive = true
396+
return
397+
default:
398+
t.Fatal("unexpected error reading file when determining case-sensitivity:", err)
399+
}
400+
})
401+
402+
return caseSensitive
403+
}
404+
367405
// scriptCmds are the script command implementations.
368406
// Keep list and the implementations below sorted by name.
369407
//

src/cmd/go/testdata/script/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ should only run when the condition is satisfied. The available conditions are:
8585
- [link] for testenv.HasLink()
8686
- [root] for os.Geteuid() == 0
8787
- [symlink] for testenv.HasSymlink()
88+
- [case-sensitive] for whether the file system is case-sensitive
8889
- [exec:prog] for whether prog is available for execution (found by exec.LookPath)
8990
- [GODEBUG:value] for whether value is one of the comma-separated entries in the GODEBUG variable
9091
- [buildmode:value] for whether -buildmode=value is supported

src/cmd/go/testdata/script/list_case_collision.txt

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@ stdout 'case-insensitive import collision'
66
! go build example/a
77
stderr 'case-insensitive import collision'
88

9-
# If we're not guaranteed to have a case-sensitive file system, list files explicitly on command line.
10-
# Otherwise, let directory read find both files.
11-
[darwin] ! go list example/b/file.go example/b/FILE.go
12-
[windows] ! go list example/b/file.go example/b/FILE.go
13-
[!darwin] [!windows] ! go list example/b
9+
# List files explicitly on command line, to encounter case-checking
10+
# logic even on case-insensitive filesystems.
11+
cp example/b/file.go example/b/FILE.go # no-op on case-insensitive filesystems
12+
! go list example/b/file.go example/b/FILE.go
1413
stderr 'case-insensitive file name collision'
1514

15+
mkdir example/a/Pkg # no-op on case-insensitive filesystems
16+
cp example/a/pkg/pkg.go example/a/Pkg/pkg.go # no-op on case-insensitive filesystems
1617
! go list example/a/pkg example/a/Pkg
17-
stderr 'case-insensitive import collision'
18-
go list -json -e example/a/pkg example/a/Pkg
19-
stdout 'case-insensitive import collision'
20-
! go build example/a/pkg example/a/Pkg
21-
stderr 'case-insensitive import collision'
2218

2319
# Test that the path reported with an indirect import is correct.
24-
[!darwin] [!windows] ! go build example/c
25-
[!darwin] [!windows] stderr '^package example/c\n\timports example/b: case-insensitive file name collision: "FILE.go" and "file.go"$'
20+
cp example/b/file.go example/b/FILE.go
21+
[case-sensitive] ! go build example/c
22+
[case-sensitive] stderr '^package example/c\n\timports example/b: case-insensitive file name collision: "FILE.go" and "file.go"$'
2623

2724
-- example/a/a.go --
2825
package p
@@ -32,12 +29,8 @@ import (
3229
)
3330
-- example/a/pkg/pkg.go --
3431
package pkg
35-
-- example/a/Pkg/pkg.go --
36-
package pkg
3732
-- example/b/file.go --
3833
package b
39-
-- example/b/FILE.go --
40-
package b
4134
-- example/c/c.go --
4235
package c
4336

0 commit comments

Comments
 (0)