2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-11-27 17:43:27 +00:00
bazel-lib/lib/tests/jq/diff_test.bzl

37 lines
1 KiB
Python
Raw Normal View History

2021-12-09 00:47:45 +00:00
"""Override diff_test behaviour to ignore carriage returns in order to
test jq output on Windows. See https://github.com/stedolan/jq/issues/92.
"""
load("//lib:diff_test.bzl", _diff_test = "diff_test")
2021-12-09 00:47:45 +00:00
def diff_test(name, file1, file2):
"""Perform a diff_test ignoring carriage returns
Args:
name: name of the test rule
file1: first file to compare
file2: second file to compare
"""
test_files = []
for i, file in enumerate([file1, file2], start = 1):
if file[0] == ":":
target = file[1:]
else:
target = file
stripped_file = "%s_file%d_stripped" % (name, i)
native.genrule(
name = "%s_file%d" % (name, i),
srcs = [file],
outs = [stripped_file],
cmd = "cat $(execpath :{target}) | sed \"s#\\r##\" > $@".format(target = target),
)
test_files.append(stripped_file)
_diff_test(
name = name,
file1 = test_files[0],
file2 = test_files[1],
)