-
Notifications
You must be signed in to change notification settings - Fork 278
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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"]) | ||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
], | ||
}, | ||
) |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
|
||
} |
This file was deleted.
There was a problem hiding this comment.
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?