yq: allow any filename in srcs (#496)

* yq: allow any filename in srcs

* yq: add test cases for free-form file extensions in input

* run buildifier

---------

Co-authored-by: Alex Eagle <alex@aspect.dev>
This commit is contained in:
peter woodman 2023-08-30 12:18:10 -04:00 committed by GitHub
parent 594fb03874
commit 3e9577ab16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 1 deletions

View File

@ -4,7 +4,7 @@ load("//lib:stamping.bzl", "STAMP_ATTRS", "maybe_stamp")
_yq_attrs = dict({
"srcs": attr.label_list(
allow_files = [".yaml", ".json", ".xml"],
allow_files = True,
mandatory = True,
allow_empty = True,
),

View File

@ -1,6 +1,7 @@
load("//lib/private:diff_test.bzl", "diff_test")
load("//lib:yq.bzl", "yq")
load("//lib:testing.bzl", "assert_contains")
load("//lib:copy_file.bzl", "copy_file")
exports_files(
[
@ -9,6 +10,18 @@ exports_files(
visibility = ["//visibility:public"],
)
copy_file(
name = "yaml_otherextension",
src = "a.yaml",
out = "a.whatever",
)
copy_file(
name = "json_otherextension",
src = "//lib/tests/jq:a_pretty.json",
out = "a.dealerschoice",
)
# Identity (dot) expression produces identical yaml
yq(
name = "case_dot_expression",
@ -22,6 +35,18 @@ diff_test(
file2 = ":case_dot_expression",
)
yq(
name = "case_dot_expression_otherextension",
srcs = ["a.whatever"],
expression = ".",
)
diff_test(
name = "case_dot_expression_otherextension_test",
file1 = "a.whatever",
file2 = ":case_dot_expression_otherextension",
)
# No expression same as dot expression
yq(
name = "case_no_expression",
@ -34,6 +59,17 @@ diff_test(
file2 = ":case_no_expression",
)
yq(
name = "case_no_expression_otherextension",
srcs = ["a.whatever"],
)
diff_test(
name = "case_no_expression_otherextension_test",
file1 = "a.whatever",
file2 = ":case_no_expression",
)
# Output json, no out declared
yq(
name = "case_json_output_no_out",
@ -48,6 +84,19 @@ diff_test(
file2 = "case_json_output_no_out.json",
)
yq(
name = "case_json_output_no_out_otherextension",
srcs = ["a.whatever"],
args = ["-o=json"],
expression = ".",
)
diff_test(
name = "case_json_output_no_out_otherextension_test",
file1 = "//lib/tests/jq:a_pretty.json",
file2 = "case_json_output_no_out.json",
)
# Output json, outs has ".json" extension but "-o=json" not set
yq(
name = "case_json_output_no_arg",
@ -77,6 +126,19 @@ diff_test(
file2 = ":case_convert_json_to_yaml",
)
yq(
name = "case_convert_json_to_yaml_otherextension",
srcs = ["a.dealerschoice"],
args = ["-P"],
expression = ".",
)
diff_test(
name = "case_convert_json_to_yaml_otherextension_test",
file1 = "a.yaml",
file2 = ":case_convert_json_to_yaml",
)
# No srcs, output is a generated expression
yq(
name = "case_generate_from_expression",