diff options
author | 2015-10-15 18:56:57 +0000 | |
---|---|---|
committer | 2015-10-16 07:39:54 +0000 | |
commit | dda3f8c8e2d088ba5d8640dfa20651ce71d0e535 (patch) | |
tree | 2d1cd830de811ed9a874d3dd1cec095820d113d4 /tools | |
parent | 9faad19c24ff526aeb6e30c7df9fcf3583ca1989 (diff) |
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
Reviewed-on: https://bazel-review.googlesource.com/#/c/2010/
MOS_MIGRATED_REVID=105529540
Diffstat (limited to 'tools')
-rw-r--r-- | tools/build_defs/groovy/README.md | 89 | ||||
-rw-r--r-- | tools/build_defs/groovy/groovy.WORKSPACE | 9 | ||||
-rw-r--r-- | tools/build_defs/groovy/groovy.bzl | 53 |
3 files changed, 151 insertions, 0 deletions
diff --git a/tools/build_defs/groovy/README.md b/tools/build_defs/groovy/README.md index 284a3eccc9..39eed6a3e3 100644 --- a/tools/build_defs/groovy/README.md +++ b/tools/build_defs/groovy/README.md @@ -12,6 +12,7 @@ libraries and vice-versa. * [`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 @@ targets: * `//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,91 @@ groovy_test( </td> </tr> </tbody> + +<a name="spock_test"></a> +### `spock_test` + +`spock_test(name, specs, deps, groovy_srcs, java_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>specs</code></td> + <td> + <code>List of labels, required</code> + <p> + List of .groovy source files that will be used as test specifications + that will be executed by JUnit. + </p> + </td> + </tr> + <tr> + <td><code>groovy_srcs</code></td> + <td> + <code>List of labels, optional</code> + <p> + List of additional .groovy source files that will be used to build the + test. + </p> + </td> + </tr> + <tr> + <td><code>java_srcs</code></td> + <td> + <code>List of labels, optional</code> + <p> + List of additional .java source files that will be used to build the + test. + </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 545df09232..8868d50a96 100644 --- a/tools/build_defs/groovy/groovy.WORKSPACE +++ b/tools/build_defs/groovy/groovy.WORKSPACE @@ -17,3 +17,12 @@ bind( 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 5e36f5504c..b2c7947003 100644 --- a/tools/build_defs/groovy/groovy.bzl +++ b/tools/build_defs/groovy/groovy.bzl @@ -256,3 +256,56 @@ def groovy_test( data = data, jvm_flags = jvm_flags, ) + +def spock_test( + name, + specs, + deps=[], + groovy_srcs=[], + java_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 + 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 specs and Groovy sources into a Groovy library + groovy_library( + name = name + "-groovylib", + srcs = specs + groovy_srcs, + deps = groovy_lib_deps, + ) + test_deps += [name + "-groovylib"] + + # 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, + ) |