diff --git a/.travis.yml b/.travis.yml index 381f3ecfb..25654dbfe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,6 +64,10 @@ jobs: - name: "[linux] Dry test rules_scala + latest bazel version" <<: *linux env: TEST_SCRIPT=test_rules_scala XDG_CACHE_HOME=~/xdg_cache USE_BAZEL_VERSION=latest + - name: "[linux] Examples" + <<: *linux + env: TEST_SCRIPT=test_examples XDG_CACHE_HOME=~/xdg_cache + allow_failures: env: TEST_SCRIPT=test_rules_scala XDG_CACHE_HOME=~/xdg_cache USE_BAZEL_VERSION=latest diff --git a/docs/testing.md b/docs/testing.md index ec3d638bb..88af978f8 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -11,12 +11,17 @@ junit_repositories() junit_toolchain() # ScalaTest -load(""@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain") +load("@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain") scalatest_repositories() scalatest_toolchain() + +# Specs2 with Junit +load("@io_bazel_rules_scala//testing:specs2_junit.bzl", "specs2_junit_repositories", "specs2_junit_toolchain") +specs2_junit_repositories() +specs2_junit_toolchain() ``` -### Example to set up JUnit dependencies +### Configuring JUnit dependencies via toolchain `BUILD` file content in your preferred package: ```starlark @@ -48,13 +53,18 @@ declare_deps_provider( ], ) ``` - +Register toolchain +```starlark +# WORKSPACE +register_toolchains('//my/package:testing_toolchains_with_junit') +``` `junit_classpath_provider` (deps_id `junit_classpath`) is where classpath required for junit tests is defined. -ScalaTest support can be enabled by configuring a provider with an id `scalatest_classpath`: +### ScalaTest dependencies can be configured by decalring a provider with an id `scalatest_classpath`: ```starlark +# my/package/BUILD scala_testing_toolchain( name = "testing_toolchains_with_scalatest", dep_providers = [ @@ -80,10 +90,66 @@ declare_deps_provider( ], ) ``` - -Toolchain must be registered in your `WORKSPACE` file: +Register toolchain ```starlark -register_toolchains('//my/package:testing_toolchain') +# WORKSPACE +register_toolchains('//my/package:testing_toolchains_with_scalatest') ``` -Single toolchain can be used to configure multiple testing rules (JUnit 4, ScalaTest). +### Specs2 with Junit support can be configured by declaring providers with +`junit_classpath_provider`, `specs2_classpath_provider`, `specs2_junit_classpath_provider` ids: +```starlark +# my/package/BUILD +scala_testing_toolchain( + name = "testing_toolchains_with_specs2_junit_impl", + dep_providers = [ + ":junit_classpath_provider", + ":specs2_classpath_provider", + ":specs2_junit_classpath_provider", + ], + visibility = ["//visibility:public"], +) + +toolchain( + name = "testing_toolchains_with_specs2_junit", + toolchain = ":testing_toolchains_with_specs2_junit_impl", + toolchain_type = "@io_bazel_rules_scala//testing/toolchain:testing_toolchain_type", + visibility = ["//visibility:public"], +) + +declare_deps_provider( + name = "junit_classpath_provider", + deps_id = "junit_classpath", + visibility = ["//visibility:public"], + deps = [ + "@my_hamcrest_core", + "@my_junit", + ], +) + +declare_deps_provider( + name = "specs2_classpath_provider", + deps_id = "specs2_classpath", + visibility = ["//visibility:public"], + deps = [ + "@my_specs2_common", + "@my_specs2_core", + "@my_specs2_fp", + "@my_specs2_matcher", + ], +) + +declare_deps_provider( + name = "specs2_junit_classpath_provider", + deps_id = "specs2_junit_classpath", + visibility = ["//visibility:public"], + deps = [ + "@my_specs2_junit", + ], +) +``` +Register toolchain +```starlark +# WORKSPACE +register_toolchains('//my/package:testing_toolchains_with_specs2_junit') +``` \ No newline at end of file diff --git a/examples/testing/specs2_junit_repositories/BUILD b/examples/testing/specs2_junit_repositories/BUILD new file mode 100644 index 000000000..e69de29bb diff --git a/examples/testing/specs2_junit_repositories/WORKSPACE b/examples/testing/specs2_junit_repositories/WORKSPACE new file mode 100644 index 000000000..db48ab649 --- /dev/null +++ b/examples/testing/specs2_junit_repositories/WORKSPACE @@ -0,0 +1,35 @@ +workspace(name = "specs2_junit_repositories") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +skylib_version = "1.0.3" + +http_archive( + name = "bazel_skylib", + sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c", + type = "tar.gz", + url = "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{}/bazel-skylib-{}.tar.gz".format(skylib_version, skylib_version), +) + +local_repository( + name = "io_bazel_rules_scala", + path = "../../..", +) + +load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config") + +scala_config() + +load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories") + +scala_repositories() + +load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains") + +scala_register_toolchains() + +load("@io_bazel_rules_scala//testing:specs2_junit.bzl", "specs2_junit_repositories", "specs2_junit_toolchain") + +specs2_junit_repositories() + +specs2_junit_toolchain() diff --git a/examples/testing/specs2_junit_repositories/example/BUILD b/examples/testing/specs2_junit_repositories/example/BUILD new file mode 100644 index 000000000..9249d8687 --- /dev/null +++ b/examples/testing/specs2_junit_repositories/example/BUILD @@ -0,0 +1,7 @@ +load("@io_bazel_rules_scala//scala:scala.bzl", "scala_specs2_junit_test") + +scala_specs2_junit_test( + name = "example", + srcs = ["Specs2ExampleTest.scala"], + suffixes = ["Test"], +) diff --git a/examples/testing/specs2_junit_repositories/example/Specs2ExampleTest.scala b/examples/testing/specs2_junit_repositories/example/Specs2ExampleTest.scala new file mode 100644 index 000000000..47face369 --- /dev/null +++ b/examples/testing/specs2_junit_repositories/example/Specs2ExampleTest.scala @@ -0,0 +1,9 @@ +package example + +import org.specs2.mutable.SpecWithJUnit + +class Specs2ExampleTest extends SpecWithJUnit { + "works" in { + 1 mustEqual 1 + } +} diff --git a/specs2/BUILD b/specs2/BUILD index 7b792d43c..a40dea758 100644 --- a/specs2/BUILD +++ b/specs2/BUILD @@ -6,10 +6,7 @@ java_import( name = "specs2", jars = [], exports = [ - "@io_bazel_rules_scala_org_specs2_specs2_common", - "@io_bazel_rules_scala_org_specs2_specs2_core", - "@io_bazel_rules_scala_org_specs2_specs2_fp", - "@io_bazel_rules_scala_org_specs2_specs2_matcher", + "//testing/toolchain:specs2_classapath", ], deps = [ "//scala/private/toolchain_deps:scala_library_classpath", diff --git a/test/shell/test_examples.sh b/test/shell/test_examples.sh index 4280d5554..cd032c2ab 100755 --- a/test/shell/test_examples.sh +++ b/test/shell/test_examples.sh @@ -8,4 +8,9 @@ function scalatest_repositories_example() { (cd examples/testing/scalatest_repositories; bazel test //...) } +function specs2_junit_repositories_example() { + (cd examples/testing/specs2_junit_repositories; bazel test //...) +} + $runner scalatest_repositories_example +$runner specs2_junit_repositories_example diff --git a/test_examples.sh b/test_examples.sh new file mode 100755 index 000000000..c59f332bb --- /dev/null +++ b/test_examples.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +test_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/test/shell + +. "${test_dir}"/test_examples.sh \ No newline at end of file diff --git a/test_rules_scala.sh b/test_rules_scala.sh index 81458a83f..dc6ef5666 100755 --- a/test_rules_scala.sh +++ b/test_rules_scala.sh @@ -46,4 +46,3 @@ $runner bazel test //test/... --extra_toolchains="//test_expect_failure/plus_one . "${test_dir}"/test_toolchain.sh . "${test_dir}"/test_unused_dependency.sh . "${test_dir}"/test_twitter_scrooge.sh -. "${test_dir}"/test_examples.sh diff --git a/testing/BUILD b/testing/BUILD index b2b4c9d29..5b914b681 100644 --- a/testing/BUILD +++ b/testing/BUILD @@ -6,6 +6,8 @@ scala_testing_toolchain( dep_providers = [ ":junit_classpath_provider", ":scalatest_classpath_provider", + ":specs2_classpath_provider", + ":specs2_junit_classpath_provider", ], visibility = ["//visibility:public"], ) @@ -32,6 +34,23 @@ toolchain( visibility = ["//visibility:public"], ) +scala_testing_toolchain( + name = "specs2_junit_toolchain_impl", + dep_providers = [ + ":junit_classpath_provider", + ":specs2_classpath_provider", + ":specs2_junit_classpath_provider", + ], + visibility = ["//visibility:public"], +) + +toolchain( + name = "specs2_junit_toolchain", + toolchain = ":specs2_junit_toolchain_impl", + toolchain_type = "@io_bazel_rules_scala//testing/toolchain:testing_toolchain_type", + visibility = ["//visibility:public"], +) + scala_testing_toolchain( name = "junit_toolchain_impl", dep_providers = [ @@ -66,3 +85,24 @@ declare_deps_provider( "//external:io_bazel_rules_scala/dependency/scala/scalatest/scalatest", ], ) + +declare_deps_provider( + name = "specs2_classpath_provider", + deps_id = "specs2_classpath", + visibility = ["//visibility:public"], + deps = [ + "@io_bazel_rules_scala_org_specs2_specs2_common", + "@io_bazel_rules_scala_org_specs2_specs2_core", + "@io_bazel_rules_scala_org_specs2_specs2_fp", + "@io_bazel_rules_scala_org_specs2_specs2_matcher", + ], +) + +declare_deps_provider( + name = "specs2_junit_classpath_provider", + deps_id = "specs2_junit_classpath", + visibility = ["//visibility:public"], + deps = [ + "//external:io_bazel_rules_scala/dependency/specs2/specs2_junit", + ], +) diff --git a/testing/specs2_junit.bzl b/testing/specs2_junit.bzl new file mode 100644 index 000000000..a7da792d8 --- /dev/null +++ b/testing/specs2_junit.bzl @@ -0,0 +1,7 @@ +load("//specs2:specs2_junit.bzl", _repositories = "specs2_junit_repositories") + +def specs2_junit_repositories(): + _repositories() + +def specs2_junit_toolchain(): + native.register_toolchains("@io_bazel_rules_scala//testing:specs2_junit_toolchain") diff --git a/testing/toolchain/BUILD b/testing/toolchain/BUILD index 3b2a81945..4af842723 100644 --- a/testing/toolchain/BUILD +++ b/testing/toolchain/BUILD @@ -16,3 +16,15 @@ testing_toolchain_deps( deps_id = "scalatest_classpath", visibility = ["//visibility:public"], ) + +testing_toolchain_deps( + name = "specs2_classapath", + deps_id = "specs2_classpath", + visibility = ["//visibility:public"], +) + +testing_toolchain_deps( + name = "specs2_junit_classapath", + deps_id = "specs2_junit_classpath", + visibility = ["//visibility:public"], +)