aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLászló Csomor <laszlocsomor@users.noreply.github.com>2019-03-20 07:48:42 +0100
committerGitHub <noreply@github.com>2019-03-20 07:48:42 +0100
commitbdbedc18326673cca7b0ceab1b88719a35be3030 (patch)
treea2e157db3391a549e86cd7ba9374d3eef9b9012b /tests
parentb2dc5c0e63efdcfaddc0b4a4ecd8b0f8bea07978 (diff)
downloadbazel-skylib-bdbedc18326673cca7b0ceab1b88719a35be3030.tar.gz
maprule: add basic integration test (#131)
Diffstat (limited to 'tests')
-rw-r--r--tests/maprule/BUILD47
-rw-r--r--tests/maprule/b/bar.txt1
-rw-r--r--tests/maprule/common.txt1
-rw-r--r--tests/maprule/foo.txt1
-rwxr-xr-xtests/maprule/maprule_tests.sh61
-rwxr-xr-xtests/maprule/mr_bash_tool.sh20
6 files changed, 131 insertions, 0 deletions
diff --git a/tests/maprule/BUILD b/tests/maprule/BUILD
new file mode 100644
index 0000000..d33039e
--- /dev/null
+++ b/tests/maprule/BUILD
@@ -0,0 +1,47 @@
+# This package aids testing the 'maprule' rule.
+
+load("//rules:maprule.bzl", "bash_maprule")
+
+package(default_testonly = 1)
+
+sh_test(
+ name = "maprule_tests",
+ srcs = ["maprule_tests.sh"],
+ data = [
+ # Use DefaultInfo.files from 'mr_bash' (via 'file_deps').
+ ":file_deps",
+ "//tests:unittest.bash",
+ ],
+ deps = ["@bazel_tools//tools/bash/runfiles"],
+)
+
+filegroup(
+ name = "file_deps",
+ # Use DefaultInfo.files from 'mr_bash'.
+ srcs = [":mr_bash"],
+)
+
+bash_maprule(
+ name = "mr_bash",
+ srcs = ["common.txt"],
+ add_env = {
+ "TOOL": "$(location :mr_bash_tool)",
+ },
+ # TODO(laszlocsomor): add quotes around $MAPRULE_TOOL after
+ # https://github.com/bazelbuild/bazel/issues/7454 is fixed.
+ cmd = "$MAPRULE_TOOL",
+ foreach_srcs = [
+ "foo.txt",
+ "b/bar.txt",
+ ],
+ outs_templates = {
+ "OUT1": "{src}.out1",
+ "OUT2": "out2/{src_name_noext}",
+ },
+ tools = [":mr_bash_tool"],
+)
+
+sh_binary(
+ name = "mr_bash_tool",
+ srcs = ["mr_bash_tool.sh"],
+)
diff --git a/tests/maprule/b/bar.txt b/tests/maprule/b/bar.txt
new file mode 100644
index 0000000..24ec369
--- /dev/null
+++ b/tests/maprule/b/bar.txt
@@ -0,0 +1 @@
+bar file
diff --git a/tests/maprule/common.txt b/tests/maprule/common.txt
new file mode 100644
index 0000000..b9e06a5
--- /dev/null
+++ b/tests/maprule/common.txt
@@ -0,0 +1 @@
+common file
diff --git a/tests/maprule/foo.txt b/tests/maprule/foo.txt
new file mode 100644
index 0000000..3f9a7b1
--- /dev/null
+++ b/tests/maprule/foo.txt
@@ -0,0 +1 @@
+foo file
diff --git a/tests/maprule/maprule_tests.sh b/tests/maprule/maprule_tests.sh
new file mode 100755
index 0000000..660021b
--- /dev/null
+++ b/tests/maprule/maprule_tests.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+# Copyright 2019 The Bazel Authors. 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.
+
+# --- begin runfiles.bash initialization ---
+set -euo pipefail
+if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
+ if [[ -f "$0.runfiles_manifest" ]]; then
+ export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
+ elif [[ -f "$0.runfiles/MANIFEST" ]]; then
+ export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
+ elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
+ export RUNFILES_DIR="$0.runfiles"
+ fi
+fi
+if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
+ source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
+elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
+ source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
+ "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
+else
+ echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
+ exit 1
+fi
+# --- end runfiles.bash initialization ---
+
+source "$(rlocation bazel_skylib/tests/unittest.bash)" \
+ || { echo "Could not source bazel_skylib/tests/unittest.bash" >&2; exit 1; }
+
+function test_bash_maprule() {
+ local -r out1foo="$(rlocation bazel_skylib/tests/maprule/mr_bash_out/tests/maprule/foo.txt.out1)"
+ local -r out1bar="$(rlocation bazel_skylib/tests/maprule/mr_bash_out/tests/maprule/b/bar.txt.out1)"
+ local -r out2foo="$(rlocation bazel_skylib/tests/maprule/mr_bash_out/out2/foo)"
+ local -r out2bar="$(rlocation bazel_skylib/tests/maprule/mr_bash_out/out2/bar)"
+
+ cat "$out1foo" | tr '\n\r' ' ' > "$TEST_log"
+ expect_log "^tests/maprule/common.txt *tests/maprule/foo.txt *$"
+
+ cat "$out1bar" | tr '\n\r' ' ' > "$TEST_log"
+ expect_log "^tests/maprule/common.txt *tests/maprule/b/bar.txt *$"
+
+ cat "$out2foo" | tr '\n\r' ' ' > "$TEST_log"
+ expect_log "^common file *foo file *$"
+
+ cat "$out2bar" | tr '\n\r' ' ' > "$TEST_log"
+ expect_log "^common file *bar file *$"
+}
+
+run_suite "maprule test suite"
diff --git a/tests/maprule/mr_bash_tool.sh b/tests/maprule/mr_bash_tool.sh
new file mode 100755
index 0000000..843eb63
--- /dev/null
+++ b/tests/maprule/mr_bash_tool.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright 2019 The Bazel Authors. 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.
+
+set -euo pipefail
+
+echo "$MAPRULE_SRCS" "$MAPRULE_SRC" > "$MAPRULE_OUT1"
+cat "$MAPRULE_SRCS" "$MAPRULE_SRC" > "$MAPRULE_OUT2"