aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornickreid <nickreid@google.com>2023-10-10 17:14:53 -0700
committerCopybara-Service <copybara-worker@google.com>2023-10-10 17:15:29 -0700
commitafa5800fcef85f59509b4f56511c6f29ebaa3ac9 (patch)
treee3774615cdddf5ebf9a851e4545ffcf027fe10b0
parentf7d95308c3abf24e6694635e7d740a7ea96276f7 (diff)
downloadbazelbuild-kotlin-rules-afa5800fcef85f59509b4f56511c6f29ebaa3ac9.tar.gz
Enforce that kt analysis test targets end with _test
PiperOrigin-RevId: 572410637 Change-Id: I570464aefe3a5c8faf553be221823c67e23a209b
-rw-r--r--kotlin/common/testing/analysis.bzl13
-rw-r--r--kotlin/common/testing/testing_rules.bzl3
-rw-r--r--kotlin/jvm/testing/jvm_library_analysis_test.bzl2
-rw-r--r--tests/analysis/jvm_library_test.bzl2
4 files changed, 19 insertions, 1 deletions
diff --git a/kotlin/common/testing/analysis.bzl b/kotlin/common/testing/analysis.bzl
index bd078d7..711bc69 100644
--- a/kotlin/common/testing/analysis.bzl
+++ b/kotlin/common/testing/analysis.bzl
@@ -73,9 +73,22 @@ def _get_arg(action, arg_name, style = "trim"):
else:
fail("Unrecognized arg style '%s" % style)
+def _check_endswith_test(ctx):
+ name = ctx.label.name
+ for i in range(0, 10):
+ # TODO: Remove support for suffix digits
+ if name.endswith(str(i)):
+ name = name.removesuffix(str(i))
+ break
+ if name.endswith("_test"):
+ return
+
+ fail("Analysis test names must end in '_test'")
+
kt_analysis = struct(
# go/keep-sorted start
DEFAULT_LIST = ["__default__"],
+ check_endswith_test = _check_endswith_test,
get_action = _get_action,
get_arg = _get_arg,
# go/keep-sorted end
diff --git a/kotlin/common/testing/testing_rules.bzl b/kotlin/common/testing/testing_rules.bzl
index b86457b..399015d 100644
--- a/kotlin/common/testing/testing_rules.bzl
+++ b/kotlin/common/testing/testing_rules.bzl
@@ -16,6 +16,7 @@
load("//:visibility.bzl", "RULES_KOTLIN")
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
+load(":analysis.bzl", "kt_analysis")
visibility(RULES_KOTLIN)
@@ -51,6 +52,8 @@ _assert_failure_test = analysistest.make(
)
def _assert_failure_test_impl(ctx):
+ kt_analysis.check_endswith_test(ctx)
+
env = analysistest.begin(ctx)
asserts.expect_failure(env, ctx.attr.msg_contains)
return analysistest.end(env)
diff --git a/kotlin/jvm/testing/jvm_library_analysis_test.bzl b/kotlin/jvm/testing/jvm_library_analysis_test.bzl
index 2321042..28dc71d 100644
--- a/kotlin/jvm/testing/jvm_library_analysis_test.bzl
+++ b/kotlin/jvm/testing/jvm_library_analysis_test.bzl
@@ -61,6 +61,8 @@ kt_jvm_library_analysis_test = analysistest.make(
)
def _kt_jvm_library_analysis_test_impl(ctx):
+ kt_analysis.check_endswith_test(ctx)
+
env = analysistest.begin(ctx)
actual = ctx.attr.target_under_test
diff --git a/tests/analysis/jvm_library_test.bzl b/tests/analysis/jvm_library_test.bzl
index e19de2d..e68afd5 100644
--- a/tests/analysis/jvm_library_test.bzl
+++ b/tests/analysis/jvm_library_test.bzl
@@ -479,7 +479,7 @@ def _test_kt_jvm_library_with_no_sources():
return test_name
def _test_kt_jvm_library_with_no_sources_with_exports():
- test_name = "kt_jvm_library_with_no_sources_test_with_exports"
+ test_name = "kt_jvm_library_with_no_sources_with_exports_test"
ktfa.kt_jvm_library(
name = test_name + "_exp",