From 414b45d91a3bcb5dacd5061c9a93cb8936592b87 Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Mon, 10 Feb 2014 10:41:47 +1100 Subject: [PATCH] cmd/go: fix test.bash 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 | 27 +++++++++++++++++++++++++++ src/cmd/go/test.bash | 20 +++++++++++++------- 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 src/cmd/go/pkg_test.go diff --git a/src/cmd/go/pkg_test.go b/src/cmd/go/pkg_test.go new file mode 100644 index 0000000000..f3590b9632 --- /dev/null +++ b/src/cmd/go/pkg_test.go @@ -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) + } + } +} diff --git a/src/cmd/go/test.bash b/src/cmd/go/test.bash index 6c6cb9ed78..d0926e2105 100755 --- a/src/cmd/go/test.bash +++ b/src/cmd/go/test.bash @@ -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 <$d/src/example/a/pkg/pkg.go <$d/src/example/a/Pkg/pkg.go <$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 -- 2.48.1