Skip to content

Commit db9da5d

Browse files
committed
refactor: Migrate transitive strict-deps build-failure tests to Bazel
Move the transitive/{scala_to_scala,java_to_scala,scala_to_java} fixtures from test_expect_failure into test/transitive, driven by expect_build_failure_test instead of the test_transitive_deps case in test/shell/test_misc.sh. Each `:d` target uses a type reachable only transitively, so strict deps must reject the build; the java_to_scala case additionally asserts the "indirect dependency" error message.
1 parent b8e902b commit db9da5d

15 files changed

Lines changed: 96 additions & 94 deletions

File tree

test/shell/test_misc.sh

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,6 @@ test_disappearing_class() {
2323
set -e
2424
}
2525

26-
test_transitive_deps() {
27-
set +e
28-
29-
bazel build test_expect_failure/transitive/scala_to_scala:d
30-
if [ $? -eq 0 ]; then
31-
echo "'bazel build test_expect_failure/transitive/scala_to_scala:d' should have failed."
32-
exit 1
33-
fi
34-
35-
expected_message="error: [strict] Using type example.A from an indirect dependency"
36-
output=$(bazel build test_expect_failure/transitive/java_to_scala:d 2>&1)
37-
if [ $? -eq 0 ] || [[ "$output" != *"$expected_message"* ]]; then
38-
echo "'bazel build test_expect_failure/transitive/java_to_scala:d' should have failed with message '$expected_message'."
39-
exit 1
40-
fi
41-
42-
bazel build test_expect_failure/transitive/scala_to_java:d
43-
if [ $? -eq 0 ]; then
44-
echo "'bazel build test_transitive_deps/scala_to_java:d' should have failed."
45-
exit 1
46-
fi
47-
48-
set -e
49-
exit 0
50-
}
51-
5226
test_repl() {
5327
local query_results=$(bazel query 'kind(scala_repl, //test/...)')
5428
#local query_results="${query_results//$'\r'}" #make sure \r is removed so bash can parse args correctly on windows
@@ -118,7 +92,6 @@ xmllint_test() {
11892
}
11993

12094
$runner test_disappearing_class
121-
$runner test_transitive_deps
12295
$runner test_repl
12396
$runner test_benchmark_jmh
12497
$runner scala_test_test_filters
File renamed without changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
load("@rules_java//java:defs.bzl", "java_library")
2+
load("//scala:scala.bzl", "scala_library")
3+
load("//test/expect_build_failure:expect_build_failure.bzl", "expect_build_failure_test")
4+
5+
scala_library(
6+
name = "a",
7+
srcs = ["A.scala"],
8+
)
9+
10+
java_library(
11+
name = "c",
12+
srcs = ["C.java"],
13+
deps = [":a"],
14+
)
15+
16+
# `d` uses a Scala type reachable only transitively (through `c`); strict deps
17+
# must reject building it with the "indirect dependency" error. Tagged "manual"
18+
# so wildcard builds skip it; the sh_test drives a nested `bazel build`.
19+
java_library(
20+
name = "d",
21+
srcs = ["D.java"],
22+
tags = ["manual"],
23+
deps = [":c"],
24+
)
25+
26+
expect_build_failure_test(
27+
name = "transitive_java_to_scala_build_test",
28+
expect = ["expected_indirect_dependency.txt"],
29+
target = ":d",
30+
)
File renamed without changes.
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error: [strict] Using type example.A from an indirect dependency
File renamed without changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
load("@rules_java//java:defs.bzl", "java_library")
2+
load("//scala:scala.bzl", "scala_library")
3+
load("//test/expect_build_failure:expect_build_failure.bzl", "expect_build_failure_test")
4+
5+
java_library(
6+
name = "a",
7+
srcs = ["A.java"],
8+
)
9+
10+
scala_library(
11+
name = "b",
12+
exports = [":a"],
13+
)
14+
15+
scala_library(
16+
name = "c",
17+
deps = [":b"],
18+
)
19+
20+
# `d` uses a Java type reachable only transitively (through `c` -> `b` ->
21+
# exported `a`); strict deps must reject building it. Tagged "manual" so wildcard
22+
# builds skip it; the sh_test drives a nested `bazel build` and asserts the failure.
23+
scala_library(
24+
name = "d",
25+
srcs = ["D.scala"],
26+
tags = ["manual"],
27+
deps = [":c"],
28+
)
29+
30+
expect_build_failure_test(
31+
name = "transitive_scala_to_java_build_test",
32+
target = ":d",
33+
)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)