]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/testdata/script: make list_case_collision's behavior more clear
authorMichael Matloob <matloob@golang.org>
Thu, 23 Apr 2020 22:06:21 +0000 (18:06 -0400)
committerMichael Matloob <matloob@golang.org>
Fri, 21 Aug 2020 16:52:08 +0000 (16:52 +0000)
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 <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/script_test.go
src/cmd/go/testdata/script/README
src/cmd/go/testdata/script/list_case_collision.txt

index 2e8f18a897222c6d58157817d20143bd01c3e967..986646252a1ef9d21802eadeb4b4c32a58405778 100644 (file)
@@ -22,6 +22,7 @@ import (
        "runtime"
        "strconv"
        "strings"
+       "sync"
        "testing"
        "time"
 
@@ -296,6 +297,8 @@ Script:
                                ok = os.Geteuid() == 0
                        case "symlink":
                                ok = testenv.HasSymlink()
+                       case "case-sensitive":
+                               ok = isCaseSensitive(ts.t)
                        default:
                                if strings.HasPrefix(cond.tag, "exec:") {
                                        prog := cond.tag[len("exec:"):]
@@ -364,6 +367,41 @@ Script:
        }
 }
 
+var (
+       onceCaseSensitive sync.Once
+       caseSensitive     bool
+)
+
+func isCaseSensitive(t *testing.T) bool {
+       onceCaseSensitive.Do(func() {
+               tmpdir, err := ioutil.TempDir("", "case-sensitive")
+               if err != nil {
+                       t.Fatal("failed to create directory to determine case-sensitivity:", err)
+               }
+               defer os.RemoveAll(tmpdir)
+
+               fcap := filepath.Join(tmpdir, "FILE")
+               if err := ioutil.WriteFile(fcap, []byte{}, 0644); err != nil {
+                       t.Fatal("error writing file to determine case-sensitivity:", err)
+               }
+
+               flow := filepath.Join(tmpdir, "file")
+               _, err = ioutil.ReadFile(flow)
+               switch {
+               case err == nil:
+                       caseSensitive = false
+                       return
+               case os.IsNotExist(err):
+                       caseSensitive = true
+                       return
+               default:
+                       t.Fatal("unexpected error reading file when determining case-sensitivity:", err)
+               }
+       })
+
+       return caseSensitive
+}
+
 // scriptCmds are the script command implementations.
 // Keep list and the implementations below sorted by name.
 //
index 76d665171830f2843fb172b7fee5244ab456cbc7..d658cebfce0170e8fcd2956b2bd2e11d74a2555c 100644 (file)
@@ -85,6 +85,7 @@ should only run when the condition is satisfied. The available conditions are:
    - [link] for testenv.HasLink()
    - [root] for os.Geteuid() == 0
    - [symlink] for testenv.HasSymlink()
+   - [case-sensitive] for whether the file system is case-sensitive
    - [exec:prog] for whether prog is available for execution (found by exec.LookPath)
    - [GODEBUG:value] for whether value is one of the comma-separated entries in the GODEBUG variable
    - [buildmode:value] for whether -buildmode=value is supported
index 1b5f30558753499b0391dbfee5cb5a8762aa0b46..73f44b63a0758557286c27c7f51c7a899449e7c8 100644 (file)
@@ -6,23 +6,20 @@ stdout 'case-insensitive import collision'
 ! go build example/a
 stderr 'case-insensitive import collision'
 
-# If we're not guaranteed to have a case-sensitive file system, list files explicitly on command line.
-# Otherwise, let directory read find both files.
-[darwin] ! go list example/b/file.go example/b/FILE.go
-[windows] ! go list example/b/file.go example/b/FILE.go
-[!darwin] [!windows] ! go list example/b
+# List files explicitly on command line, to encounter case-checking
+# logic even on case-insensitive filesystems.
+cp example/b/file.go example/b/FILE.go  # no-op on case-insensitive filesystems
+! go list example/b/file.go example/b/FILE.go
 stderr 'case-insensitive file name collision'
 
+mkdir example/a/Pkg  # no-op on case-insensitive filesystems
+cp example/a/pkg/pkg.go example/a/Pkg/pkg.go  # no-op on case-insensitive filesystems
 ! go list example/a/pkg example/a/Pkg
-stderr 'case-insensitive import collision'
-go list -json -e example/a/pkg example/a/Pkg
-stdout 'case-insensitive import collision'
-! go build example/a/pkg example/a/Pkg
-stderr 'case-insensitive import collision'
 
 # Test that the path reported with an indirect import is correct.
-[!darwin] [!windows] ! go build example/c
-[!darwin] [!windows] stderr '^package example/c\n\timports example/b: case-insensitive file name collision: "FILE.go" and "file.go"$'
+cp example/b/file.go example/b/FILE.go
+[case-sensitive] ! go build example/c
+[case-sensitive] stderr '^package example/c\n\timports example/b: case-insensitive file name collision: "FILE.go" and "file.go"$'
 
 -- example/a/a.go --
 package p
@@ -32,12 +29,8 @@ import (
 )
 -- example/a/pkg/pkg.go --
 package pkg
--- example/a/Pkg/pkg.go --
-package pkg
 -- example/b/file.go --
 package b
--- example/b/FILE.go --
-package b
 -- example/c/c.go --
 package c