diff options
author | 2016-06-20 11:44:06 +0000 | |
---|---|---|
committer | 2016-06-21 09:57:38 +0000 | |
commit | fc6100505ca52aa3bd488b19360f2bd2706aea98 (patch) | |
tree | 781bce14825cb31ce84001346d42ffca4ff63d96 /src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java | |
parent | 2ee0377d835af26a6488ad7b80291953860c4dce (diff) |
Fixed more Bazel tests on Windows by using the right line separator
Newly passing:
//src/test/java/com/google/devtools/build/...
lib:syntax_test
lib/skylark:SkylarkTests
lib:analysis_actions_test
lib:pkgcache_test
--
Change-Id: Iefdcf9e90ad28e664126aa7269487db95da1000a
Reviewed-on: https://bazel-review.googlesource.com/#/c/3840
MOS_MIGRATED_REVID=125324588
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java index e41b90c134..78067a70db 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java @@ -47,6 +47,7 @@ import com.google.devtools.build.lib.syntax.SkylarkList.MutableList; import com.google.devtools.build.lib.syntax.SkylarkNestedSet; import com.google.devtools.build.lib.testutil.MoreAsserts; +import com.google.devtools.build.lib.util.OsUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -71,8 +72,14 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { @Param(name = "mandatory", doc = ""), @Param(name = "optional", doc = "", defaultValue = "None"), @Param(name = "mandatory_key", doc = "", positional = false, named = true), - @Param(name = "optional_key", doc = "", defaultValue = "'x'", - positional = false, named = true)}, + @Param( + name = "optional_key", + doc = "", + defaultValue = "'x'", + positional = false, + named = true + ) + }, useEnvironment = true ) private BuiltinFunction mockFunc; @@ -85,7 +92,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { BuiltinFunction throwFunction; @Before - public final void createBuildFile() throws Exception { + public final void createBuildFile() throws Exception { scratch.file( "foo/BUILD", "genrule(name = 'foo',", @@ -126,7 +133,10 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { new BuiltinFunction("mock") { @SuppressWarnings("unused") public Object invoke( - Object mandatory, Object optional, Object mandatoryKey, Object optionalKey, + Object mandatory, + Object optional, + Object mandatoryKey, + Object optionalKey, Environment env) { return EvalUtils.optionMap( env, @@ -230,8 +240,8 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions()); assertArtifactFilenames(action.getInputs(), "a.txt", "b.img"); assertArtifactFilenames(action.getOutputs(), "a.txt", "b.img"); - MoreAsserts.assertContainsSublist(action.getArguments(), - "-c", "dummy_command", "", "--a", "--b"); + MoreAsserts.assertContainsSublist( + action.getArguments(), "-c", "dummy_command", "", "--a", "--b"); assertEquals("DummyMnemonic", action.getMnemonic()); assertEquals("dummy_message", action.getProgressMessage()); assertEquals(targetConfig.getLocalShellEnvironment(), action.getEnvironment()); @@ -409,7 +419,6 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { " inputs = ctx.files.srcs,", " mnemonic = 'EA',", " )", - "empty_action_rule = rule(", " implementation = _impl,", " attrs = {", @@ -422,11 +431,9 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { "load('/test/empty', 'empty_action_rule')", "empty_action_rule(name = 'my_empty_action',", " srcs = ['foo.in', 'other_foo.in'])", - "action_listener(name = 'listener',", " mnemonics = ['EA'],", " extra_actions = [':extra'])", - "extra_action(name = 'extra',", " cmd='')"); @@ -480,15 +487,16 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { assertMatches( "Expanded string", expectedPattern, - (String) evalRuleContextCode( - ruleContext, String.format("ruleContext.expand_location('$(%s)')", command))); + (String) + evalRuleContextCode( + ruleContext, String.format("ruleContext.expand_location('$(%s)')", command))); } private void assertMatches(String description, String expectedPattern, String computedValue) throws Exception { assertTrue( - Printer.format("%s %r did not match pattern '%s'", - description, computedValue, expectedPattern), + Printer.format( + "%s %r did not match pattern '%s'", description, computedValue, expectedPattern), Pattern.matches(expectedPattern, computedValue)); } @@ -502,7 +510,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { @SuppressWarnings("unchecked") List<String> argv = (List<String>) (List<?>) (MutableList) lookup("argv"); assertThat(argv).hasSize(3); - assertMatches("argv[0]", "^.*/bash$", argv.get(0)); + assertMatches("argv[0]", "^.*/bash" + OsUtils.executableExtension() + "$", argv.get(0)); assertThat(argv.get(1)).isEqualTo("-c"); assertThat(argv.get(2)).isEqualTo("I got the World on a string"); } @@ -537,11 +545,11 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { @SuppressWarnings("unchecked") List<String> argv = (List<String>) (List<?>) (MutableList) lookup("argv"); assertThat(argv).hasSize(3); - assertMatches("argv[0]", "^.*/bash$", argv.get(0)); + assertMatches("argv[0]", "^.*/bash" + OsUtils.executableExtension() + "$", argv.get(0)); assertThat(argv.get(1)).isEqualTo("-c"); assertMatches("argv[2]", "A.*/mytool .*/mytool.sh B.*file3.dat", argv.get(2)); } - + @Test public void testResolveCommandExecutionRequirements() throws Exception { // Tests that requires-darwin execution requirements result in the usage of /bin/bash. @@ -567,7 +575,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { @SuppressWarnings("unchecked") List<String> argv = (List<String>) (List<?>) (MutableList) lookup("argv"); assertThat(argv).hasSize(2); - assertMatches("argv[0]", "^.*/bash$", argv.get(0)); + assertMatches("argv[0]", "^.*/bash" + OsUtils.executableExtension() + "$", argv.get(0)); assertMatches("argv[1]", "^.*/resolve_me[.]script[.]sh$", argv.get(1)); } @@ -857,7 +865,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { String java = (String) evalRuleContextCode(ctx, "ruleContext.var['JAVA']"); // Get the last path segment java = java.substring(java.lastIndexOf('/')); - assertEquals("/java", java); + assertEquals("/java" + OsUtils.executableExtension(), java); } @Test @@ -908,9 +916,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { fail( String.format( "Found %d error(s), but none with the expected message '%s'. First error: '%s'", - count, - errorMsg, - first)); + count, errorMsg, first)); } } finally { eventCollector.clear(); @@ -953,7 +959,8 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { @Test public void testGlobInImplicitOutputs() throws Exception { - scratch.file("test/glob.bzl", + scratch.file( + "test/glob.bzl", "def _impl(ctx):", " ctx.empty_action(", " inputs = [],", @@ -964,7 +971,8 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { " implementation = _impl,", " outputs = _foo,", ")"); - scratch.file("test/BUILD", + scratch.file( + "test/BUILD", "load('/test/glob', 'glob_rule')", "glob_rule(name = 'my_glob',", " srcs = ['foo.bar', 'other_foo.bar'])"); @@ -975,15 +983,9 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { @Test public void testRuleFromBzlFile() throws Exception { - scratch.file("test/rule.bzl", - "def _impl(ctx): return", - "foo = rule(implementation = _impl)"); - scratch.file("test/ext.bzl", - "load('//test:rule.bzl', 'foo')", - "a = 1", - "foo(name = 'x')"); - scratch.file("test/BUILD", - "load('//test:ext.bzl', 'a')"); + scratch.file("test/rule.bzl", "def _impl(ctx): return", "foo = rule(implementation = _impl)"); + scratch.file("test/ext.bzl", "load('//test:rule.bzl', 'foo')", "a = 1", "foo(name = 'x')"); + scratch.file("test/BUILD", "load('//test:ext.bzl', 'a')"); reporter.removeHandler(failFastHandler); getConfiguredTarget("//test:x"); assertContainsEvent("Cannot instantiate a rule when loading a .bzl file"); @@ -991,7 +993,8 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { @Test public void testImplicitOutputsFromGlob() throws Exception { - scratch.file("test/glob.bzl", + scratch.file( + "test/glob.bzl", "def _impl(ctx):", " outs = ctx.outputs", " for i in ctx.attr.srcs:", @@ -1015,7 +1018,8 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { ")"); scratch.file("test/a.bar", "a"); scratch.file("test/b.bar", "b"); - scratch.file("test/BUILD", + scratch.file( + "test/BUILD", "load('/test/glob', 'glob_rule')", "glob_rule(name = 'my_glob', srcs = glob(['*.bar']))"); ConfiguredTarget ct = getConfiguredTarget("//test:my_glob"); |