use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testTemplateExpansionActionInterface.
@Test
public void testTemplateExpansionActionInterface() throws Exception {
scratch.file("test/rules.bzl", "def _undertest_impl(ctx):", " out = ctx.outputs.out", " ctx.template_action(output=out, template=ctx.file.template, substitutions={'a': 'b'})", "undertest_rule = rule(", " implementation = _undertest_impl,", " outputs = {'out': '%{name}.txt'},", " attrs = {'template': attr.label(allow_single_file=True)},", " _skylark_testable = True,", ")", testingRuleDefinition);
scratch.file("test/template.txt", "aaaaa", "bcdef");
scratch.file("test/BUILD", "load(':rules.bzl', 'undertest_rule', 'testing_rule')", "undertest_rule(", " name = 'undertest',", " template = ':template.txt',", ")", "testing_rule(", " name = 'testing',", " dep = ':undertest',", ")");
SkylarkRuleContext ruleContext = createRuleContext("//test:testing");
update("ruleContext", ruleContext);
update("file", eval("list(ruleContext.attr.dep.files)[0]"));
update("action", eval("ruleContext.attr.dep[Actions].by_file[file]"));
assertThat(eval("type(action)")).isEqualTo("Action");
Object contentUnchecked = eval("action.content");
assertThat(contentUnchecked).isInstanceOf(String.class);
assertThat(contentUnchecked).isEqualTo("bbbbb\nbcdef\n");
Object substitutionsUnchecked = eval("action.substitutions");
assertThat(substitutionsUnchecked).isInstanceOf(SkylarkDict.class);
assertThat(substitutionsUnchecked).isEqualTo(SkylarkDict.of(null, "a", "b"));
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testGetRuleAttributeListType.
@Test
public void testGetRuleAttributeListType() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.outs");
assertThat(result).isInstanceOf(SkylarkList.class);
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkFileHelperTest method testFilterFiltersFilesOut.
@Test
public void testFilterFiltersFilesOut() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "FileType(['.xyz']).filter(ruleContext.files.srcs)");
assertThat(((Iterable<?>) result)).isEmpty();
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkFileHelperTest method testFilterPasses.
@SuppressWarnings("unchecked")
@Test
public void testFilterPasses() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "FileType(['.img']).filter(ruleContext.files.srcs)");
assertEquals(ActionsTestUtil.baseNamesOf((Iterable<Artifact>) result), "b.img");
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkFileHelperTest method testArtifactPath.
@Test
public void testArtifactPath() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
String result = (String) evalRuleContextCode(ruleContext, "ruleContext.files.tools[0].path");
assertEquals("foo/t.exe", result);
}
Aggregations