aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Han-Wen Nienhuys <hanwen@google.com>2015-10-20 13:20:21 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2015-10-20 16:38:15 +0000
commitc68e3b34e0724a2c756ec9786dc22ec98dc261c5 (patch)
tree0db00a3ff53e1e2b4d27710aae0b9aa0435dd767 /src
parent3f032c9902d718618bb2121a8c5811e6f2647c4c (diff)
Add e2e test for Go support.
-- Change-Id: I6b76e1fe76ae8a640b2ab7d70cc8bfda50801b74 Reviewed-on: https://bazel-review.googlesource.com/#/c/2160 MOS_MIGRATED_REVID=105854761
Diffstat (limited to 'src')
-rw-r--r--src/test/shell/bazel/BUILD11
-rwxr-xr-xsrc/test/shell/bazel/bazel_go_example_test.sh85
2 files changed, 96 insertions, 0 deletions
diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD
index 52a7543c36..85df323cd0 100644
--- a/src/test/shell/bazel/BUILD
+++ b/src/test/shell/bazel/BUILD
@@ -81,6 +81,17 @@ sh_test(
)
sh_test(
+ name = "bazel_go_example_test",
+ srcs = ["bazel_go_example_test.sh"],
+ data = [
+ ":test-deps",
+ "//tools/build_rules/go:srcs",
+ "//tools/build_rules/go/toolchain:srcs",
+ "//tools/build_rules/go/tools:srcs",
+ ],
+)
+
+sh_test(
name = "bazel_rules_test",
srcs = ["bazel_rules_test.sh"],
data = [":test-deps"],
diff --git a/src/test/shell/bazel/bazel_go_example_test.sh b/src/test/shell/bazel/bazel_go_example_test.sh
new file mode 100755
index 0000000000..fd64246a26
--- /dev/null
+++ b/src/test/shell/bazel/bazel_go_example_test.sh
@@ -0,0 +1,85 @@
+#!/bin/bash
+#
+# Copyright 2015 The Bazel Authors. All arights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Tests the examples provided in Bazel
+#
+
+# Load test environment
+source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
+ || { echo "test-setup.sh not found!" >&2; exit 1; }
+
+function set_up() {
+ copy_examples
+
+ cat <<EOF > WORKSPACE
+bind(name = "go_prefix",
+ actual = "//:go_prefix",
+)
+
+EOF
+
+ # avoid trying to download the SDK from within the test.
+ rm -rf tools/build_rules/go/toolchain
+ for p in golang-linux-amd64 golang-darwin-amd64 ; do
+ d=$TEST_SRCDIR/external/${p}
+ for f in $(cd ${d}; find -L . -type f -print ) ; do
+ mkdir -p tools/build_rules/go/toolchain/$(dirname $f)
+ ln -s ${d}/$f tools/build_rules/go/toolchain/$f
+ done
+ done
+ ln -s $TEST_SRCDIR/tools/build_rules/go/toolchain/BUILD.go-toolchain tools/build_rules/go/toolchain/BUILD
+ cat <<EOF > BUILD
+load("/tools/build_rules/go/def", "go_prefix")
+go_prefix("prefix")
+EOF
+
+}
+
+function test_basic() {
+ mkdir -p ex/
+ cat <<EOF > ex/m.go
+package main
+import (
+ "fmt"
+
+ "prefix/ex"
+)
+func main() {
+ fmt.Println("F", ex.F())
+}
+
+EOF
+ cat <<EOF > ex/l.go
+package ex
+func F() int { return 42 }
+EOF
+
+ cat <<EOF > ex/BUILD
+load("/tools/build_rules/go/def", "go_library", "go_binary")
+go_library(name = "go_default_library",
+ srcs = [ "l.go"])
+go_binary(name = "m",
+ srcs = [ "m.go" ],
+ deps = [ ":go_default_library" ])
+EOF
+
+ assert_build //ex:m
+ test -x ./bazel-bin/ex/m || fail "binary not found"
+ (./bazel-bin/ex/m > out) || fail "binary does not execute"
+ grep "F 42" out || fail "binary output suspect"
+}
+
+run_suite "go_examples"