aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-04-26 08:29:24 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-26 08:31:14 -0700
commite4fda3b047a38dbd6edfcc36458f4a21e69062a1 (patch)
treea7f5b36796eeb0d017f9cde6170cb8ddaa78ee00 /src/test
parenta7f202c3ae18a66d5ad6e1292e098bb8bd13482b (diff)
Abstract away the param file write action from tests.
Rule authors frequently wants to make assertions on the parameter files their rule implementations have created. However, if they do not explicitly create parameter file write actions, or if indeed _there aren't_ any parameter file write actions inserted into the action graph, the tests will fail. This CL puts an abstraction between the tests and obtaining their parameter files, allowing us to change the implementation without updating hundreds of lines of test code in the same CL. Note that we can no longer sanely assert that the parameter file argument is inserted into the main command line, because the parameter file system controls both whether it is inserted and the name used. Those assertions have been removed where found. RELNOTES: None PiperOrigin-RevId: 194400070
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java40
1 files changed, 21 insertions, 19 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 01823ba1c9..71b1ca9c92 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
@@ -2178,24 +2178,26 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
@Test
public void testLazyArgsWithParamFile() throws Exception {
- SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
- evalRuleContextCode(
- ruleContext,
- "foo_args = ruleContext.actions.args()",
- "foo_args.add('--foo')",
- "foo_args.use_param_file('--file=%s', use_always=True)",
- "output=ruleContext.actions.declare_file('out')",
- "ruleContext.actions.run(",
- " inputs = depset(ruleContext.files.srcs),",
- " outputs = [output],",
- " arguments = [foo_args],",
- " executable = ruleContext.files.tools[0],",
- ")");
- List<ActionAnalysisMetadata> actions =
- ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions();
- assertThat(actions.stream().anyMatch(a -> a instanceof ParameterFileWriteAction)).isTrue();
- SpawnAction action =
- (SpawnAction) actions.stream().filter(a -> a instanceof SpawnAction).findAny().get();
+ scratch.file(
+ "test/main_rule.bzl",
+ "def _impl(ctx):",
+ " args = ctx.actions.args()",
+ " args.add('--foo')",
+ " args.use_param_file('--file=%s', use_always=True)",
+ " output=ctx.actions.declare_file('out')",
+ " ctx.actions.run_shell(",
+ " inputs = [output],",
+ " outputs = [output],",
+ " arguments = [args],",
+ " command = 'touch out',",
+ " )",
+ "main_rule = rule(implementation = _impl)");
+ scratch.file(
+ "test/BUILD", "load('//test:main_rule.bzl', 'main_rule')", "main_rule(name='main')");
+ ConfiguredTarget ct = getConfiguredTarget("//test:main");
+ Artifact output = getBinArtifact("out", ct);
+ SpawnAction action = (SpawnAction) getGeneratingAction(output);
+ assertThat(paramFileArgsForAction(action)).containsExactly("--foo");
// Assert that there is a file argument. Don't bother matching the exact string
assertThat(action.getArguments().stream().anyMatch(arg -> arg.matches("--file=.*"))).isTrue();
}
@@ -2218,7 +2220,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
actions.stream().filter(a -> a instanceof ParameterFileWriteAction).findFirst();
assertThat(action.isPresent()).isTrue();
ParameterFileWriteAction paramAction = (ParameterFileWriteAction) action.get();
- assertThat(paramAction.getContents()).containsExactly("--foo");
+ assertThat(paramAction.getArguments()).containsExactly("--foo");
}
@Test