aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLászló Csomor <laszlocsomor@users.noreply.github.com>2019-05-09 15:29:44 +0200
committerGitHub <noreply@github.com>2019-05-09 15:29:44 +0200
commit6bf64439752b2a98418a731ff21eb9d58ed5631c (patch)
treeb7800c4abd43c2c2c690e2b3605f8c14de7df1ad /tests
parent67ecd632735a45267da051003d7eaf8d8ca1b998 (diff)
downloadbazel-skylib-6bf64439752b2a98418a731ff21eb9d58ed5631c.tar.gz
write_file: support different line endings (#150)
The user can specify which line endings they want write_file to use. This helps avoiding line ending mismatches with diff_test. Example: diff_test verifies that a rule generates correct output by comparing it to a checked-in "golden" file. Both files are text files, and the user builds on Windows but the golden file was written on Linux and git checkout preserved original line endings. Without explicitly specifying which line endings to use, this diff_test would fail on an otherwise good output. With explicit line endings we don't need to check in the golden file to git, we can just generate it with "auto" line endings.
Diffstat (limited to 'tests')
-rw-r--r--tests/write_file/BUILD47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/write_file/BUILD b/tests/write_file/BUILD
index 321bcc0..9ea3609 100644
--- a/tests/write_file/BUILD
+++ b/tests/write_file/BUILD
@@ -32,6 +32,7 @@
# field of it, so we assert that that field contains the output file of the
# rule
+load("//rules:diff_test.bzl", "diff_test")
load("//rules:write_file.bzl", "write_file")
licenses(["notice"])
@@ -117,3 +118,49 @@ write_file(
],
is_executable = True,
)
+
+write_file(
+ name = "newline_unix_actual",
+ out = "out/newline_unix_actual.txt",
+ content = [
+ "ab",
+ "cd",
+ "ef",
+ ],
+ newline = "unix",
+)
+
+write_file(
+ name = "newline_unix_exp",
+ out = "out/newline_unix_exp.txt",
+ content = ["ab\ncd\nef"],
+)
+
+diff_test(
+ name = "unix_line_ending_test",
+ file1 = ":newline_unix_actual",
+ file2 = ":newline_unix_exp",
+)
+
+write_file(
+ name = "newline_win_actual",
+ out = "out/newline_win_actual.txt",
+ content = [
+ "ab",
+ "cd",
+ "ef",
+ ],
+ newline = "windows",
+)
+
+write_file(
+ name = "newline_win_exp",
+ out = "out/newline_win_exp.txt",
+ content = ["ab\r\ncd\r\nef"],
+)
+
+diff_test(
+ name = "win_line_ending_test",
+ file1 = ":newline_win_actual",
+ file2 = ":newline_win_exp",
+)