aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar David Chen <dzc@google.com>2015-10-22 09:35:11 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-10-22 15:17:19 +0000
commit854b72dddb80a4c8da6bf0ac9dbd683951875541 (patch)
treee55cce6f32ed203070f60e2aa6ce8fbe70edc936 /examples
parent16f10837a224df9d792cba563dbee138a0789cb7 (diff)
[jsonnet] Add jsonnet_to_json_test rule for testing Jsonnet code.
RELNOTES: [jsonnet] Add jsonnet_to_json_test rule for testing Jsonnet code. -- MOS_MIGRATED_REVID=106040951
Diffstat (limited to 'examples')
-rw-r--r--examples/jsonnet/BUILD28
-rw-r--r--examples/jsonnet/intersection_golden.json48
-rw-r--r--examples/jsonnet/invalid.jsonnet15
-rw-r--r--examples/jsonnet/invalid.out2
-rw-r--r--examples/jsonnet/wordcount_golden.json53
5 files changed, 145 insertions, 1 deletions
diff --git a/examples/jsonnet/BUILD b/examples/jsonnet/BUILD
index 3c829df876..735057ed17 100644
--- a/examples/jsonnet/BUILD
+++ b/examples/jsonnet/BUILD
@@ -1,6 +1,11 @@
package(default_visibility = ["//visibility:public"])
-load("/tools/build_defs/jsonnet/jsonnet", "jsonnet_library", "jsonnet_to_json")
+load(
+ "/tools/build_defs/jsonnet/jsonnet",
+ "jsonnet_library",
+ "jsonnet_to_json",
+ "jsonnet_to_json_test",
+)
jsonnet_library(
name = "workflow",
@@ -14,6 +19,13 @@ jsonnet_to_json(
deps = [":workflow"],
)
+jsonnet_to_json_test(
+ name = "wordcount_test",
+ src = "wordcount.jsonnet",
+ golden = "wordcount_golden.json",
+ deps = [":workflow"],
+)
+
jsonnet_to_json(
name = "intersection",
src = "intersection.jsonnet",
@@ -21,6 +33,13 @@ jsonnet_to_json(
deps = [":workflow"],
)
+jsonnet_to_json_test(
+ name = "intersection_test",
+ src = "intersection.jsonnet",
+ golden = "intersection_golden.json",
+ deps = [":workflow"],
+)
+
jsonnet_library(
name = "shell-workflows-lib",
srcs = [
@@ -39,3 +58,10 @@ jsonnet_to_json(
],
deps = [":shell-workflows-lib"],
)
+
+jsonnet_to_json_test(
+ name = "invalid_test",
+ src = "invalid.jsonnet",
+ error = 1,
+ golden = "invalid.out",
+)
diff --git a/examples/jsonnet/intersection_golden.json b/examples/jsonnet/intersection_golden.json
new file mode 100644
index 0000000000..6e8fa63864
--- /dev/null
+++ b/examples/jsonnet/intersection_golden.json
@@ -0,0 +1,48 @@
+{
+ "intersection": {
+ "jobs": {
+ "intersect": {
+ "command": "comm -12 /tmp/list1_sorted /tmp/list2_sorted > /tmp/intersection",
+ "deps": [
+ ":sort_file1",
+ ":sort_file2"
+ ],
+ "inputs": [
+ "/tmp/list1_sorted",
+ "/tmp/list2_sorted"
+ ],
+ "outputs": [
+ "/tmp/intersection"
+ ],
+ "type": "sh",
+ "vars": { }
+ },
+ "sort_file1": {
+ "command": "sort /tmp/list1 > /tmp/list1_sorted",
+ "deps": [ ],
+ "inputs": [
+ "/tmp/list1"
+ ],
+ "outputs": [
+ "/tmp/list1_sorted"
+ ],
+ "type": "sh",
+ "vars": { }
+ },
+ "sort_file2": {
+ "command": "sort /tmp/list2 > /tmp/list2_sorted",
+ "deps": [ ],
+ "inputs": [
+ "/tmp/list2"
+ ],
+ "outputs": [
+ "/tmp/list2_sorted"
+ ],
+ "type": "sh",
+ "vars": { }
+ }
+ },
+ "retries": 5,
+ "schedule": { }
+ }
+}
diff --git a/examples/jsonnet/invalid.jsonnet b/examples/jsonnet/invalid.jsonnet
new file mode 100644
index 0000000000..e911037832
--- /dev/null
+++ b/examples/jsonnet/invalid.jsonnet
@@ -0,0 +1,15 @@
+// Copyright 2015 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+error "Foo."
diff --git a/examples/jsonnet/invalid.out b/examples/jsonnet/invalid.out
new file mode 100644
index 0000000000..6c220f5170
--- /dev/null
+++ b/examples/jsonnet/invalid.out
@@ -0,0 +1,2 @@
+RUNTIME ERROR: Foo.
+ examples/jsonnet/invalid.jsonnet:15:1-12
diff --git a/examples/jsonnet/wordcount_golden.json b/examples/jsonnet/wordcount_golden.json
new file mode 100644
index 0000000000..25d99cf3ab
--- /dev/null
+++ b/examples/jsonnet/wordcount_golden.json
@@ -0,0 +1,53 @@
+{
+ "wordcount": {
+ "jobs": {
+ "count": {
+ "command": "uniq -c /tmp/sorted_tokens > /tmp/counts",
+ "deps": [
+ ":sort"
+ ],
+ "inputs": [
+ "/tmp/sorted_tokens"
+ ],
+ "outputs": [
+ "/tmp/counts"
+ ],
+ "type": "sh",
+ "vars": { }
+ },
+ "sort": {
+ "command": "sort /tmp/tokens > /tmp/sorted_tokens",
+ "deps": [
+ ":tokenize"
+ ],
+ "inputs": [
+ "/tmp/tokens"
+ ],
+ "outputs": [
+ "/tmp/sorted_tokens"
+ ],
+ "type": "sh",
+ "vars": { }
+ },
+ "tokenize": {
+ "command": "tr ' ' '\n' < /tmp/passage_test > /tmp/tokens",
+ "deps": [ ],
+ "inputs": [
+ "/tmp/passage_test"
+ ],
+ "outputs": [
+ "/tmp/tokens"
+ ],
+ "type": "sh",
+ "vars": { }
+ }
+ },
+ "retries": 12,
+ "schedule": {
+ "repeat_frequency": 1,
+ "repeat_type": "week",
+ "start_date": "2015-11-15",
+ "start_time": "17:30"
+ }
+ }
+}