Skip to content

Commit

Permalink
[testing] Revert to JUnit4. (#1145)
Browse files Browse the repository at this point in the history
* Revert "Remove leading . from package inference (#1142)"

This reverts commit 10452e1.

* Revert "[testing] Switch to junit5 (#1128)"

This reverts commit 60e1636.
  • Loading branch information
restingbull authored Mar 24, 2024
1 parent 3a3bb0c commit 80dd277
Show file tree
Hide file tree
Showing 38 changed files with 67 additions and 371 deletions.
35 changes: 15 additions & 20 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,29 @@ maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
name = "kotlin_rules_maven",
artifacts = [
"org.junit.jupiter:junit-jupiter-api:5.4.2",
"org.junit.jupiter:junit-jupiter-engine:5.4.2",
"org.junit.jupiter:junit-jupiter-params:5.4.2",
"org.junit.platform:junit-platform-console:1.4.2",
"com.google.auto.service:auto-service-annotations:1.0.1",
"com.google.auto.service:auto-service-annotations:jar:1.1.1",
"com.google.code.findbugs:jsr305:3.0.2",
"junit:junit:4.13-beta-3",
"com.google.protobuf:protobuf-java:3.6.0",
"com.google.protobuf:protobuf-java-util:3.6.0",
"com.google.guava:guava:27.1-jre",
"com.google.truth:truth:0.45",
"com.google.auto.service:auto-service:1.0.1",
"com.google.auto.value:auto-value-annotations:1.10.1",
"com.google.auto.service:auto-service-annotations:1.0.1",
"com.google.auto.value:auto-value:1.10.1",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.auto.value:auto-value-annotations:1.10.1",
"com.google.dagger:dagger:2.43.2",
"com.google.dagger:dagger-compiler:2.43.2",
"com.google.dagger:dagger-producers:2.43.2",
"com.google.dagger:dagger:2.43.2",
"com.google.guava:guava:27.1-jre",
"com.google.protobuf:protobuf-java-util:3.6.0",
"com.google.protobuf:protobuf-java:3.6.0",
"com.google.truth:truth:0.45",
"com.squareup.moshi:moshi-kotlin-codegen:1.15.0",
"com.squareup.moshi:moshi-kotlin:1.15.0",
"com.squareup.moshi:moshi:1.15.0",
"commons-lang:commons-lang:2.6",
"dev.zacsweers.autoservice:auto-service-ksp:jar:1.1.0",
"javax.annotation:javax.annotation-api:1.3.2",
"javax.inject:javax.inject:1",
"junit:junit:4.13-beta-3",
"org.pantsbuild:jarjar:1.7.2",
"org.jetbrains.kotlinx:atomicfu-js:0.15.2",
"org.jetbrains.kotlinx:kotlinx-serialization-runtime:1.0-M1-1.4.0-rc",
"org.pantsbuild:jarjar:1.7.2",
"dev.zacsweers.autoservice:auto-service-ksp:jar:1.1.0",
"com.squareup.moshi:moshi:1.15.0",
"com.squareup.moshi:moshi-kotlin:1.15.0",
"com.squareup.moshi:moshi-kotlin-codegen:1.15.0",
"com.google.auto.service:auto-service-annotations:jar:1.1.1",
],
fail_if_repin_required = True,
fetch_sources = True,
Expand Down
3 changes: 1 addition & 2 deletions docs/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ kt_jvm_library(<a href="#kt_jvm_library-name">name</a>, <a href="#kt_jvm_library

kt_jvm_test(<a href="#kt_jvm_test-name">name</a>, <a href="#kt_jvm_test-associates">associates</a>, <a href="#kt_jvm_test-data">data</a>, <a href="#kt_jvm_test-deps">deps</a>, <a href="#kt_jvm_test-env">env</a>, <a href="#kt_jvm_test-javac_opts">javac_opts</a>, <a href="#kt_jvm_test-jvm_flags">jvm_flags</a>, <a href="#kt_jvm_test-kotlinc_opts">kotlinc_opts</a>, <a href="#kt_jvm_test-main_class">main_class</a>,
<a href="#kt_jvm_test-module_name">module_name</a>, <a href="#kt_jvm_test-plugins">plugins</a>, <a href="#kt_jvm_test-resource_jars">resource_jars</a>, <a href="#kt_jvm_test-resource_strip_prefix">resource_strip_prefix</a>, <a href="#kt_jvm_test-resources">resources</a>, <a href="#kt_jvm_test-runtime_deps">runtime_deps</a>, <a href="#kt_jvm_test-srcs">srcs</a>,
<a href="#kt_jvm_test-test_class">test_class</a>, <a href="#kt_jvm_test-use_testrunner">use_testrunner</a>)
<a href="#kt_jvm_test-test_class">test_class</a>)

Setup a simple kotlin_test.
Expand Down Expand Up @@ -238,7 +238,6 @@ kt_jvm_test(<a href="#kt_jvm_test-name">name</a>, <a href="#kt_jvm_test-associat
|<a id="kt_jvm_test-runtime_deps"></a>runtime_deps | Libraries to make available to the final binary or test at runtime only. Like ordinary deps, these will appear on the runtime classpath, but unlike them, not on the compile-time classpath. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | [] |
|<a id="kt_jvm_test-srcs"></a>srcs | The list of source files that are processed to create the target, this can contain both Java and Kotlin files. Java analysis occurs first so Kotlin classes may depend on Java classes in the same compilation unit. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | [] |
|<a id="kt_jvm_test-test_class"></a>test_class | The Java class to be loaded by the test runner. | String | optional | "" |
|<a id="kt_jvm_test-use_testrunner"></a>use_testrunner | Use bazel test runner. When disabled, an alternative test runner implementation should be provided and selected via <code>main_class</code>. | Boolean | optional | True |


<!-- Generated with Stardoc: http://skydoc.bazel.build -->
Expand Down
23 changes: 10 additions & 13 deletions kotlin/internal/jvm/impl.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
load("@bazel_tools//tools/jdk:toolchain_utils.bzl", "find_java_runtime_toolchain")
load("@rules_java//java:defs.bzl", "JavaInfo", "JavaPluginInfo", "java_common")
load(
"//kotlin/internal:defs.bzl",
Expand Down Expand Up @@ -70,7 +69,14 @@ def _write_launcher_action(ctx, rjars, main_class, jvm_flags):
"""
jvm_flags = " ".join([ctx.expand_location(f, ctx.attr.data) for f in jvm_flags])
template = ctx.attr._java_stub_template.files.to_list()[0]
java_bin_path = ctx.attr._java_runtime[java_common.JavaRuntimeInfo].java_executable_exec_path

java_runtime = ctx.toolchains["@bazel_tools//tools/jdk:runtime_toolchain_type"].java_runtime
java_bin_path = java_runtime.java_executable_exec_path

# Following https://github.com/bazelbuild/bazel/blob/6d5b084025a26f2f6d5041f7a9e8d302c590bc80/src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary.bzl#L66-L67
# Enable the security manager past deprecation.
if java_runtime.version >= 17:
jvm_flags = jvm_flags + " -Djava.security.manager=allow"

if ctx.configuration.coverage_enabled:
jacocorunner = ctx.toolchains[_TOOLCHAIN_TYPE].jacocorunner
Expand Down Expand Up @@ -109,6 +115,7 @@ def _write_launcher_action(ctx, rjars, main_class, jvm_flags):
classpath = ctx.configuration.host_path_separator.join(
["${RUNPATH}%s" % (j.short_path) for j in rjars.to_list()],
)

ctx.actions.expand_template(
template = template,
output = ctx.outputs.executable,
Expand Down Expand Up @@ -264,10 +271,7 @@ _SPLIT_STRINGS = [

def kt_jvm_junit_test_impl(ctx):
providers = _kt_jvm_produce_jar_actions(ctx, "kt_jvm_test")
runtime_jars = depset(
ctx.files._bazel_test_runner if ctx.attr.use_testrunner else [],
transitive = [providers.java.transitive_runtime_jars],
)
runtime_jars = depset(ctx.files._bazel_test_runner, transitive = [providers.java.transitive_runtime_jars])

coverage_runfiles = []
if ctx.configuration.coverage_enabled:
Expand All @@ -291,13 +295,6 @@ def kt_jvm_junit_test_impl(ctx):
if hasattr(ctx.fragments.java, "default_jvm_opts"):
jvm_flags = ctx.fragments.java.default_jvm_opts

java_runtime_toolchain = find_java_runtime_toolchain(ctx, ctx.attr._host_javabase)

# Following https://github.com/bazelbuild/bazel/blob/6d5b084025a26f2f6d5041f7a9e8d302c590bc80/src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary.bzl#L66-L67
# Enable the security manager past deprecation.
if java_runtime_toolchain.version >= 17:
jvm_flags.append("-Djava.security.manager=allow")

jvm_flags.extend(ctx.attr.jvm_flags)
coverage_metadata = _write_launcher_action(
ctx,
Expand Down
5 changes: 0 additions & 5 deletions kotlin/internal/jvm/jvm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,6 @@ Setup a simple kotlin_test.
default = Label("@bazel_tools//tools/jdk:TestRunner_deploy.jar"),
allow_files = True,
),
"use_testrunner": attr.bool(
doc = "Use bazel test runner. When disabled, an alternative test runner " +
"implementation should be provided and selected via `main_class`.",
default = True,
),
"test_class": attr.string(
doc = "The Java class to be loaded by the test runner.",
default = "",
Expand Down
Loading

0 comments on commit 80dd277

Please sign in to comment.