]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix test.bash
authorDave Cheney <dave@cheney.net>
Sun, 9 Feb 2014 23:41:47 +0000 (10:41 +1100)
committerDave Cheney <dave@cheney.net>
Sun, 9 Feb 2014 23:41:47 +0000 (10:41 +1100)
Fixes #7260.

Fix three broken tests in test.bash

The test for issue 4568 was confused by go $ACTION . producing a package root of "", avoiding this mode fixes the test but weakens the test.

The test for issue 4773 was broken on linux because math/Rand would fail to resolve as a package causing the test for duplicates to be skipped.

Finally, the last breakage was a small change in the error message.

Also, add test for foldDup.

LGTM=iant
R=iant, rsc
CC=golang-codereviews
https://golang.org/cl/61070044

src/cmd/go/pkg_test.go [new file with mode: 0644]
src/cmd/go/test.bash

diff --git a/src/cmd/go/pkg_test.go b/src/cmd/go/pkg_test.go
new file mode 100644 (file)
index 0000000..f3590b9
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright 2014 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 main
+
+import "testing"
+
+var foldDupTests = []struct {
+       list   []string
+       f1, f2 string
+}{
+       {stringList("math/rand", "math/big"), "", ""},
+       {stringList("math", "strings"), "", ""},
+       {stringList("strings"), "", ""},
+       {stringList("strings", "strings"), "strings", "strings"},
+       {stringList("Rand", "rand", "math", "math/rand", "math/Rand"), "Rand", "rand"},
+}
+
+func TestFoldDup(t *testing.T) {
+       for _, tt := range foldDupTests {
+               f1, f2 := foldDup(tt.list)
+               if f1 != tt.f1 || f2 != tt.f2 {
+                       t.Errorf("foldDup(%q) = %q, %q, want %q, %q", tt.list, f1, f2, tt.f1, tt.f2)
+               }
+       }
+}
index 6c6cb9ed7893b5ed525a525bae3862744b2f6061..d0926e21052b348b4b3b53d8860d77074944810a 100755 (executable)
@@ -427,10 +427,10 @@ d=$(TMPDIR=$tmp mktemp -d -t testgoXXX)
 mkdir -p $d/src
 (
        ln -s $d $d/src/dir1
-       cd $d/src/dir1
-       echo package p >p.go
+       cd $d/src
+       echo package p >dir1/p.go
        export GOPATH=$d
-       if [ "$($old/testgo list -f '{{.Root}}' .)" != "$d" ]; then
+       if [ "$($old/testgo list -f '{{.Root}}' dir1)" != "$d" ]; then
                echo Confused by symlinks.
                echo "Package in current directory $(pwd) should have Root $d"
                env|grep WD
@@ -479,14 +479,20 @@ rm -rf $d
 TEST case collisions '(issue 4773)'
 d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
 export GOPATH=$d
-mkdir -p $d/src/example/a $d/src/example/b
+mkdir -p $d/src/example/{a/pkg,a/Pkg,b}
 cat >$d/src/example/a/a.go <<EOF
 package p
 import (
-       _ "math/rand"
-       _ "math/Rand"
+       _ "example/a/pkg"
+       _ "example/a/Pkg"
 )
 EOF
+cat >$d/src/example/a/pkg/pkg.go <<EOF
+package pkg
+EOF
+cat >$d/src/example/a/Pkg/pkg.go <<EOF
+package pkg
+EOF
 if ./testgo list example/a 2>$d/out; then
        echo go list example/a should have failed, did not.
        ok=false
@@ -547,7 +553,7 @@ fi
 
 # The error for go install should mention the conflicting directory.
 err=$(! ./testgo install ./testdata/shadow/root2/src/foo 2>&1)
-if [ "$err" != "go install: no install location for directory $(pwd)/testdata/shadow/root2/src/foo hidden by $(pwd)/testdata/shadow/root1/src/foo" ]; then
+if [ "$err" != "go install: no install location for $(pwd)/testdata/shadow/root2/src/foo: hidden by $(pwd)/testdata/shadow/root1/src/foo" ]; then
        echo wrong shadowed install error: "$err"
        ok=false
 fi