Change in bazel[master]: Add Spock support to Groovy rules.

63 views
Skip to first unread message

Erik Kuefler (Gerrit)

unread,
Sep 22, 2015, 6:43:39 PM9/22/15
to bazel-de...@googlegroups.com
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>

Laurent Le Brun (Gerrit)

unread,
Sep 23, 2015, 12:10:18 PM9/23/15
to Erik Kuefler
Laurent Le Brun has posted comments on this change.

Change subject: Add Spock support to Groovy rules.
......................................................................


Patch Set 1:

(1 comment)

https://bazel-review.googlesource.com/#/c/2010/1/tools/build_defs/groovy/groovy.bzl
File tools/build_defs/groovy/groovy.bzl:

Line 282: java_srcs += [src]
This is going to fail with 'select' attributes. When an argument is a
select, you cannot iterate over it.

I would recommend using different attributes instead, so that you don't
have to do any filtering.
Gerrit-MessageType: comment
Gerrit-Change-Id: Ia70346a87762f89d587310cf9578daa9d7d9f34a
Gerrit-PatchSet: 1
Gerrit-Project: bazel
Gerrit-Branch: master
Gerrit-Owner: Erik Kuefler <ekue...@gmail.com>
Gerrit-Reviewer: Laurent Le Brun <laur...@google.com>
Gerrit-HasComments: Yes

Erik Kuefler (Gerrit)

unread,
Oct 8, 2015, 3:55:30 PM10/8/15
to Laurent Le Brun
Erik Kuefler has uploaded a new patch set (#2).

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, 151 insertions(+), 0 deletions(-)
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ia70346a87762f89d587310cf9578daa9d7d9f34a
Gerrit-PatchSet: 2
Gerrit-Project: bazel
Gerrit-Branch: master
Gerrit-Owner: Erik Kuefler <ekue...@gmail.com>

Erik Kuefler (Gerrit)

unread,
Oct 8, 2015, 3:59:34 PM10/8/15
to Laurent Le Brun
Erik Kuefler has posted comments on this change.

Change subject: Add Spock support to Groovy rules.
......................................................................


Patch Set 1:

(1 comment)

https://bazel-review.googlesource.com/#/c/2010/1/tools/build_defs/groovy/groovy.bzl
File tools/build_defs/groovy/groovy.bzl:

Line 282: java_srcs += [src]
> This is going to fail with 'select' attributes. When an argument is a
> selec
Ah interesting. OK, split this into separate groovy_srcs and java_srcs, and
also made specs its own.
Gerrit-MessageType: comment
Gerrit-Change-Id: Ia70346a87762f89d587310cf9578daa9d7d9f34a
Gerrit-PatchSet: 1
Gerrit-Project: bazel
Gerrit-Branch: master
Gerrit-Owner: Erik Kuefler <ekue...@gmail.com>
Gerrit-Reviewer: Erik Kuefler <ekue...@gmail.com>
Gerrit-Reviewer: Laurent Le Brun <laur...@google.com>
Gerrit-HasComments: Yes

Laurent Le Brun (Gerrit)

unread,
Oct 15, 2015, 8:27:17 AM10/15/15
to Erik Kuefler
Laurent Le Brun has posted comments on this change.

Change subject: Add Spock support to Groovy rules.
......................................................................


Patch Set 2: Code-Review+2
Gerrit-MessageType: comment
Gerrit-Change-Id: Ia70346a87762f89d587310cf9578daa9d7d9f34a
Gerrit-PatchSet: 2
Gerrit-Project: bazel
Gerrit-Branch: master
Gerrit-Owner: Erik Kuefler <ekue...@gmail.com>
Gerrit-Reviewer: Erik Kuefler <ekue...@gmail.com>
Gerrit-Reviewer: Laurent Le Brun <laur...@google.com>
Gerrit-HasComments: No

László Csomor (Gerrit)

unread,
Oct 16, 2015, 3:43:35 AM10/16/15
to Erik Kuefler, Laurent Le Brun
László Csomor has submitted this change and it was merged.

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
Reviewed-on: https://bazel-review.googlesource.com/#/c/2010/
MOS_MIGRATED_REVID=105529540
---
M tools/build_defs/groovy/README.md
M tools/build_defs/groovy/groovy.WORKSPACE
M tools/build_defs/groovy/groovy.bzl
3 files changed, 151 insertions(+), 0 deletions(-)



diff --git a/tools/build_defs/groovy/README.md
b/tools/build_defs/groovy/README.md
index 284a3ec..39eed6a 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,91 @@
</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.
index 5e36f55..b2c7947 100644
--- a/tools/build_defs/groovy/groovy.bzl
+++ b/tools/build_defs/groovy/groovy.bzl
@@ -256,3 +256,56 @@
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,
+ )

--
To view, visit https://bazel-review.googlesource.com/2010
To unsubscribe, visit https://bazel-review.googlesource.com/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia70346a87762f89d587310cf9578daa9d7d9f34a
Gerrit-PatchSet: 3
Gerrit-Project: bazel
Gerrit-Branch: master
Gerrit-Owner: Erik Kuefler <ekue...@gmail.com>
Gerrit-Reviewer: Erik Kuefler <ekue...@gmail.com>
Gerrit-Reviewer: Laurent Le Brun <laur...@google.com>
Gerrit-Reviewer: László Csomor <laszlo...@google.com>

László Csomor (Gerrit)

unread,
Oct 16, 2015, 3:43:35 AM10/16/15
to Erik Kuefler, Laurent Le Brun
Hello Laurent Le Brun,

I'd like you to reexamine a change. Please visit

https://bazel-review.googlesource.com/2010

to look at the new patch set (#3).

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
Reviewed-on: https://bazel-review.googlesource.com/#/c/2010/
MOS_MIGRATED_REVID=105529540
---
M tools/build_defs/groovy/README.md
M tools/build_defs/groovy/groovy.WORKSPACE
M tools/build_defs/groovy/groovy.bzl
3 files changed, 151 insertions(+), 0 deletions(-)
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ia70346a87762f89d587310cf9578daa9d7d9f34a
Gerrit-PatchSet: 3
Gerrit-Project: bazel
Gerrit-Branch: master
Gerrit-Owner: Erik Kuefler <ekue...@gmail.com>
Reply all
Reply to author
Forward
0 new messages