Skip to content

Commit

Permalink
cmd/go: convert some tests in vendor_test to the script framework
Browse files Browse the repository at this point in the history
Part of converting all tests to script framework to improve
test parallelism.

Updates #36320
Updates #17751

Change-Id: I601e0fcee32b8c5bf2107b520d1dfbe12a19ad3f
Reviewed-on: https://go-review.googlesource.com/c/go/+/213223
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
matloob committed Feb 27, 2020
1 parent 2cfc5e2 commit c6d281e
Show file tree
Hide file tree
Showing 37 changed files with 476 additions and 428 deletions.
41 changes: 41 additions & 0 deletions src/cmd/go/testdata/script/build_vendor.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Build
go build vend/x
! stdout .
! stderr .

-- vend/dir1/dir1.go --
package dir1
-- vend/subdir/bad.go --
package subdir

import _ "r"
-- vend/subdir/good.go --
package subdir

import _ "p"
-- vend/vendor/p/p.go --
package p
-- vend/vendor/q/q.go --
package q
-- vend/vendor/vend/dir1/dir2/dir2.go --
package dir2
-- vend/x/invalid/invalid.go --
package invalid

import "vend/x/invalid/vendor/foo"
-- vend/x/vendor/p/p/p.go --
package p

import _ "notfound"
-- vend/x/vendor/p/p.go --
package p
-- vend/x/vendor/r/r.go --
package r
-- vend/x/x.go --
package x

import _ "p"
import _ "q"
import _ "r"
import _ "vend/dir1" // not vendored
import _ "vend/dir1/dir2" // vendored
94 changes: 94 additions & 0 deletions src/cmd/go/testdata/script/get_vendor.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
[short] skip

cd $GOPATH/src/v
go run m.go
go test
go list -f '{{.Imports}}'
stdout 'v/vendor/vendor.org/p'
go list -f '{{.TestImports}}'
stdout 'v/vendor/vendor.org/p'
go get -d
go get -t -d

[!net] stop
[!exec:git] stop

cd $GOPATH/src

# Update
go get 'github.com/rsc/go-get-issue-11864'
go get -u 'github.com/rsc/go-get-issue-11864'
exists github.com/rsc/go-get-issue-11864/vendor

# get -u
rm $GOPATH
mkdir $GOPATH/src
go get -u 'github.com/rsc/go-get-issue-11864'
exists github.com/rsc/go-get-issue-11864/vendor

# get -t -u
rm $GOPATH
mkdir $GOPATH/src
go get -t -u 'github.com/rsc/go-get-issue-11864/...'
exists github.com/rsc/go-get-issue-11864/vendor

# Submodules
rm $GOPATH
mkdir $GOPATH/src
go get -d 'github.com/rsc/go-get-issue-12612'
go get -u -d 'github.com/rsc/go-get-issue-12612'
exists github.com/rsc/go-get-issue-12612/vendor/golang.org/x/crypto/.git

# Bad vendor (bad/imp)
rm $GOPATH
mkdir $GOPATH/src
! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/imp'
stderr 'must be imported as'
! exists github.com/rsc/go-get-issue-11864/vendor

# Bad vendor (bad/imp2)
rm $GOPATH
mkdir $GOPATH/src
! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/imp2'
stderr 'must be imported as'
! exists github.com/rsc/go-get-issue-11864/vendor

# Bad vendor (bad/imp3)
rm $GOPATH
mkdir $GOPATH/src
! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/imp3'
stderr 'must be imported as'
! exists github.com/rsc/go-get-issue-11864/vendor

# Bad vendor (bad/...)
rm $GOPATH
mkdir $GOPATH/src
! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/...'
stderr 'must be imported as'
! exists github.com/rsc/go-get-issue-11864/vendor

-- v/m.go --
package main

import (
"fmt"
"vendor.org/p"
)

func main() {
fmt.Println(p.C)
}
-- v/m_test.go --
package main
import (
"fmt"
"testing"
"vendor.org/p"
)

func TestNothing(t *testing.T) {
fmt.Println(p.C)
}
-- v/vendor/vendor.org/p/p.go --
package p
const C = 1
33 changes: 33 additions & 0 deletions src/cmd/go/testdata/script/run_vendor.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Run
cd vend/hello
go run hello.go
stdout 'hello, world'

-- vend/hello/hello.go --
package main

import (
"fmt"
"strings" // really ../vendor/strings
)

func main() {
fmt.Printf("%s\n", strings.Msg)
}
-- vend/hello/hello_test.go --
package main

import (
"strings" // really ../vendor/strings
"testing"
)

func TestMsgInternal(t *testing.T) {
if strings.Msg != "hello, world" {
t.Fatalf("unexpected msg: %v", strings.Msg)
}
}
-- vend/vendor/strings/msg.go --
package strings

var Msg = "hello, world"
47 changes: 47 additions & 0 deletions src/cmd/go/testdata/script/test_vendor.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Test
cd vend/hello
go test -v
stdout TestMsgInternal
stdout TestMsgExternal

-- vend/hello/hello.go --
package main

import (
"fmt"
"strings" // really ../vendor/strings
)

func main() {
fmt.Printf("%s\n", strings.Msg)
}
-- vend/hello/hello_test.go --
package main

import (
"strings" // really ../vendor/strings
"testing"
)

func TestMsgInternal(t *testing.T) {
if strings.Msg != "hello, world" {
t.Fatalf("unexpected msg: %v", strings.Msg)
}
}
-- vend/hello/hellox_test.go --
package main_test

import (
"strings" // really ../vendor/strings
"testing"
)

func TestMsgExternal(t *testing.T) {
if strings.Msg != "hello, world" {
t.Fatalf("unexpected msg: %v", strings.Msg)
}
}
-- vend/vendor/strings/msg.go --
package strings

var Msg = "hello, world"
51 changes: 51 additions & 0 deletions src/cmd/go/testdata/script/vendor_gopath_issue11409.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[!windows] [short] stop 'this test only applies to Windows'

go build run_go.go
exec ./run_go$GOEXE $GOPATH $GOPATH/src/vend/hello
stdout 'hello, world'

-- run_go.go --
package main

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)

func changeVolume(s string, f func(s string) string) string {
vol := filepath.VolumeName(s)
return f(vol) + s[len(vol):]
}

func main() {
gopath := changeVolume(os.Args[1], strings.ToLower)
dir := changeVolume(os.Args[2], strings.ToUpper)
cmd := exec.Command("go", "run", "hello.go")
cmd.Dir = dir
cmd.Env = append(os.Environ(), "GOPATH="+gopath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

-- vend/hello/hello.go --
package main

import (
"fmt"
"strings" // really ../vendor/strings
)

func main() {
fmt.Printf("%s\n", strings.Msg)
}
-- vend/vendor/strings/msg.go --
package strings

var Msg = "hello, world"
103 changes: 103 additions & 0 deletions src/cmd/go/testdata/script/vendor_import.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Imports
go list -f '{{.ImportPath}} {{.Imports}}' 'vend/...' 'vend/vendor/...' 'vend/x/vendor/...'
cmp stdout want_vendor_imports.txt

-- want_vendor_imports.txt --
vend [vend/vendor/p r]
vend/dir1 []
vend/hello [fmt vend/vendor/strings]
vend/subdir [vend/vendor/p r]
vend/x [vend/x/vendor/p vend/vendor/q vend/x/vendor/r vend/dir1 vend/vendor/vend/dir1/dir2]
vend/x/invalid [vend/x/invalid/vendor/foo]
vend/vendor/p []
vend/vendor/q []
vend/vendor/strings []
vend/vendor/vend/dir1/dir2 []
vend/x/vendor/p []
vend/x/vendor/p/p [notfound]
vend/x/vendor/r []
-- vend/bad.go --
package vend

import _ "r"
-- vend/dir1/dir1.go --
package dir1
-- vend/good.go --
package vend

import _ "p"
-- vend/hello/hello.go --
package main

import (
"fmt"
"strings" // really ../vendor/strings
)

func main() {
fmt.Printf("%s\n", strings.Msg)
}
-- vend/hello/hello_test.go --
package main

import (
"strings" // really ../vendor/strings
"testing"
)

func TestMsgInternal(t *testing.T) {
if strings.Msg != "hello, world" {
t.Fatalf("unexpected msg: %v", strings.Msg)
}
}
-- vend/hello/hellox_test.go --
package main_test

import (
"strings" // really ../vendor/strings
"testing"
)

func TestMsgExternal(t *testing.T) {
if strings.Msg != "hello, world" {
t.Fatalf("unexpected msg: %v", strings.Msg)
}
}
-- vend/subdir/bad.go --
package subdir

import _ "r"
-- vend/subdir/good.go --
package subdir

import _ "p"
-- vend/vendor/p/p.go --
package p
-- vend/vendor/q/q.go --
package q
-- vend/vendor/strings/msg.go --
package strings

var Msg = "hello, world"
-- vend/vendor/vend/dir1/dir2/dir2.go --
package dir2
-- vend/x/invalid/invalid.go --
package invalid

import "vend/x/invalid/vendor/foo"
-- vend/x/vendor/p/p/p.go --
package p

import _ "notfound"
-- vend/x/vendor/p/p.go --
package p
-- vend/x/vendor/r/r.go --
package r
-- vend/x/x.go --
package x

import _ "p"
import _ "q"
import _ "r"
import _ "vend/dir1" // not vendored
import _ "vend/dir1/dir2" // vendored
7 changes: 7 additions & 0 deletions src/cmd/go/testdata/script/vendor_import_missing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Missing package error message
! go build vend/x/vendor/p/p

-- vend/x/vendor/p/p/p.go --
package p

import _ "notfound"
9 changes: 9 additions & 0 deletions src/cmd/go/testdata/script/vendor_import_wrong.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Wrong import path
! go build vend/x/invalid
stderr 'must be imported as foo'

-- vend/x/invalid/invalid.go --
package invalid

import "vend/x/invalid/vendor/foo"

Loading

0 comments on commit c6d281e

Please sign in to comment.