Erik Kuefler has uploaded a new change for review.
https://bazel-review.googlesource.com/2010
Change subject: Add Spock support to Groovy rules.
......................................................................
Add Spock support to Groovy rules.
Spock is a popular unit testing framework for Java and Groovy applications,
see
https://code.google.com/p/spock/ for details. This build rule is just a
wrapper around java and groovy libraries and tests that makes it convenient
to define a spock-based test using a single BUILD target containing the test
specs and any supporting Groovy and Java code.
Change-Id: Ia70346a87762f89d587310cf9578daa9d7d9f34a
---
M tools/build_defs/groovy/README.md
M tools/build_defs/groovy/groovy.WORKSPACE
M tools/build_defs/groovy/groovy.bzl
3 files changed, 147 insertions(+), 0 deletions(-)
diff --git a/tools/build_defs/groovy/README.md
b/tools/build_defs/groovy/README.md
index 284a3ec..5bb8532 100644
--- a/tools/build_defs/groovy/README.md
+++ b/tools/build_defs/groovy/README.md
@@ -12,6 +12,7 @@
* [`groovy_library`](#groovy_library)
* [`groovy_and_java_library`](#groovy_and_java_library)
* [`groovy_binary`](#groovy_binary)
+ * [`spock_test`](#spock_test)
<a name="setup"></a>
## Setup
@@ -22,6 +23,7 @@
* `//external:groovy-sdk`, pointing at the
[Groovy SDK binaries](
http://www.groovy-lang.org/download.html)
* `//external:junit`, pointing at JUnit (only required if using
`groovy_test`)
+ * `//external:spock`, pointing at Spock (only required if using
`spock_test`)
The easiest way to do so is by copying the content of `groovy.WORKSPACE`
to your
workspace file and putting `groovy.BUILD` at the root of your workspace.
@@ -365,4 +367,72 @@
</td>
</tr>
</tbody>
+
+<a name="spock_test"></a>
+### `spock_test`
+
+`spock_test(name, deps, srcs, data, resources, jvm_flags, size, tags)`
+
+<table>
+ <thead>
+ <tr>
+ <th>Attribute</th>
+ <th>Description</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>name</code></td>
+ <td>
+ <code>Name, required</code>
+ <p>A unique name for this rule.</p>
+ </td>
+ </tr>
+ <tr>
+ <td><code>srcs</code></td>
+ <td>
+ <code>List of labels, required</code>
+ <p>
+ List of .groovy and .java source files used to build the test.
Files
+ whose names end with "Spec.groovy" are assumed to be the actual
test
+ files that will be executed with JUnit.
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td><code>deps</code></td>
+ <td>
+ <code>List of labels or .jar files, optional</code>
+ <p>
+ List of libraries to be included on both the compile-time
classpath
+ when building this test and on the runtime classpath when
executing it.
+ </p>
+ <p>
+ These can be `groovy_library` targets, `java_library` targets,
+ `groovy_and_java_library` targets, or raw .jar files.
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td><code>resources</code></td>
+ <td>
+ <code>List of labels, optional</code>
+ <p>
+ A list of data files to include on the test's classpath. This is
+ accomplished by creating a `java_library` containing only the
specified
+ resources and including that library in the test's dependencies.
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td><code>jvm_flags</code></td>
+ <td>
+ <code>List of strings, optional</code>
+ <p>
+ A list of flags to embed in the wrapper script generated for
running
+ this binary.
+ </p>
+ </td>
+ </tr>
+ </tbody>
</table>
diff --git a/tools/build_defs/groovy/groovy.WORKSPACE
b/tools/build_defs/groovy/groovy.WORKSPACE
index 545df09..8868d50 100644
--- a/tools/build_defs/groovy/groovy.WORKSPACE
+++ b/tools/build_defs/groovy/groovy.WORKSPACE
@@ -17,3 +17,12 @@
name = "junit",
actual = "@junit-artifact//jar",
)
+
+maven_jar(
+ name = "spock-artifact",
+ artifact = "org.spockframework:spock-core:0.7-groovy-2.0",
+)
+bind(
+ name = "spock",
+ actual = "@spock-artifact//jar",
+)
diff --git a/tools/build_defs/groovy/groovy.bzl
b/tools/build_defs/groovy/groovy.bzl
index 3c3102c..eb2263f 100644
--- a/tools/build_defs/groovy/groovy.bzl
+++ b/tools/build_defs/groovy/groovy.bzl
@@ -256,3 +256,71 @@
data = data,
jvm_flags = jvm_flags,
)
+
+def spock_test(
+ name,
+ deps=[],
+ srcs=[],
+ data=[],
+ resources=[],
+ jvm_flags=[],
+ size="small",
+ tags=[]):
+ groovy_lib_deps = deps + [
+ "//external:junit",
+ "//external:spock",
+ ]
+ test_deps = deps + [
+ "//external:junit",
+ "//external:spock",
+ ]
+
+ # Put all .java sources into a Java library
+ java_srcs = []
+ for src in srcs:
+ if src.endswith(".java"):
+ java_srcs += [src]
+ if java_srcs:
+ native.java_library(
+ name = name + "-javalib",
+ srcs = java_srcs,
+ deps = deps + [
+ "//external:junit",
+ "//external:spock",
+ ],
+ )
+ groovy_lib_deps += [name + "-javalib"]
+ test_deps += [name + "-javalib"]
+
+ # Put all .groovy sources into a groovy library
+ groovy_srcs = []
+ for src in srcs:
+ if src.endswith(".groovy"):
+ groovy_srcs += [src]
+ if groovy_srcs:
+ groovy_library(
+ name = name + "-groovylib",
+ srcs = groovy_srcs,
+ deps = groovy_lib_deps,
+ )
+ test_deps += [name + "-groovylib"]
+
+ # Search for file names ending in "Spec.groovy" to use as test classes
+ specs = []
+ for src in srcs:
+ if src.endswith("Spec.groovy"):
+ specs += [src]
+ if not specs:
+ fail("No specs found")
+
+ # Create a groovy test
+ groovy_test(
+ name = name,
+ deps = test_deps,
+ srcs = specs,
+ data = data,
+ resources = resources,
+ jvm_flags = jvm_flags,
+ size = size,
+ tags = tags,
+ )
--
To view, visit
https://bazel-review.googlesource.com/2010
To unsubscribe, visit
https://bazel-review.googlesource.com/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia70346a87762f89d587310cf9578daa9d7d9f34a
Gerrit-PatchSet: 1
Gerrit-Project: bazel
Gerrit-Branch: master
Gerrit-Owner: Erik Kuefler <
ekue...@gmail.com>