use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCreateFileAction.
@Test
public void testCreateFileAction() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
evalRuleContextCode(ruleContext, "ruleContext.file_action(", " output = ruleContext.files.srcs[0],", " content = 'hello world',", " executable = False)");
FileWriteAction action = (FileWriteAction) Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
assertEquals("foo/a.txt", Iterables.getOnlyElement(action.getOutputs()).getExecPathString());
assertEquals("hello world", action.getFileContents());
assertFalse(action.makeExecutable());
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testBadParamTypeErrorMessage.
@Test
public void testBadParamTypeErrorMessage() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
checkErrorContains(ruleContext, "method ctx.file_action(output: File, content: string, executable: bool) is not applicable " + "for arguments (File, int, bool): 'content' is 'int', but should be 'string'", "ruleContext.file_action(", " output = ruleContext.files.srcs[0],", " content = 1,", " executable = False)");
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testStructPlusArtifactErrorMessage.
@Test
public void testStructPlusArtifactErrorMessage() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
checkErrorContains(ruleContext, "unsupported operand type(s) for +: 'File' and 'struct'", "ruleContext.files.tools[0] + struct(a = 1)");
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testRunfilesArtifactsFromNestedSetArtifacts.
@Test
public void testRunfilesArtifactsFromNestedSetArtifacts() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ftb = depset() + ruleContext.files.srcs", "ruleContext.runfiles(transitive_files = ftb)");
assertEquals(ActionsTestUtil.baseArtifactNames(getRunfileArtifacts(result)), ImmutableList.of("a.txt", "b.img"));
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testRunfilesArtifactsFromIterableArtifacts.
@Test
public void testRunfilesArtifactsFromIterableArtifacts() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "artifacts = ruleContext.files.srcs", "ruleContext.runfiles(files = artifacts)");
assertEquals(ActionsTestUtil.baseArtifactNames(getRunfileArtifacts(result)), ImmutableList.of("a.txt", "b.img"));
}
Aggregations