use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testNoAccessToCreatedActionsWithoutSkylarkTest.
@Test
public void testNoAccessToCreatedActionsWithoutSkylarkTest() throws Exception {
scratch.file("test/rules.bzl", getSimpleNontestableUnderTestDefinition("ctx.action(outputs=[out], command='echo foo123 > ' + out.path)"));
scratch.file("test/BUILD", "load(':rules.bzl', 'undertest_rule')", "undertest_rule(", " name = 'undertest',", ")");
SkylarkRuleContext ruleContext = createRuleContext("//test:undertest");
Object result = evalRuleContextCode(ruleContext, "ruleContext.created_actions()");
assertThat(result).isEqualTo(Runtime.NONE);
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testNoAccessToDependencyActionsWithoutSkylarkTest.
@Test
public void testNoAccessToDependencyActionsWithoutSkylarkTest() throws Exception {
reporter.removeHandler(failFastHandler);
scratch.file("test/rules.bzl", getSimpleNontestableUnderTestDefinition("ctx.action(outputs=[out], command='echo foo123 > ' + out.path)"), testingRuleDefinition);
scratch.file("test/BUILD", simpleBuildDefinition);
SkylarkRuleContext ruleContext = createRuleContext("//test:testing");
try {
evalRuleContextCode(ruleContext, "ruleContext.attr.dep[Actions]");
fail("Should have failed due to trying to access actions of a rule not marked " + "_skylark_testable");
} catch (Exception e) {
assertThat(e).hasMessage("Object of type Target doesn't contain declared provider Actions");
}
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testGetExecutablePrerequisite.
@Test
public void testGetExecutablePrerequisite() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:androidlib");
Object result = evalRuleContextCode(ruleContext, "ruleContext.executable._jarjar_bin");
assertThat(((Artifact) result).getFilename()).matches("^jarjar_bin(\\.cmd){0,1}$");
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testGetRuleAttributeStringTypeValueNoGet.
@Test
public void testGetRuleAttributeStringTypeValueNoGet() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.cmd");
assertEquals("dummy_cmd", (String) result);
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testStringKeyedLabelDictAttributeInSkylarkRuleContext.
@Test
public void testStringKeyedLabelDictAttributeInSkylarkRuleContext() throws Exception {
scratch.file("jvm/BUILD", "java_runtime(name='runtime', srcs=[], java_home='')", "java_runtime_suite(", " name = 'suite',", " runtimes = {'x86': ':runtime'},", " default = ':runtime',", ")");
invalidatePackages();
SkylarkRuleContext ruleContext = createRuleContext("//jvm:suite");
assertNoEvents();
String keyString = (String) evalRuleContextCode(ruleContext, "ruleContext.attr.runtimes.keys()[0]");
assertThat(keyString).isEqualTo("x86");
Label valueLabel = (Label) evalRuleContextCode(ruleContext, "ruleContext.attr.runtimes.values()[0]");
assertThat(valueLabel).isEqualTo(Label.parseAbsolute("//jvm:runtime"));
}
Aggregations