From 74a79f56e8a6d968381c3cbee5ed7740e33683a7 Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Wed, 15 Nov 2023 15:20:52 +0100 Subject: [PATCH] Implement support for `test_suffixes_excludes` (#218) Fixes #215 --- .gitignore | 2 +- java/private/create_jvm_test_suite.bzl | 11 ++++++++--- .../contrib_rules_jvm/junit5/BUILD.bazel | 1 + .../contrib_rules_jvm/junit5/ExcludedBaseTest.java | 13 +++++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/ExcludedBaseTest.java diff --git a/.gitignore b/.gitignore index b4037f1b..5c318f1f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ bazel-* .bazelrc.user .idea .ijwb - +.eclipse /comparative-tests/.gradle/ diff --git a/java/private/create_jvm_test_suite.bzl b/java/private/create_jvm_test_suite.bzl index 04511590..c86a6609 100644 --- a/java/private/create_jvm_test_suite.bzl +++ b/java/private/create_jvm_test_suite.bzl @@ -1,8 +1,11 @@ load("//java/private:package.bzl", "get_class_name") -def _is_test(src, test_suffixes): +def _is_test(src, test_suffixes, test_suffixes_excludes): for suffix in test_suffixes: if src.endswith(suffix): + for suffix_exclude in test_suffixes_excludes: + if src.endswith(suffix_exclude): + return False return True return False @@ -35,6 +38,7 @@ def create_jvm_test_suite( visibility = None, size = None, package_prefixes = [], + test_suffixes_excludes = [], **kwargs): """Generate a test suite for rules that "feel" like `java_test`. @@ -53,6 +57,7 @@ def create_jvm_test_suite( name: The name of the generated test suite. srcs: A list of source files. test_suffixes: A list of suffixes (eg. `["Test.kt"]`) + test_suffixes_excludes: A list of suffix excludes (eg. `["BaseTest.kt"]`) package: The package name to use. If `None`, a value will be calculated from the bazel package. library_attributes: Attributes to pass to `define_library`. @@ -72,8 +77,8 @@ def create_jvm_test_suite( # First, grab any interesting attrs library_attrs = {attr: kwargs[attr] for attr in library_attributes if attr in kwargs} - test_srcs = [src for src in srcs if _is_test(src, test_suffixes)] - nontest_srcs = [src for src in srcs if not _is_test(src, test_suffixes)] + test_srcs = [src for src in srcs if _is_test(src, test_suffixes, test_suffixes_excludes)] + nontest_srcs = [src for src in srcs if not _is_test(src, test_suffixes, test_suffixes_excludes)] if nontest_srcs: lib_dep_name = "%s-test-lib" % name diff --git a/java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/BUILD.bazel b/java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/BUILD.bazel index f63aa155..c7777284 100644 --- a/java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/BUILD.bazel +++ b/java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/BUILD.bazel @@ -29,6 +29,7 @@ java_test_suite( ), exclude_engines = ["junit-vintage"], include_engines = ["junit-jupiter"], + test_suffixes_excludes = ["BaseTest.java"], runner = "junit5", deps = [ "//java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5", diff --git a/java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/ExcludedBaseTest.java b/java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/ExcludedBaseTest.java new file mode 100644 index 00000000..ff78ecb6 --- /dev/null +++ b/java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/ExcludedBaseTest.java @@ -0,0 +1,13 @@ +package com.github.bazel_contrib.contrib_rules_jvm.junit5; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +public abstract class ExcludedBaseTest { + + @Test + public void defaultTestForOtherTests() { + assertTrue(false); + } +}