Skip to content

Commit c9e81c0

Browse files
committed
tests: Add test that GopherJS can be vendored.
This test is expected to fail here, because the current master version doesn't support GopherJS being vendored.
1 parent 558a913 commit c9e81c0

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

tests/gopherjsvendored_test.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# Don't run this file directly. It's executed as part of TestGopherJSCanBeVendored.
3+
4+
set -e
5+
6+
tmp=$(mktemp -d "${TMPDIR:-/tmp}/gopherjsvendored_test.XXXXXXXXXX")
7+
8+
cleanup() {
9+
rm -rf "$tmp"
10+
exit
11+
}
12+
13+
trap cleanup EXIT SIGHUP SIGINT SIGTERM
14+
15+
# Make a hello project that will vendor GopherJS.
16+
mkdir -p "$tmp/src/example.org/hello"
17+
echo 'package main
18+
19+
import "github.com/gopherjs/gopherjs/js"
20+
21+
func main() {
22+
js.Global.Get("console").Call("log", "hello using js pkg")
23+
}' > "$tmp/src/example.org/hello/main.go"
24+
25+
# Vendor GopherJS and its dependencies into hello project.
26+
mkdir -p "$tmp/src/example.org/hello/vendor/github.com/gopherjs" \
27+
"$tmp/src/example.org/hello/vendor/github.com/fsnotify" \
28+
"$tmp/src/example.org/hello/vendor/github.com/kisielk" \
29+
"$tmp/src/example.org/hello/vendor/github.com/neelance" \
30+
"$tmp/src/example.org/hello/vendor/github.com/shurcooL" \
31+
"$tmp/src/example.org/hello/vendor/github.com/spf13" \
32+
"$tmp/src/example.org/hello/vendor/golang.org/x"
33+
cp -r $(go list -e -f '{{.Dir}}' github.com/gopherjs/gopherjs) "$tmp/src/example.org/hello/vendor/github.com/gopherjs/gopherjs"
34+
cp -r $(go list -e -f '{{.Dir}}' github.com/fsnotify/fsnotify) "$tmp/src/example.org/hello/vendor/github.com/fsnotify/fsnotify"
35+
cp -r $(go list -e -f '{{.Dir}}' github.com/kisielk/gotool) "$tmp/src/example.org/hello/vendor/github.com/kisielk/gotool"
36+
cp -r $(go list -e -f '{{.Dir}}' github.com/neelance/sourcemap) "$tmp/src/example.org/hello/vendor/github.com/neelance/sourcemap"
37+
cp -r $(go list -e -f '{{.Dir}}' github.com/shurcooL/httpfs) "$tmp/src/example.org/hello/vendor/github.com/shurcooL/httpfs"
38+
cp -r $(go list -e -f '{{.Dir}}' github.com/spf13/cobra) "$tmp/src/example.org/hello/vendor/github.com/spf13/cobra"
39+
cp -r $(go list -e -f '{{.Dir}}' github.com/spf13/pflag) "$tmp/src/example.org/hello/vendor/github.com/spf13/pflag"
40+
cp -r $(go list -e -f '{{.Dir}}' golang.org/x/crypto) "$tmp/src/example.org/hello/vendor/golang.org/x/crypto"
41+
cp -r $(go list -e -f '{{.Dir}}' golang.org/x/sys) "$tmp/src/example.org/hello/vendor/golang.org/x/sys"
42+
cp -r $(go list -e -f '{{.Dir}}' golang.org/x/tools) "$tmp/src/example.org/hello/vendor/golang.org/x/tools"
43+
44+
# Make $tmp our GOPATH workspace.
45+
export GOPATH="$tmp"
46+
47+
# Build the vendored copy of GopherJS.
48+
go install example.org/hello/vendor/github.com/gopherjs/gopherjs
49+
50+
# Use it to build and run the hello command.
51+
(cd "$GOPATH/src/example.org/hello" && "$GOPATH/bin/gopherjs" run main.go)

tests/gorepo_test.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
// +build !js
2-
31
package tests_test
42

53
import (
64
"os"
75
"os/exec"
6+
"runtime"
87
"testing"
98
)
109

1110
// Go repository basic compiler tests, and regression tests for fixed compiler bugs.
1211
func TestGoRepositoryCompilerTests(t *testing.T) {
12+
if runtime.GOARCH == "js" {
13+
t.Skip("test meant to be run using normal Go compiler (needs os/exec)")
14+
}
15+
1316
args := []string{"go", "run", "run.go", "-summary"}
1417
if testing.Verbose() {
1518
args = append(args, "-v")
@@ -22,3 +25,19 @@ func TestGoRepositoryCompilerTests(t *testing.T) {
2225
t.Fatal(err)
2326
}
2427
}
28+
29+
// Test that GopherJS can be vendored into a project, and then used to build Go programs.
30+
// See issue https://github.com/gopherjs/gopherjs/issues/415.
31+
func TestGopherJSCanBeVendored(t *testing.T) {
32+
if runtime.GOARCH == "js" {
33+
t.Skip("test meant to be run using normal Go compiler (needs os/exec)")
34+
}
35+
36+
got, err := exec.Command("bash", "gopherjsvendored_test.sh").Output()
37+
if err != nil {
38+
t.Fatal(err)
39+
}
40+
if want := "hello using js pkg\n"; string(got) != want {
41+
t.Errorf("got != want:\ngot:\n%s\nwant:\n%s", got, want)
42+
}
43+
}

tests/lowlevel_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// +build !js
2-
31
package tests_test
42

53
import (
64
"bytes"
75
"io/ioutil"
86
"os/exec"
97
"path/filepath"
8+
"runtime"
109
"testing"
1110
)
1211

@@ -15,6 +14,10 @@ import (
1514
//
1615
// See https://github.com/gopherjs/gopherjs/issues/279.
1716
func TestTimeInternalizationExternalization(t *testing.T) {
17+
if runtime.GOARCH == "js" {
18+
t.Skip("test meant to be run using normal Go compiler (needs os/exec)")
19+
}
20+
1821
got, err := exec.Command("gopherjs", "run", filepath.Join("testdata", "time_inexternalization.go")).Output()
1922
if err != nil {
2023
t.Fatalf("%v:\n%s", err, got)

0 commit comments

Comments
 (0)