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

Moving scala junit test from test_rules_scala.sh to RulesScalaIntegra… #503

Closed
wants to merge 1 commit into from
Closed
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
43 changes: 43 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ scala_maven_import_external(
jar_sha256 = "972139718abc8a4893fa78cba8cf7b2c903f35c97aaf44fa3031b0669948b480",
)

scala_maven_import_external(
name = "junit_4_11",
licenses = ["restricted"], # Eclipse Public License - v 1.0
artifact = "junit:junit:4.11",
server_urls = ["http://central.maven.org/maven2"],
jar_sha256 = "90a8e1603eeca48e7e879f3afbc9560715322985f39a274f6f6070b43f9d06fe",
)

# bazel's java_import_external has been altered in rules_scala to be a macro based on jvm_import_external
# in order to allow for other jvm-language imports (e.g. scala_import)
# the 3rd-party dependency below is using the java_import_external macro
Expand All @@ -108,3 +116,38 @@ java_import_external(
neverlink = True,
generated_linkable_rule_name="linkable_org_apache_commons_commons_lang_3_5_without_file",
)

build_bazel_integration_testing_version="36ffe6fe0f4bb727c1fe34209a8d6fd33d8d0d8e" # update this as needed
http_archive(
name = "build_bazel_integration_testing",
url = "https://github.com/bazelbuild/bazel-integration-testing/archive/%s.zip"%build_bazel_integration_testing_version,
strip_prefix = "bazel-integration-testing-" + build_bazel_integration_testing_version,
)
load("@build_bazel_integration_testing//tools:repositories.bzl", "bazel_binaries")
bazel_binaries(versions = ["0.12.0"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make a bazel_version_notes.md or something that lists all the place we need to update when we bump bazel versions?

load("@build_bazel_integration_testing//tools:bazel_java_integration_test.bzl", "bazel_java_integration_test_deps")
bazel_java_integration_test_deps()

load("@build_bazel_integration_testing//tools:import.bzl", "bazel_external_dependency_archive")
BAZEL_JAVA_LAUNCHER_VERSION = "0.4.5"
java_stub_template_url = ("raw.githubusercontent.com/bazelbuild/bazel/" +
BAZEL_JAVA_LAUNCHER_VERSION +
"/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" +
"java_stub_template.txt")

rules_scala_version = "a8ef632b1b020cdf2c215ecd9fcfa84bc435efcb"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty wild, we are pointing to a previous version of this repo. Can we comment why?

bazel_external_dependency_archive(
name = "integration_test_ext",
srcs = {
"fe61287087b471a74c81625d9d341224fb5ffc6c9358e51c7368182b7b6f112c": [
"https://github.com/bazelbuild/rules_scala/archive/%s.zip" % rules_scala_version,
],
"f09d06d55cd25168427a323eb29d32beca0ded43bec80d76fc6acd8199a24489": [
"https://mirror.bazel.build/%s" % java_stub_template_url,
"https://%s" % java_stub_template_url
],
"12037ca64c68468e717e950f47fc77d5ceae5e74e3bdca56f6d02fd5bfd6900b": [
"https://downloads.lightbend.com/scala/2.11.11/scala-2.11.11.tgz"
],
},
)
31 changes: 25 additions & 6 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ load("//scala:scala.bzl",
load("//scala_proto:scala_proto.bzl",
"scalapb_proto_library")

load("@build_bazel_integration_testing//tools:bazel_java_integration_test.bzl", "bazel_java_integration_test")

# The examples below show how to combine Scala and Java rules.
# ScalaBinary is the Scala equivalent of JavaBinary.

Expand Down Expand Up @@ -364,12 +366,29 @@ scala_junit_test(
print_discovered_classes = True
)

scala_junit_test(
name = "JunitFiltersClassesWithoutTests",
srcs = ["src/main/scala/scala/test/junit/JunitNoTests.scala"],
size = "small",
suffixes = ["Test"],
print_discovered_classes = True
scala_library(
name = "rules_scala_it_junit",
srcs = ["src/main/scala/scala/test/junit/RulesScalaIntegrationTests.scala"],

deps = [
"@junit_4_11//jar",
"@build_bazel_integration_testing//java/build/bazel/tests/integration:workspace_driver",
"@build_bazel_integration_testing//java/build/bazel/tests/integration:integration",
],
testonly = 1
)

bazel_java_integration_test (
name = "RulesScalaIntegrationTests",
versions = ["0.12.0"],
test_class = "scala.test.junit.RulesScalaIntegrationTests",
srcs = [],
runtime_deps = [":rules_scala_it_junit"],
external_deps = [
"@integration_test_ext",
],
tags = ["IT"],

)

scala_junit_test(
Expand Down
11 changes: 0 additions & 11 deletions test/src/main/scala/scala/test/junit/JunitNoTests.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package scala.test.junit

import build.bazel.tests.integration.BazelBaseTestCase
import org.junit.{Assert, Test}
import scala.collection.JavaConverters._

class RulesScalaIntegrationTests extends BazelBaseTestCase {

private val NoTestsFoundExitCode = 3
private val NoTestsFoundLabel = "no_tests_found"

@Test
def singleTestSoTargetWillNotFailDueToNoTestsTest: Unit = {
givenRulesScalaWorkspaceFile()
givenBuildFile()
givenEmptyTestSuitFile()

val cmd = driver.bazelCommand("test", "//...").build()
val exitCode = cmd.run()
val errorOutput = cmd.getErrorLines.asScala

assertNoTestsFoundCorrectOutput(errorOutput, exitCode)
}

private def assertNoTestsFoundCorrectOutput(output: Seq[String], exitCode: Int): Unit = {
Assert.assertEquals(exitCode, NoTestsFoundExitCode )
val hasCorrectOutput = output.exists(line => {
line.contains("FAIL") && line.contains(NoTestsFoundLabel)
})

Assert.assertTrue(hasCorrectOutput)
}

private def givenRulesScalaWorkspaceFile(): Unit = {
val workspace =
"""
|rules_scala_version="a8ef632b1b020cdf2c215ecd9fcfa84bc435efcb" # update this as needed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not somehow point to the current version? It feels weird to always be testing a previous version. Also, how updating this seems like a challenge especially if we have many.

|
|http_archive(
| name = "io_bazel_rules_scala",
| url = "https://github.com/bazelbuild/rules_scala/archive/%s.zip"%rules_scala_version,
| type = "zip",
| strip_prefix= "rules_scala-%s" % rules_scala_version
|)
|
|load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
|scala_register_toolchains()
|
|load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
|scala_repositories()
|
|load("@io_bazel_rules_scala//junit:junit.bzl", "junit_repositories")
|junit_repositories()
""".stripMargin
driver.scratchFile("WORKSPACE", workspace)
}

private def givenBuildFile(): Unit = {
val build =
s"""
|load("@io_bazel_rules_scala//scala:scala.bzl", "scala_junit_test")
|
|scala_junit_test(
| name = "$NoTestsFoundLabel",
| srcs = ["JunitTest.scala"],
| suffixes = ["WrongTestSuffix"],
| size = "small"
|)
""".stripMargin
driver.scratchFile("BUILD", build)
}

private def givenEmptyTestSuitFile(): Unit = {
val junitTest =
"""
|import org.junit.Test
|class JunitTest {
| @Test
| def running: Unit = {
| }
|}
""".stripMargin

driver.scratchFile("JunitTest.scala", junitTest)
}

}
6 changes: 0 additions & 6 deletions test_expect_failure/scala_junit_test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,3 @@ scala_junit_test(
srcs = ["JunitTest.scala"],
size = "small",
)
scala_junit_test(
name = "no_tests_found",
srcs = ["JunitTest.scala"],
suffixes = ["DoesNotMatch"],
size = "small",
)
10 changes: 0 additions & 10 deletions test_expect_failure/scala_junit_test/JunitTest.scala

This file was deleted.

5 changes: 0 additions & 5 deletions test_rules_scala.sh
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,6 @@ test_junit_test_must_have_prefix_or_suffix() {
action_should_fail test test_expect_failure/scala_junit_test:no_prefix_or_suffix
}

test_junit_test_errors_when_no_tests_found() {
action_should_fail test test_expect_failure/scala_junit_test:no_tests_found
}

test_resources() {
RESOURCE_NAME="resource.txt"
TARGET=$1
Expand Down Expand Up @@ -750,7 +746,6 @@ $runner junit_generates_xml_logs
$runner scala_library_jar_without_srcs_must_fail_on_mismatching_resource_strip_prefix
$runner multiple_junit_patterns
$runner test_junit_test_must_have_prefix_or_suffix
$runner test_junit_test_errors_when_no_tests_found
$runner scala_library_jar_without_srcs_must_include_direct_file_resources
$runner scala_library_jar_without_srcs_must_include_filegroup_resources
$runner bazel run test/src/main/scala/scala/test/large_classpath:largeClasspath
Expand Down