Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for test_suffixes_excludes #218

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading