Skip to content
Open
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
5 changes: 3 additions & 2 deletions java/private/create_jvm_test_suite.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def create_jvm_test_suite(
)
if not _contains_label(deps or [], lib_dep_label):
deps = deps + [lib_dep_label]
if "resources" in library_attrs:
# Prevent duplicate resources from appearing in classpath
kwargs.pop("resources")

tests = []

Expand All @@ -100,7 +103,6 @@ def create_jvm_test_suite(
visibility = ["//visibility:private"],
tags = tags,
testonly = True,
**library_attrs
)
runtime_deps_lib_name = "%s-test-runtime-deps-lib" % name
define_library(
Expand All @@ -109,7 +111,6 @@ def create_jvm_test_suite(
visibility = ["//visibility:private"],
tags = tags,
testonly = True,
**library_attrs
)

# Get any deps referenced in make vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ java_test_suite(
),
exclude_engines = ["junit-vintage"],
include_engines = ["junit-jupiter"],
resources = glob(["resources/*"]),
runner = "junit5",
test_suffixes_excludes = ["BaseTest.java"],
deps = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.github.bazel_contrib.contrib_rules_jvm.junit5;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipFile;
import org.junit.jupiter.api.Test;

public class JavaTestSuiteTest {

@Test
public void testClasspathDoesNotContainDuplicateResources() throws IOException {
final String resourceName = "duplicate_resource_test.txt";
String[] classpath = System.getProperty("java.class.path").split(":");
List<String> resourcesFound = new ArrayList<>();
for (String entry : classpath) {
if (entry.endsWith(".jar")) {
try (ZipFile zipfile = new ZipFile(new File(entry))) {
zipfile
.entries()
.asIterator()
.forEachRemaining(
zipEntry -> {
if (zipEntry.getName().endsWith(resourceName)) {
resourcesFound.add(entry);
}
});
}
} else {
fail("Classpath contains non-jar files");
}
}
assertEquals(
1,
resourcesFound.size(),
"Expected a single instance of a resource to be on the classpath, instead found entries in:"
+ " "
+ resourcesFound);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simple resource to validate suites only pick up a single resource
Loading