aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar David Chen <dzc@google.com>2015-07-16 13:23:01 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2015-07-17 13:17:26 +0000
commitdeb003fae0e0da7d45156f5ea0b36900aa9e5790 (patch)
tree4989137a972c6e6e19f4fcb8cebf6085d0745513 /src/test/shell
parent768b5ccdfad99e3ead5bd8c1c861b3f52506f748 (diff)
Add git_repository and new_git_repository workspace rules.
TESTED=Added integration tests. -- MOS_MIGRATED_REVID=98396197
Diffstat (limited to 'src/test/shell')
-rw-r--r--src/test/shell/bazel/BUILD10
-rwxr-xr-xsrc/test/shell/bazel/git_repository_test.sh313
-rw-r--r--src/test/shell/bazel/testdata/BUILD9
-rw-r--r--src/test/shell/bazel/testdata/outer-planets-repo.tar.gzbin0 -> 10744 bytes
-rw-r--r--src/test/shell/bazel/testdata/outer-planets.git_log36
-rw-r--r--src/test/shell/bazel/testdata/pluto-repo.tar.gzbin0 -> 8340 bytes
-rw-r--r--src/test/shell/bazel/testdata/pluto.git_log41
-rwxr-xr-xsrc/test/shell/bazel/testenv.sh3
8 files changed, 412 insertions, 0 deletions
diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD
index 3880ce0258..58a37d8689 100644
--- a/src/test/shell/bazel/BUILD
+++ b/src/test/shell/bazel/BUILD
@@ -95,6 +95,16 @@ sh_test(
)
sh_test(
+ name = "git_repository_test",
+ size = "medium",
+ srcs = ["git_repository_test.sh"],
+ data = [
+ ":test-deps",
+ "//src/test/shell/bazel/testdata:git-repos",
+ ],
+)
+
+sh_test(
name = "local_repository_test",
size = "medium",
srcs = ["local_repository_test.sh"],
diff --git a/src/test/shell/bazel/git_repository_test.sh b/src/test/shell/bazel/git_repository_test.sh
new file mode 100755
index 0000000000..580808c570
--- /dev/null
+++ b/src/test/shell/bazel/git_repository_test.sh
@@ -0,0 +1,313 @@
+#!/bin/bash
+#
+# Copyright 2015 Google Inc. All rights 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.
+#
+# Test git_repository and new_git_repository workspace rules.
+#
+
+# Load test environment
+source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
+ || { echo "test-setup.sh not found!" >&2; exit 1; }
+
+# Global test setup.
+#
+# Unpacks the test Git repositories in the test temporary directory.
+function set_up() {
+ bazel clean --expunge
+ local repos_dir=$TEST_TMPDIR/repos
+ if [ -e "$repos_dir" ]; then
+ rm -rf $repos_dir
+ fi
+
+ mkdir -p $repos_dir
+ cp $testdata_path/pluto-repo.tar.gz $repos_dir
+ cp $testdata_path/outer-planets-repo.tar.gz $repos_dir
+ cd $repos_dir
+ tar zxvf pluto-repo.tar.gz
+ tar zxvf outer-planets-repo.tar.gz
+}
+
+# Test cloning a Git repository using the git_repository rule.
+#
+# This test uses the pluto Git repository at tag 1-build, which contains the
+# following files:
+#
+# pluto/
+# WORKSPACE
+# BUILD
+# info
+#
+# Then, set up workspace with the following files:
+#
+# $WORKSPACE_DIR/
+# WORKSPACE
+# planets/
+# BUILD
+# planet_info.sh
+#
+# //planets has a dependency on a target in the pluto Git repository.
+function test_git_repository() {
+ local pluto_repo_dir=$TEST_TMPDIR/repos/pluto
+ # Commit 85b8224 corresponds to tag 1-build. See testdata/pluto.git_log.
+ local commit_hash="b87de93"
+
+ # Create a workspace that clones the repository at the first commit.
+ cd $WORKSPACE_DIR
+ cat > WORKSPACE <<EOF
+git_repository(
+ name = "pluto",
+ remote = "$pluto_repo_dir",
+ commit = "$commit_hash",
+)
+EOF
+ mkdir -p planets
+ cat > planets/BUILD <<EOF
+sh_binary(
+ name = "planet-info",
+ srcs = ["planet_info.sh"],
+ data = ["@pluto//:pluto"],
+)
+EOF
+
+ cat > planets/planet_info.sh <<EOF
+#!/bin/bash
+cat external/pluto/info
+EOF
+ chmod +x planets/planet_info.sh
+
+ bazel run //planets:planet-info >& $TEST_log \
+ || echo "Expected build/run to succeed"
+ expect_log "Pluto is a dwarf planet"
+}
+
+# Test cloning a Git repository using the new_git_repository rule.
+#
+# This test uses the pluto Git repository at tag 0-initial, which contains the
+# following files:
+#
+# pluto/
+# info
+#
+# Set up workspace with the following files:
+#
+# $WORKSPACE_DIR/
+# WORKSPACE
+# pluto.BUILD
+# planets/
+# BUILD
+# planet_info.sh
+#
+# //planets has a dependency on a target in the $TEST_TMPDIR/pluto Git
+# repository.
+function test_new_git_repository() {
+ local pluto_repo_dir=$TEST_TMPDIR/repos/pluto
+
+ # Create a workspace that clones the repository at the first commit.
+ cd $WORKSPACE_DIR
+ cat > WORKSPACE <<EOF
+new_git_repository(
+ name = "pluto",
+ remote = "$pluto_repo_dir",
+ tag = "0-initial",
+ build_file = "pluto.BUILD",
+)
+EOF
+
+ cat > pluto.BUILD <<EOF
+filegroup(
+ name = "pluto",
+ srcs = ["info"],
+ visibility = ["//visibility:public"],
+)
+EOF
+
+ mkdir -p planets
+ cat > planets/BUILD <<EOF
+sh_binary(
+ name = "planet-info",
+ srcs = ["planet_info.sh"],
+ data = ["@pluto//:pluto"],
+)
+EOF
+
+ cat > planets/planet_info.sh <<EOF
+#!/bin/bash
+cat external/pluto/info
+EOF
+ chmod +x planets/planet_info.sh
+
+ bazel run //planets:planet-info >& $TEST_log \
+ || echo "Expected build/run to succeed"
+ expect_log "Pluto is a planet"
+}
+
+# Test cloning a Git repository that has a submodule using the
+# new_git_repository rule.
+#
+# This test uses the outer-planets Git repository at revision 1-submodule, which
+# contains the following files:
+#
+# outer_planets/
+# neptune/
+# info
+# pluto/ --> submodule ../pluto
+# info
+#
+# Set up workspace with the following files:
+#
+# $WORKSPACE_DIR/
+# WORKSPACE
+# outer_planets.BUILD
+# planets/
+# BUILD
+# planet_info.sh
+#
+# planets has a dependency on targets in the $TEST_TMPDIR/outer_planets Git
+# repository.
+function test_new_git_repository_submodules() {
+ local outer_planets_repo_dir=$TEST_TMPDIR/repos/outer-planets
+
+ # Create a workspace that clones the outer_planets repository.
+ cd $WORKSPACE_DIR
+ cat > WORKSPACE <<EOF
+new_git_repository(
+ name = "outer-planets",
+ remote = "$outer_planets_repo_dir",
+ tag = "1-submodule",
+ init_submodules = 1,
+ build_file = "outer_planets.BUILD",
+)
+EOF
+
+ cat > outer_planets.BUILD <<EOF
+filegroup(
+ name = "neptune",
+ srcs = ["neptune/info"],
+ visibility = ["//visibility:public"],
+)
+
+filegroup(
+ name = "pluto",
+ srcs = ["pluto/info"],
+ visibility = ["//visibility:public"],
+)
+EOF
+
+ mkdir -p planets
+ cat > planets/BUILD <<EOF
+sh_binary(
+ name = "planet-info",
+ srcs = ["planet_info.sh"],
+ data = [
+ "@outer-planets//:neptune",
+ "@outer-planets//:pluto",
+ ],
+)
+EOF
+
+ cat > planets/planet_info.sh <<EOF
+#!/bin/bash
+cat external/outer-planets/neptune/info
+cat external/outer-planets/pluto/info
+EOF
+ chmod +x planets/planet_info.sh
+
+ bazel run //planets:planet-info >& $TEST_log \
+ || echo "Expected build/run to succeed"
+ expect_log "Neptune is a planet"
+ expect_log "Pluto is a planet"
+}
+
+# Helper function for setting up the workspace as follows
+#
+# $WORKSPACE_DIR/
+# WORKSPACE
+# planets/
+# planet_info.sh
+# BUILD
+function setup_error_test() {
+ cd $WORKSPACE_DIR
+ mkdir -p planets
+ cat > planets/planet_info.sh <<EOF
+#!/bin/bash
+cat external/pluto/info
+EOF
+
+ cat > planets/BUILD <<EOF
+sh_binary(
+ name = "planet-info",
+ srcs = ["planet_info.sh"],
+ data = ["@pluto//:pluto"],
+)
+EOF
+}
+
+# Verifies that rule fails if both tag and commit are set.
+#
+# This test uses the pluto Git repository at tag 1-build, which contains the
+# following files:
+#
+# pluto/
+# WORKSPACE
+# BUILD
+# info
+function test_git_repository_both_commit_tag_error() {
+ setup_error_test
+ local pluto_repo_dir=$TEST_TMPDIR/pluto
+ # Commit 85b8224 corresponds to tag 1-build. See testdata/pluto.git_log.
+ local commit_hash="b87de93"
+
+ cd $WORKSPACE_DIR
+ cat > WORKSPACE <<EOF
+git_repository(
+ name = "pluto",
+ remote = "$pluto_repo_dir",
+ tag = "1-build",
+ commit = "$commit_hash",
+)
+EOF
+
+ bazel fetch //planets:planet-info >& $TEST_log \
+ || echo "Expect run to fail."
+ expect_log "One of either commit or tag must be defined"
+}
+
+# Verifies that rule fails if neither tag or commit are set.
+#
+# This test uses the pluto Git repository at tag 1-build, which contains the
+# following files:
+#
+# pluto/
+# WORKSPACE
+# BUILD
+# info
+function test_git_repository_no_commit_tag_error() {
+ setup_error_test
+ local pluto_repo_dir=$TEST_TMPDIR/pluto
+
+ cd $WORKSPACE_DIR
+ cat > WORKSPACE <<EOF
+git_repository(
+ name = "pluto",
+ remote = "$pluto_repo_dir",
+)
+EOF
+
+ bazel fetch //planets:planet-info >& $TEST_log \
+ || echo "Expect run to fail."
+ expect_log "One of either commit or tag must be defined"
+}
+
+run_suite "git_repository tests"
diff --git a/src/test/shell/bazel/testdata/BUILD b/src/test/shell/bazel/testdata/BUILD
new file mode 100644
index 0000000000..291d17a1a5
--- /dev/null
+++ b/src/test/shell/bazel/testdata/BUILD
@@ -0,0 +1,9 @@
+filegroup(
+ name = "git-repos",
+ testonly = 1,
+ srcs = [
+ "outer-planets-repo.tar.gz",
+ "pluto-repo.tar.gz",
+ ],
+ visibility = ["//src/test/shell/bazel:__pkg__"],
+)
diff --git a/src/test/shell/bazel/testdata/outer-planets-repo.tar.gz b/src/test/shell/bazel/testdata/outer-planets-repo.tar.gz
new file mode 100644
index 0000000000..254a63877f
--- /dev/null
+++ b/src/test/shell/bazel/testdata/outer-planets-repo.tar.gz
Binary files differ
diff --git a/src/test/shell/bazel/testdata/outer-planets.git_log b/src/test/shell/bazel/testdata/outer-planets.git_log
new file mode 100644
index 0000000000..fc26500343
--- /dev/null
+++ b/src/test/shell/bazel/testdata/outer-planets.git_log
@@ -0,0 +1,36 @@
+commit c6ffd1361759036836186f06078af8ebc297bf39 (HEAD -> master, tag: 1-submodule)
+Author: John Doe <john@foo.com>
+Date: Thu Jul 16 04:53:18 2015 -0700
+
+ Add pluto submodule.
+
+diff --git a/.gitmodules b/.gitmodules
+new file mode 100644
+index 0000000..1d2f9b1
+--- /dev/null
++++ b/.gitmodules
+@@ -0,0 +1,3 @@
++[submodule "pluto"]
++ path = pluto
++ url = ../pluto
+diff --git a/pluto b/pluto
+new file mode 160000
+index 0000000..36db6be
+--- /dev/null
++++ b/pluto
+@@ -0,0 +1 @@
++Subproject commit 36db6be50fd9f33cf89fc5b8206f2e3714b520e3
+
+commit eaf1b34982ead69228b6f3f894a0a34c59c07f17 (tag: 0-initial)
+Author: John Doe <john@foo.com>
+Date: Thu Jul 16 04:52:23 2015 -0700
+
+ Initial commit.
+
+diff --git a/neptune/info b/neptune/info
+new file mode 100644
+index 0000000..41cf7b5
+--- /dev/null
++++ b/neptune/info
+@@ -0,0 +1 @@
++Neptune is a planet
diff --git a/src/test/shell/bazel/testdata/pluto-repo.tar.gz b/src/test/shell/bazel/testdata/pluto-repo.tar.gz
new file mode 100644
index 0000000000..a347a37312
--- /dev/null
+++ b/src/test/shell/bazel/testdata/pluto-repo.tar.gz
Binary files differ
diff --git a/src/test/shell/bazel/testdata/pluto.git_log b/src/test/shell/bazel/testdata/pluto.git_log
new file mode 100644
index 0000000000..fb98d77cb0
--- /dev/null
+++ b/src/test/shell/bazel/testdata/pluto.git_log
@@ -0,0 +1,41 @@
+commit b87de9346bb1a4a3d4d2ab1a567b07c5d11a486a (HEAD -> master, tag: 1-build)
+Author: John Doe <john@foo.com>
+Date: Thu Jul 16 04:50:53 2015 -0700
+
+ Add WORKSPACE and BUILD file. Update info because Pluto is no longer a planet.
+
+diff --git a/BUILD b/BUILD
+new file mode 100644
+index 0000000..874e03f
+--- /dev/null
++++ b/BUILD
+@@ -0,0 +1,5 @@
++filegroup(
++ name = "pluto",
++ srcs = ["info"],
++ visibility = ["//visibility:public"],
++)
+diff --git a/WORKSPACE b/WORKSPACE
+new file mode 100644
+index 0000000..e69de29
+diff --git a/info b/info
+index 8f442be..36cbae4 100644
+--- a/info
++++ b/info
+@@ -1 +1 @@
+-Pluto is a planet
++Pluto is a dwarf planet
+
+commit 36db6be50fd9f33cf89fc5b8206f2e3714b520e3 (tag: 0-initial)
+Author: John Doe <john@foo.com>
+Date: Thu Jul 16 04:49:35 2015 -0700
+
+ Initial commit.
+
+diff --git a/info b/info
+new file mode 100644
+index 0000000..8f442be
+--- /dev/null
++++ b/info
+@@ -0,0 +1 @@
++Pluto is a planet
diff --git a/src/test/shell/bazel/testenv.sh b/src/test/shell/bazel/testenv.sh
index 44d15f35c0..dc0a5c3c6b 100755
--- a/src/test/shell/bazel/testenv.sh
+++ b/src/test/shell/bazel/testenv.sh
@@ -44,6 +44,9 @@ singlejar_path="${TEST_SRCDIR}/src/java_tools/singlejar/SingleJar_deploy.jar"
genclass_path="${TEST_SRCDIR}/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass_deploy.jar"
ijar_path="${TEST_SRCDIR}/third_party/ijar/ijar"
+# Test data
+testdata_path=${TEST_SRCDIR}/src/test/shell/bazel/testdata
+
# Third-party
PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
MACHINE_TYPE="$(uname -m)"