Search in sources :

Example 1 with SkylarkClassObjectConstructor

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

the class SkylarkRuleClassFunctionsTest method declaredProvidersConcatSuccess.

@Test
public void declaredProvidersConcatSuccess() throws Exception {
    evalAndExport("data = provider()", "dx = data(x = 1)", "dy = data(y = 'abc')", "dxy = dx + dy", "x = dxy.x", "y = dxy.y");
    assertThat(lookup("x")).isEqualTo(1);
    assertThat(lookup("y")).isEqualTo("abc");
    SkylarkClassObjectConstructor dataConstructor = (SkylarkClassObjectConstructor) lookup("data");
    SkylarkClassObject dx = (SkylarkClassObject) lookup("dx");
    assertThat(dx.getConstructor()).isEqualTo(dataConstructor);
    SkylarkClassObject dy = (SkylarkClassObject) lookup("dy");
    assertThat(dy.getConstructor()).isEqualTo(dataConstructor);
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkClassObjectConstructor(com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor) Test(org.junit.Test)

Example 2 with SkylarkClassObjectConstructor

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

the class SkylarkRuleClassFunctionsTest method multipleTopLevels.

@Test
public void multipleTopLevels() throws Exception {
    evalAndExport("p = provider()", "p1 = p");
    SkylarkClassObjectConstructor p = (SkylarkClassObjectConstructor) lookup("p");
    SkylarkClassObjectConstructor p1 = (SkylarkClassObjectConstructor) lookup("p1");
    assertThat(p).isEqualTo(p1);
    assertThat(p.getKey()).isEqualTo(new SkylarkClassObjectConstructor.SkylarkKey(FAKE_LABEL, "p"));
    assertThat(p1.getKey()).isEqualTo(new SkylarkClassObjectConstructor.SkylarkKey(FAKE_LABEL, "p"));
}
Also used : SkylarkClassObjectConstructor(com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor) Test(org.junit.Test)

Example 3 with SkylarkClassObjectConstructor

use of com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor 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 4 with SkylarkClassObjectConstructor

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

the class SkylarkRuleClassFunctionsTest method fancyExports.

@Test
public void fancyExports() throws Exception {
    evalAndExport("def _impla(target, ctx): pass", "p, (a, p1) = [", "   provider(),", "   [ aspect(_impla),", "     provider() ]", "]");
    SkylarkClassObjectConstructor p = (SkylarkClassObjectConstructor) lookup("p");
    SkylarkAspect a = (SkylarkAspect) lookup("a");
    SkylarkClassObjectConstructor p1 = (SkylarkClassObjectConstructor) lookup("p1");
    assertThat(p.getPrintableName()).isEqualTo("p");
    assertThat(p.getKey()).isEqualTo(new SkylarkClassObjectConstructor.SkylarkKey(FAKE_LABEL, "p"));
    assertThat(p1.getPrintableName()).isEqualTo("p1");
    assertThat(p1.getKey()).isEqualTo(new SkylarkClassObjectConstructor.SkylarkKey(FAKE_LABEL, "p1"));
    assertThat(a.getAspectClass()).isEqualTo(new SkylarkAspectClass(FAKE_LABEL, "a"));
}
Also used : SkylarkAspectClass(com.google.devtools.build.lib.packages.SkylarkAspectClass) SkylarkAspect(com.google.devtools.build.lib.packages.SkylarkAspect) SkylarkClassObjectConstructor(com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor) Test(org.junit.Test)

Aggregations

SkylarkClassObjectConstructor (com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor)4 Test (org.junit.Test)4 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)2 SkylarkAspect (com.google.devtools.build.lib.packages.SkylarkAspect)1 SkylarkAspectClass (com.google.devtools.build.lib.packages.SkylarkAspectClass)1