Skip to content

Commit

Permalink
Implement support for test_suffixes_excludes (#218)
Browse files Browse the repository at this point in the history
Fixes #215
  • Loading branch information
guw authored Nov 15, 2023
1 parent 3d8dc43 commit 74a79f5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ bazel-*
.bazelrc.user
.idea
.ijwb

.eclipse
/comparative-tests/.gradle/
11 changes: 8 additions & 3 deletions java/private/create_jvm_test_suite.bzl
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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`.
Expand All @@ -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`.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 74a79f5

Please sign in to comment.