Skip to content

Commit 376765b

Browse files
authored
Specs2 toolchain (bazel-contrib#1136)
* Update testing docs, toolchain and repository loading * Add testing toolchain to version tests WORKSPACE * specs2 and specs2 junit toolchain deps * Use external name in toolchain helpers * Update and add specs2 docs and examples * Docs update * Remove duplicate toolchain registration * Move example workspace tests to a separete Travis CI job * Fix typo in docs
1 parent 28280be commit 376765b

File tree

13 files changed

+201
-13
lines changed

13 files changed

+201
-13
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ jobs:
6464
- name: "[linux] Dry test rules_scala + latest bazel version"
6565
<<: *linux
6666
env: TEST_SCRIPT=test_rules_scala XDG_CACHE_HOME=~/xdg_cache USE_BAZEL_VERSION=latest
67+
- name: "[linux] Examples"
68+
<<: *linux
69+
env: TEST_SCRIPT=test_examples XDG_CACHE_HOME=~/xdg_cache
70+
6771

6872
allow_failures:
6973
env: TEST_SCRIPT=test_rules_scala XDG_CACHE_HOME=~/xdg_cache USE_BAZEL_VERSION=latest

docs/testing.md

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ junit_repositories()
1111
junit_toolchain()
1212

1313
# ScalaTest
14-
load(""@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain")
14+
load("@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain")
1515
scalatest_repositories()
1616
scalatest_toolchain()
17+
18+
# Specs2 with Junit
19+
load("@io_bazel_rules_scala//testing:specs2_junit.bzl", "specs2_junit_repositories", "specs2_junit_toolchain")
20+
specs2_junit_repositories()
21+
specs2_junit_toolchain()
1722
```
1823

19-
### Example to set up JUnit dependencies
24+
### Configuring JUnit dependencies via toolchain
2025

2126
`BUILD` file content in your preferred package:
2227
```starlark
@@ -48,13 +53,18 @@ declare_deps_provider(
4853
],
4954
)
5055
```
51-
56+
Register toolchain
57+
```starlark
58+
# WORKSPACE
59+
register_toolchains('//my/package:testing_toolchains_with_junit')
60+
```
5261
`junit_classpath_provider` (deps_id `junit_classpath`) is where classpath required for junit tests
5362
is defined.
5463

55-
ScalaTest support can be enabled by configuring a provider with an id `scalatest_classpath`:
64+
### ScalaTest dependencies can be configured by decalring a provider with an id `scalatest_classpath`:
5665

5766
```starlark
67+
# my/package/BUILD
5868
scala_testing_toolchain(
5969
name = "testing_toolchains_with_scalatest",
6070
dep_providers = [
@@ -80,10 +90,66 @@ declare_deps_provider(
8090
],
8191
)
8292
```
83-
84-
Toolchain must be registered in your `WORKSPACE` file:
93+
Register toolchain
8594
```starlark
86-
register_toolchains('//my/package:testing_toolchain')
95+
# WORKSPACE
96+
register_toolchains('//my/package:testing_toolchains_with_scalatest')
8797
```
8898

89-
Single toolchain can be used to configure multiple testing rules (JUnit 4, ScalaTest).
99+
### Specs2 with Junit support can be configured by declaring providers with
100+
`junit_classpath_provider`, `specs2_classpath_provider`, `specs2_junit_classpath_provider` ids:
101+
```starlark
102+
# my/package/BUILD
103+
scala_testing_toolchain(
104+
name = "testing_toolchains_with_specs2_junit_impl",
105+
dep_providers = [
106+
":junit_classpath_provider",
107+
":specs2_classpath_provider",
108+
":specs2_junit_classpath_provider",
109+
],
110+
visibility = ["//visibility:public"],
111+
)
112+
113+
toolchain(
114+
name = "testing_toolchains_with_specs2_junit",
115+
toolchain = ":testing_toolchains_with_specs2_junit_impl",
116+
toolchain_type = "@io_bazel_rules_scala//testing/toolchain:testing_toolchain_type",
117+
visibility = ["//visibility:public"],
118+
)
119+
120+
declare_deps_provider(
121+
name = "junit_classpath_provider",
122+
deps_id = "junit_classpath",
123+
visibility = ["//visibility:public"],
124+
deps = [
125+
"@my_hamcrest_core",
126+
"@my_junit",
127+
],
128+
)
129+
130+
declare_deps_provider(
131+
name = "specs2_classpath_provider",
132+
deps_id = "specs2_classpath",
133+
visibility = ["//visibility:public"],
134+
deps = [
135+
"@my_specs2_common",
136+
"@my_specs2_core",
137+
"@my_specs2_fp",
138+
"@my_specs2_matcher",
139+
],
140+
)
141+
142+
declare_deps_provider(
143+
name = "specs2_junit_classpath_provider",
144+
deps_id = "specs2_junit_classpath",
145+
visibility = ["//visibility:public"],
146+
deps = [
147+
"@my_specs2_junit",
148+
],
149+
)
150+
```
151+
Register toolchain
152+
```starlark
153+
# WORKSPACE
154+
register_toolchains('//my/package:testing_toolchains_with_specs2_junit')
155+
```

examples/testing/specs2_junit_repositories/BUILD

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
workspace(name = "specs2_junit_repositories")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
skylib_version = "1.0.3"
6+
7+
http_archive(
8+
name = "bazel_skylib",
9+
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
10+
type = "tar.gz",
11+
url = "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{}/bazel-skylib-{}.tar.gz".format(skylib_version, skylib_version),
12+
)
13+
14+
local_repository(
15+
name = "io_bazel_rules_scala",
16+
path = "../../..",
17+
)
18+
19+
load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")
20+
21+
scala_config()
22+
23+
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
24+
25+
scala_repositories()
26+
27+
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
28+
29+
scala_register_toolchains()
30+
31+
load("@io_bazel_rules_scala//testing:specs2_junit.bzl", "specs2_junit_repositories", "specs2_junit_toolchain")
32+
33+
specs2_junit_repositories()
34+
35+
specs2_junit_toolchain()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_specs2_junit_test")
2+
3+
scala_specs2_junit_test(
4+
name = "example",
5+
srcs = ["Specs2ExampleTest.scala"],
6+
suffixes = ["Test"],
7+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package example
2+
3+
import org.specs2.mutable.SpecWithJUnit
4+
5+
class Specs2ExampleTest extends SpecWithJUnit {
6+
"works" in {
7+
1 mustEqual 1
8+
}
9+
}

specs2/BUILD

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ java_import(
66
name = "specs2",
77
jars = [],
88
exports = [
9-
"@io_bazel_rules_scala_org_specs2_specs2_common",
10-
"@io_bazel_rules_scala_org_specs2_specs2_core",
11-
"@io_bazel_rules_scala_org_specs2_specs2_fp",
12-
"@io_bazel_rules_scala_org_specs2_specs2_matcher",
9+
"//testing/toolchain:specs2_classapath",
1310
],
1411
deps = [
1512
"//scala/private/toolchain_deps:scala_library_classpath",

test/shell/test_examples.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ function scalatest_repositories_example() {
88
(cd examples/testing/scalatest_repositories; bazel test //...)
99
}
1010

11+
function specs2_junit_repositories_example() {
12+
(cd examples/testing/specs2_junit_repositories; bazel test //...)
13+
}
14+
1115
$runner scalatest_repositories_example
16+
$runner specs2_junit_repositories_example

test_examples.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
test_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/test/shell
6+
7+
. "${test_dir}"/test_examples.sh

test_rules_scala.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,3 @@ $runner bazel test //test/... --extra_toolchains="//test_expect_failure/plus_one
4646
. "${test_dir}"/test_toolchain.sh
4747
. "${test_dir}"/test_unused_dependency.sh
4848
. "${test_dir}"/test_twitter_scrooge.sh
49-
. "${test_dir}"/test_examples.sh

testing/BUILD

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ scala_testing_toolchain(
66
dep_providers = [
77
":junit_classpath_provider",
88
":scalatest_classpath_provider",
9+
":specs2_classpath_provider",
10+
":specs2_junit_classpath_provider",
911
],
1012
visibility = ["//visibility:public"],
1113
)
@@ -32,6 +34,23 @@ toolchain(
3234
visibility = ["//visibility:public"],
3335
)
3436

37+
scala_testing_toolchain(
38+
name = "specs2_junit_toolchain_impl",
39+
dep_providers = [
40+
":junit_classpath_provider",
41+
":specs2_classpath_provider",
42+
":specs2_junit_classpath_provider",
43+
],
44+
visibility = ["//visibility:public"],
45+
)
46+
47+
toolchain(
48+
name = "specs2_junit_toolchain",
49+
toolchain = ":specs2_junit_toolchain_impl",
50+
toolchain_type = "@io_bazel_rules_scala//testing/toolchain:testing_toolchain_type",
51+
visibility = ["//visibility:public"],
52+
)
53+
3554
scala_testing_toolchain(
3655
name = "junit_toolchain_impl",
3756
dep_providers = [
@@ -66,3 +85,24 @@ declare_deps_provider(
6685
"//external:io_bazel_rules_scala/dependency/scala/scalatest/scalatest",
6786
],
6887
)
88+
89+
declare_deps_provider(
90+
name = "specs2_classpath_provider",
91+
deps_id = "specs2_classpath",
92+
visibility = ["//visibility:public"],
93+
deps = [
94+
"@io_bazel_rules_scala_org_specs2_specs2_common",
95+
"@io_bazel_rules_scala_org_specs2_specs2_core",
96+
"@io_bazel_rules_scala_org_specs2_specs2_fp",
97+
"@io_bazel_rules_scala_org_specs2_specs2_matcher",
98+
],
99+
)
100+
101+
declare_deps_provider(
102+
name = "specs2_junit_classpath_provider",
103+
deps_id = "specs2_junit_classpath",
104+
visibility = ["//visibility:public"],
105+
deps = [
106+
"//external:io_bazel_rules_scala/dependency/specs2/specs2_junit",
107+
],
108+
)

testing/specs2_junit.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("//specs2:specs2_junit.bzl", _repositories = "specs2_junit_repositories")
2+
3+
def specs2_junit_repositories():
4+
_repositories()
5+
6+
def specs2_junit_toolchain():
7+
native.register_toolchains("@io_bazel_rules_scala//testing:specs2_junit_toolchain")

testing/toolchain/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ testing_toolchain_deps(
1616
deps_id = "scalatest_classpath",
1717
visibility = ["//visibility:public"],
1818
)
19+
20+
testing_toolchain_deps(
21+
name = "specs2_classapath",
22+
deps_id = "specs2_classpath",
23+
visibility = ["//visibility:public"],
24+
)
25+
26+
testing_toolchain_deps(
27+
name = "specs2_junit_classapath",
28+
deps_id = "specs2_junit_classpath",
29+
visibility = ["//visibility:public"],
30+
)

0 commit comments

Comments
 (0)