Reformat .bzl files with buildifier and add format check.
Buildifier 0.12.0 includes initial support for reformatting .bzl files.
- Reformat all the bzl files.
- Expand the travis check to check the .bzl files also.
diff --git a/tests/shell_tests.bzl b/tests/shell_tests.bzl
index d0a9769..18b7bc7 100644
--- a/tests/shell_tests.bzl
+++ b/tests/shell_tests.bzl
@@ -14,98 +14,94 @@
"""Unit tests for shell.bzl."""
-load("//:lib.bzl", "shell", "asserts", "unittest")
-
+load("//:lib.bzl", "asserts", "shell", "unittest")
def _shell_array_literal_test(ctx):
- """Unit tests for shell.array_literal."""
- env = unittest.begin(ctx)
+ """Unit tests for shell.array_literal."""
+ env = unittest.begin(ctx)
- asserts.equals(env, "()", shell.array_literal([]))
- asserts.equals(env, "('1')", shell.array_literal([1]))
- asserts.equals(env, "('1' '2' '3')", shell.array_literal([1, 2, 3]))
- asserts.equals(env, "('$foo')", shell.array_literal(["$foo"]))
- asserts.equals(env, "('qu\"o\"te')", shell.array_literal(['qu"o"te']))
+ asserts.equals(env, "()", shell.array_literal([]))
+ asserts.equals(env, "('1')", shell.array_literal([1]))
+ asserts.equals(env, "('1' '2' '3')", shell.array_literal([1, 2, 3]))
+ asserts.equals(env, "('$foo')", shell.array_literal(["$foo"]))
+ asserts.equals(env, "('qu\"o\"te')", shell.array_literal(['qu"o"te']))
- unittest.end(env)
+ unittest.end(env)
shell_array_literal_test = unittest.make(_shell_array_literal_test)
-
def _shell_quote_test(ctx):
- """Unit tests for shell.quote."""
- env = unittest.begin(ctx)
+ """Unit tests for shell.quote."""
+ env = unittest.begin(ctx)
- asserts.equals(env, "'foo'", shell.quote("foo"))
- asserts.equals(env, "'foo bar'", shell.quote("foo bar"))
- asserts.equals(env, "'three spaces'", shell.quote("three spaces"))
- asserts.equals(env, "' leading'", shell.quote(" leading"))
- asserts.equals(env, "'trailing '", shell.quote("trailing "))
- asserts.equals(env, "'new\nline'", shell.quote("new\nline"))
- asserts.equals(env, "'tab\tcharacter'", shell.quote("tab\tcharacter"))
- asserts.equals(env, "'$foo'", shell.quote("$foo"))
- asserts.equals(env, "'qu\"o\"te'", shell.quote('qu"o"te'))
- asserts.equals(env, "'it'\\''s'", shell.quote("it's"))
- asserts.equals(env, "'foo\\bar'", shell.quote(r"foo\bar"))
- asserts.equals(env, "'back`echo q`uote'", shell.quote(r"back`echo q`uote"))
+ asserts.equals(env, "'foo'", shell.quote("foo"))
+ asserts.equals(env, "'foo bar'", shell.quote("foo bar"))
+ asserts.equals(env, "'three spaces'", shell.quote("three spaces"))
+ asserts.equals(env, "' leading'", shell.quote(" leading"))
+ asserts.equals(env, "'trailing '", shell.quote("trailing "))
+ asserts.equals(env, "'new\nline'", shell.quote("new\nline"))
+ asserts.equals(env, "'tab\tcharacter'", shell.quote("tab\tcharacter"))
+ asserts.equals(env, "'$foo'", shell.quote("$foo"))
+ asserts.equals(env, "'qu\"o\"te'", shell.quote('qu"o"te'))
+ asserts.equals(env, "'it'\\''s'", shell.quote("it's"))
+ asserts.equals(env, "'foo\\bar'", shell.quote("foo\\bar"))
+ asserts.equals(env, "'back`echo q`uote'", shell.quote("back`echo q`uote"))
- unittest.end(env)
+ unittest.end(env)
shell_quote_test = unittest.make(_shell_quote_test)
-
def _shell_spawn_e2e_test_impl(ctx):
- """Test spawning a real shell."""
- args = [
- "foo",
- "foo bar",
- "three spaces",
- " leading",
- "trailing ",
- "new\nline",
- "tab\tcharacter",
- "$foo",
- 'qu"o"te',
- "it's",
- r"foo\bar",
- "back`echo q`uote",
- ]
- script_content = "\n".join([
- "#!/bin/bash",
- "myarray=" + shell.array_literal(args),
- 'output=$(echo "${myarray[@]}")',
- # For logging:
- 'echo "DEBUG: output=[${output}]" >&2',
- # The following is a shell representation of what the echo of the quoted
- # array will look like. It looks a bit confusing considering it's shell
- # quoted into Python. Shell using single quotes to minimize shell
- # escaping, so only the single quote needs to be escaped as '\'', all
- # others are essentially kept literally.
- "expected='foo foo bar three spaces leading trailing new",
- "line tab\tcharacter $foo qu\"o\"te it'\\''s foo\\bar back`echo q`uote'",
- '[[ "${output}" == "${expected}" ]]',
- ])
- script_file = ctx.actions.declare_file("%s.sh" % (ctx.label.name))
- ctx.actions.write(
- output = script_file,
- content = script_content,
- is_executable = True,
- )
- return [
- DefaultInfo(executable=script_file),
- ]
+ """Test spawning a real shell."""
+ args = [
+ "foo",
+ "foo bar",
+ "three spaces",
+ " leading",
+ "trailing ",
+ "new\nline",
+ "tab\tcharacter",
+ "$foo",
+ 'qu"o"te',
+ "it's",
+ "foo\\bar",
+ "back`echo q`uote",
+ ]
+ script_content = "\n".join([
+ "#!/bin/bash",
+ "myarray=" + shell.array_literal(args),
+ 'output=$(echo "${myarray[@]}")',
+ # For logging:
+ 'echo "DEBUG: output=[${output}]" >&2',
+ # The following is a shell representation of what the echo of the quoted
+ # array will look like. It looks a bit confusing considering it's shell
+ # quoted into Python. Shell using single quotes to minimize shell
+ # escaping, so only the single quote needs to be escaped as '\'', all
+ # others are essentially kept literally.
+ "expected='foo foo bar three spaces leading trailing new",
+ "line tab\tcharacter $foo qu\"o\"te it'\\''s foo\\bar back`echo q`uote'",
+ '[[ "${output}" == "${expected}" ]]',
+ ])
+ script_file = ctx.actions.declare_file("%s.sh" % (ctx.label.name))
+ ctx.actions.write(
+ output = script_file,
+ content = script_content,
+ is_executable = True,
+ )
+ return [
+ DefaultInfo(executable = script_file),
+ ]
shell_spawn_e2e_test = rule(
test = True,
implementation = _shell_spawn_e2e_test_impl,
)
-
def shell_test_suite():
- """Creates the test targets and test suite for shell.bzl tests."""
- unittest.suite(
- "shell_tests",
- shell_array_literal_test,
- shell_quote_test,
- shell_spawn_e2e_test,
- )
+ """Creates the test targets and test suite for shell.bzl tests."""
+ unittest.suite(
+ "shell_tests",
+ shell_array_literal_test,
+ shell_quote_test,
+ shell_spawn_e2e_test,
+ )