Fix diff_test when filepath includes external (#241)
Resolves https://github.com/bazelbuild/bazel-skylib/issues/240.
This commit is contained in:
parent
9935e0f820
commit
feb52960eb
|
@ -79,8 +79,8 @@ if %ERRORLEVEL% neq 0 (
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
F1="{file1}"
|
F1="{file1}"
|
||||||
F2="{file2}"
|
F2="{file2}"
|
||||||
[[ "$F1" =~ external/* ]] && F1="${{F1#external/}}" || F1="$TEST_WORKSPACE/$F1"
|
[[ "$F1" =~ ^external/* ]] && F1="${{F1#external/}}" || F1="$TEST_WORKSPACE/$F1"
|
||||||
[[ "$F2" =~ external/* ]] && F2="${{F2#external/}}" || F2="$TEST_WORKSPACE/$F2"
|
[[ "$F2" =~ ^external/* ]] && F2="${{F2#external/}}" || F2="$TEST_WORKSPACE/$F2"
|
||||||
if [[ -d "${{RUNFILES_DIR:-/dev/null}}" && "${{RUNFILES_MANIFEST_ONLY:-}}" != 1 ]]; then
|
if [[ -d "${{RUNFILES_DIR:-/dev/null}}" && "${{RUNFILES_MANIFEST_ONLY:-}}" != 1 ]]; then
|
||||||
RF1="$RUNFILES_DIR/$F1"
|
RF1="$RUNFILES_DIR/$F1"
|
||||||
RF2="$RUNFILES_DIR/$F2"
|
RF2="$RUNFILES_DIR/$F2"
|
||||||
|
|
|
@ -50,10 +50,12 @@ function import_diff_test() {
|
||||||
function assert_simple_diff_test() {
|
function assert_simple_diff_test() {
|
||||||
local -r flag="$1"
|
local -r flag="$1"
|
||||||
local -r ws="${TEST_TMPDIR}/$2"
|
local -r ws="${TEST_TMPDIR}/$2"
|
||||||
|
local -r subdir="$3"
|
||||||
|
|
||||||
import_diff_test "$ws"
|
import_diff_test "$ws"
|
||||||
touch "$ws/WORKSPACE"
|
touch "$ws/WORKSPACE"
|
||||||
cat >"$ws/BUILD" <<'eof'
|
mkdir -p "$ws/$subdir"
|
||||||
|
cat >"$ws/${subdir}BUILD" <<'eof'
|
||||||
load("//rules:diff_test.bzl", "diff_test")
|
load("//rules:diff_test.bzl", "diff_test")
|
||||||
|
|
||||||
diff_test(
|
diff_test(
|
||||||
|
@ -68,17 +70,17 @@ diff_test(
|
||||||
file2 = "b.txt",
|
file2 = "b.txt",
|
||||||
)
|
)
|
||||||
eof
|
eof
|
||||||
echo foo > "$ws/a.txt"
|
echo foo > "$ws/$subdir/a.txt"
|
||||||
echo bar > "$ws/b.txt"
|
echo bar > "$ws/$subdir/b.txt"
|
||||||
|
|
||||||
(cd "$ws" && \
|
(cd "$ws" && \
|
||||||
bazel test "$flag" //:same --test_output=errors 1>"$TEST_log" 2>&1 \
|
bazel test "$flag" "//${subdir%/}:same" --test_output=errors 1>"$TEST_log" 2>&1 \
|
||||||
|| fail "expected success")
|
|| fail "expected success")
|
||||||
|
|
||||||
(cd "$ws" && \
|
(cd "$ws" && \
|
||||||
bazel test "$flag" //:different --test_output=errors 1>"$TEST_log" 2>&1 \
|
bazel test "$flag" "//${subdir%/}:different" --test_output=errors 1>"$TEST_log" 2>&1 \
|
||||||
&& fail "expected failure" || true)
|
&& fail "expected failure" || true)
|
||||||
expect_log 'FAIL: files "a.txt" and "b.txt" differ'
|
expect_log "FAIL: files \"${subdir}a.txt\" and \"${subdir}b.txt\" differ"
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_from_ext_repo() {
|
function assert_from_ext_repo() {
|
||||||
|
@ -187,11 +189,19 @@ eof
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_simple_diff_test_with_legacy_external_runfiles() {
|
function test_simple_diff_test_with_legacy_external_runfiles() {
|
||||||
assert_simple_diff_test "--legacy_external_runfiles" "${FUNCNAME[0]}"
|
assert_simple_diff_test "--legacy_external_runfiles" "${FUNCNAME[0]}" ""
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_simple_diff_test_without_legacy_external_runfiles() {
|
function test_simple_diff_test_without_legacy_external_runfiles() {
|
||||||
assert_simple_diff_test "--nolegacy_external_runfiles" "${FUNCNAME[0]}"
|
assert_simple_diff_test "--nolegacy_external_runfiles" "${FUNCNAME[0]}" ""
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_directory_named_external_with_legacy_external_runfiles() {
|
||||||
|
assert_simple_diff_test "--legacy_external_runfiles" "${FUNCNAME[0]}" "path/to/direcotry/external/in/name/"
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_directory_named_external_without_legacy_external_runfiles() {
|
||||||
|
assert_simple_diff_test "--nolegacy_external_runfiles" "${FUNCNAME[0]}" "path/to/direcotry/external/in/name/"
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_from_ext_repo_with_legacy_external_runfiles() {
|
function test_from_ext_repo_with_legacy_external_runfiles() {
|
||||||
|
|
Loading…
Reference in New Issue