Search in sources :

Example 26 with SkylarkClassObject

use of com.google.devtools.build.lib.packages.SkylarkClassObject in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method declaredProviders.

@Test
public void declaredProviders() throws Exception {
    evalAndExport("data = provider()", "d = data(x = 1, y ='abc')", "d_x = d.x", "d_y = d.y");
    assertThat(lookup("d_x")).isEqualTo(1);
    assertThat(lookup("d_y")).isEqualTo("abc");
    SkylarkClassObjectConstructor dataConstructor = (SkylarkClassObjectConstructor) lookup("data");
    SkylarkClassObject data = (SkylarkClassObject) lookup("d");
    assertThat(data.getConstructor()).isEqualTo(dataConstructor);
    assertThat(dataConstructor.isExported()).isTrue();
    assertThat(dataConstructor.getPrintableName()).isEqualTo("data");
    assertThat(dataConstructor.getKey()).isEqualTo(new SkylarkClassObjectConstructor.SkylarkKey(FAKE_LABEL, "data"));
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkClassObjectConstructor(com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor) Test(org.junit.Test)

Example 27 with SkylarkClassObject

use of com.google.devtools.build.lib.packages.SkylarkClassObject in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testStructConcatenationFieldNames.

@Test
public void testStructConcatenationFieldNames() throws Exception {
    // TODO(fwe): cannot be handled by current testing suite
    eval("x = struct(a = 1, b = 2)", "y = struct(c = 1, d = 2)", "z = x + y\n");
    SkylarkClassObject z = (SkylarkClassObject) lookup("z");
    assertEquals(ImmutableSet.of("a", "b", "c", "d"), z.getKeys());
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) Test(org.junit.Test)

Aggregations

SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)27 Test (org.junit.Test)15 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)10 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)9 EvalException (com.google.devtools.build.lib.syntax.EvalException)6 Location (com.google.devtools.build.lib.events.Location)4 SkylarkClassObjectConstructor (com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor)4 ClassObject (com.google.devtools.build.lib.syntax.ClassObject)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Artifact (com.google.devtools.build.lib.actions.Artifact)3 FileConfiguredTarget (com.google.devtools.build.lib.analysis.FileConfiguredTarget)2 RuleConfiguredTarget (com.google.devtools.build.lib.analysis.RuleConfiguredTarget)2 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)2 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)2 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)2 ClassObjectConstructor (com.google.devtools.build.lib.packages.ClassObjectConstructor)2 SkylarkKey (com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor.SkylarkKey)2 SkylarkRuleContext (com.google.devtools.build.lib.rules.SkylarkRuleContext)2 Environment (com.google.devtools.build.lib.syntax.Environment)2 Mutability (com.google.devtools.build.lib.syntax.Mutability)2