maprule: add basic integration test (#131)
This commit is contained in:
parent
b2dc5c0e63
commit
bdbedc1832
|
@ -454,12 +454,15 @@ def _maprule_main(ctx, strategy):
|
||||||
inputs = depset(direct = [src], transitive = [common_srcs, inputs_from_tools]),
|
inputs = depset(direct = [src], transitive = [common_srcs, inputs_from_tools]),
|
||||||
outputs = foreach_src_outs_dicts[src].values(),
|
outputs = foreach_src_outs_dicts[src].values(),
|
||||||
# The custom envmap contains envvars specific to the current "src", such as MAPRULE_SRC.
|
# The custom envmap contains envvars specific to the current "src", such as MAPRULE_SRC.
|
||||||
env = common_envmap + _custom_envmap(
|
env = dicts.add(
|
||||||
ctx,
|
common_envmap,
|
||||||
strategy,
|
_custom_envmap(
|
||||||
src_placeholders_dicts[src],
|
ctx,
|
||||||
foreach_src_outs_dicts[src],
|
strategy,
|
||||||
add_env,
|
src_placeholders_dicts[src],
|
||||||
|
foreach_src_outs_dicts[src],
|
||||||
|
add_env,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
command = ctx.attr.cmd,
|
command = ctx.attr.cmd,
|
||||||
progress_message = progress_message,
|
progress_message = progress_message,
|
||||||
|
|
|
@ -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"],
|
||||||
|
)
|
|
@ -0,0 +1 @@
|
||||||
|
bar file
|
|
@ -0,0 +1 @@
|
||||||
|
common file
|
|
@ -0,0 +1 @@
|
||||||
|
foo file
|
|
@ -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"
|
|
@ -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"
|
Loading…
Reference in New Issue