Search in sources :

Example 6 with RuleFunction

use of com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testIntDefaultValue.

@Test
public void testIntDefaultValue() throws Exception {
    evalAndExport("def impl(ctx): return None", "r1 = rule(impl, attrs = {'a1': attr.int(default = 40+2)})");
    RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
    Attribute a = c.getAttributeByName("a1");
    assertEquals(42, a.getDefaultValueForTesting());
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 7 with RuleFunction

use of com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testRuleAddAttribute.

@Test
public void testRuleAddAttribute() throws Exception {
    evalAndExport("def impl(ctx): return None", "r1 = rule(impl, attrs={'a1': attr.string()})");
    RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
    assertTrue(c.hasAttr("a1", Type.STRING));
}
Also used : RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 8 with RuleFunction

use of com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testRuleLabelDefaultValue.

@Test
public void testRuleLabelDefaultValue() throws Exception {
    evalAndExport("def impl(ctx): return None\n" + "r1 = rule(impl, attrs = {'a1': " + "attr.label(default = Label('//foo:foo'), allow_files=True)})");
    RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
    Attribute a = c.getAttributeByName("a1");
    assertThat(a.getDefaultValueForTesting()).isInstanceOf(Label.class);
    assertEquals("//foo:foo", a.getDefaultValueForTesting().toString());
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 9 with RuleFunction

use of com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testOutputToGenfiles.

@Test
public void testOutputToGenfiles() throws Exception {
    evalAndExport("def impl(ctx): pass", "r1 = rule(impl, output_to_genfiles=True)");
    RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
    assertFalse(c.hasBinaryOutput());
}
Also used : RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Aggregations

RuleClass (com.google.devtools.build.lib.packages.RuleClass)9 RuleFunction (com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction)9 Test (org.junit.Test)9 Attribute (com.google.devtools.build.lib.packages.Attribute)2 ImplicitOutputsFunction (com.google.devtools.build.lib.packages.ImplicitOutputsFunction)1