mirror of
https://github.com/bazel-contrib/bazel-lib
synced 2024-11-30 01:41:21 +00:00
106 lines
2 KiB
Python
106 lines
2 KiB
Python
load("//lib/tests/jq:diff_test.bzl", "diff_test")
|
|
load("//lib:jq.bzl", "jq")
|
|
|
|
# Identity filter produces identical json
|
|
jq(
|
|
name = "case_dot_filter",
|
|
srcs = ["a.json"],
|
|
filter = ".",
|
|
)
|
|
|
|
diff_test(
|
|
name = "case_dot_filter_test",
|
|
file1 = "a_pretty.json",
|
|
file2 = ":case_dot_filter",
|
|
)
|
|
|
|
# Merge filter with slurp merges two jsons
|
|
jq(
|
|
name = "case_merge_filter",
|
|
srcs = [
|
|
"a.json",
|
|
"b.json",
|
|
],
|
|
args = ["--slurp"],
|
|
filter = ".[0] * .[1]",
|
|
)
|
|
|
|
diff_test(
|
|
name = "case_merge_filter_test",
|
|
file1 = "a_b_merged.json",
|
|
file2 = ":case_merge_filter",
|
|
)
|
|
|
|
# Use predeclared output
|
|
jq(
|
|
name = "case_predeclared_output",
|
|
srcs = ["a.json"],
|
|
out = "foo.json",
|
|
filter = ".",
|
|
)
|
|
|
|
diff_test(
|
|
name = "case_predeclared_output_test",
|
|
file1 = "a_pretty.json",
|
|
file2 = "foo.json",
|
|
)
|
|
|
|
# No sources produces null (equivalent to --null-input)
|
|
jq(
|
|
name = "case_no_sources",
|
|
srcs = [],
|
|
filter = ".",
|
|
)
|
|
|
|
diff_test(
|
|
name = "case_no_sources_test",
|
|
file1 = ":case_no_sources",
|
|
file2 = "null.json",
|
|
)
|
|
|
|
# Sources with --null-input flag produces null
|
|
jq(
|
|
name = "case_null_input_flag",
|
|
srcs = ["a.json"],
|
|
args = ["--null-input"],
|
|
filter = ".",
|
|
)
|
|
|
|
diff_test(
|
|
name = "case_null_input_flag_test",
|
|
file1 = ":case_null_input_flag",
|
|
file2 = "null.json",
|
|
)
|
|
|
|
# Load filter from file
|
|
jq(
|
|
name = "case_filter_file",
|
|
srcs = [
|
|
"a.json",
|
|
"b.json",
|
|
],
|
|
args = ["--slurp"],
|
|
filter_file = "merge_filter.txt",
|
|
)
|
|
|
|
diff_test(
|
|
name = "case_filter_file_test",
|
|
file1 = "a_b_merged.json",
|
|
file2 = ":case_filter_file",
|
|
)
|
|
|
|
# Call jq within a genrule
|
|
genrule(
|
|
name = "case_genrule",
|
|
srcs = ["a.json"],
|
|
outs = ["genrule_output.json"],
|
|
cmd = "$(JQ_BIN) '.' $(location a.json) > $@",
|
|
toolchains = ["@jq_toolchains//:resolved_toolchain"],
|
|
)
|
|
|
|
diff_test(
|
|
name = "case_genrule_test",
|
|
file1 = "genrule_output.json",
|
|
file2 = "a_pretty.json",
|
|
)
|