From cdb6ef554397c1d3da7ee9921305f646bec5ae16 Mon Sep 17 00:00:00 2001 From: Dmitry Lomov Date: Fri, 5 Aug 2016 08:38:26 +0000 Subject: Make SkylarkClassObject "Bazel-specific". This in preparation to DeclaredProviders implementation. -- MOS_MIGRATED_REVID=129420617 --- .../lib/skylark/SkylarkRuleClassFunctionsTest.java | 220 ++++++++++++++++++++- .../build/lib/skylark/util/SkylarkTestCase.java | 1 + .../devtools/build/lib/syntax/EvalUtilsTest.java | 22 --- .../build/lib/syntax/MethodLibraryTest.java | 4 - .../build/lib/syntax/SkylarkEvaluationTest.java | 131 ------------ .../build/lib/syntax/SkylarkNestedSetTest.java | 26 +-- .../devtools/build/lib/syntax/ValidationTest.java | 31 +-- 7 files changed, 229 insertions(+), 206 deletions(-) (limited to 'src/test/java/com/google/devtools/build/lib') diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java index 65d0c48ab0..07a8c6b232 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.cmdline.Label; @@ -33,15 +34,23 @@ import com.google.devtools.build.lib.packages.PredicateWithMessage; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType; import com.google.devtools.build.lib.packages.SkylarkAspect; +import com.google.devtools.build.lib.packages.SkylarkClassObject; import com.google.devtools.build.lib.rules.SkylarkAttr; import com.google.devtools.build.lib.rules.SkylarkFileType; import com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions; import com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction; import com.google.devtools.build.lib.skylark.util.SkylarkTestCase; +import com.google.devtools.build.lib.syntax.ClassObject; +import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.EvalException; +import com.google.devtools.build.lib.syntax.EvalUtils; +import com.google.devtools.build.lib.syntax.SkylarkDict; +import com.google.devtools.build.lib.syntax.SkylarkList.MutableList; +import com.google.devtools.build.lib.syntax.SkylarkList.Tuple; +import com.google.devtools.build.lib.syntax.SkylarkNestedSet; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.util.FileTypeSet; - +import java.util.Collection; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -748,4 +757,213 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase { // Should succeed without a "licenses attribute is potentially configurable" loading error: createRuleContext("//third_party/foo:r"); } + + @Test + public void testStructCreation() throws Exception { + // TODO(fwe): cannot be handled by current testing suite + eval("x = struct(a = 1, b = 2)"); + assertThat(lookup("x")).isInstanceOf(ClassObject.class); + } + + @Test + public void testStructFields() throws Exception { + // TODO(fwe): cannot be handled by current testing suite + eval("x = struct(a = 1, b = 2)"); + ClassObject x = (ClassObject) lookup("x"); + assertEquals(1, x.getValue("a")); + assertEquals(2, x.getValue("b")); + } + + @Test + public void testStructAccessingFieldsFromSkylark() throws Exception { + eval("x = struct(a = 1, b = 2)", "x1 = x.a", "x2 = x.b"); + assertThat(lookup("x1")).isEqualTo(1); + assertThat(lookup("x2")).isEqualTo(2); + } + + @Test + public void testStructAccessingUnknownField() throws Exception { + checkErrorContains( + "'struct' object has no attribute 'c'\n" + "Available attributes: a, b", + "x = struct(a = 1, b = 2)", + "y = x.c"); + } + + @Test + public void testStructAccessingUnknownFieldWithArgs() throws Exception { + checkErrorContains( + "struct has no method 'c'", "x = struct(a = 1, b = 2)", "y = x.c()"); + } + + @Test + public void testStructAccessingNonFunctionFieldWithArgs() throws Exception { + checkErrorContains( + "struct field 'a' is not a function", "x = struct(a = 1, b = 2)", "x1 = x.a(1)"); + } + + @Test + public void testStructAccessingFunctionFieldWithArgs() throws Exception { + eval("def f(x): return x+5", "x = struct(a = f, b = 2)", "x1 = x.a(1)"); + assertThat(lookup("x1")).isEqualTo(6); + } + + @Test + public void testStructPosArgs() throws Exception { + checkErrorContains( + "struct(**kwargs) does not accept positional arguments, but got 1", "x = struct(1, b = 2)"); + } + + @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()); + } + + @Test + public void testStructConcatenationFieldValues() 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(1, z.getValue("a")); + assertEquals(2, z.getValue("b")); + assertEquals(1, z.getValue("c")); + assertEquals(2, z.getValue("d")); + } + + @Test + public void testStructConcatenationCommonFields() throws Exception { + checkErrorContains("Cannot concat structs with common field(s): a", + "x = struct(a = 1, b = 2)", "y = struct(c = 1, a = 2)", "z = x + y\n"); + } + + @Test + public void testConditionalStructConcatenation() throws Exception { + // TODO(fwe): cannot be handled by current testing suite + eval("def func():", + " x = struct(a = 1, b = 2)", + " if True:", + " x += struct(c = 1, d = 2)", + " return x", + "x = func()"); + SkylarkClassObject x = (SkylarkClassObject) lookup("x"); + assertEquals(1, x.getValue("a")); + assertEquals(2, x.getValue("b")); + assertEquals(1, x.getValue("c")); + assertEquals(2, x.getValue("d")); + } + + @Test + public void testGetattrNoAttr() throws Exception { + checkErrorContains("Object of type 'struct' has no attribute \"b\"", + "s = struct(a='val')", "getattr(s, 'b')"); + } + + @Test + public void testGetattr() throws Exception { + eval( + "s = struct(a='val')", + "x = getattr(s, 'a')", + "y = getattr(s, 'b', 'def')", + "z = getattr(s, 'b', default = 'def')", + "w = getattr(s, 'a', default='ignored')"); + assertThat(lookup("x")).isEqualTo("val"); + assertThat(lookup("y")).isEqualTo("def"); + assertThat(lookup("z")).isEqualTo("def"); + assertThat(lookup("w")).isEqualTo("val"); + } + + @Test + public void testHasattr() throws Exception { + eval("s = struct(a=1)", + "x = hasattr(s, 'a')", + "y = hasattr(s, 'b')\n"); + assertThat(lookup("x")).isEqualTo(true); + assertThat(lookup("y")).isEqualTo(false); + } + + @Test + public void testStructStr() throws Exception { + assertThat(eval("str(struct(x = 2, y = 3, z = 4))")) + .isEqualTo("struct(x = 2, y = 3, z = 4)"); + } + + @Test + public void testStructsInSets() throws Exception { + eval("set([struct(a='a')])"); + } + + @Test + public void testStructMembersAreImmutable() throws Exception { + checkErrorContains( + "can only assign to variables and tuples, not to 's.x'", + "s = struct(x = 'a')", + "s.x = 'b'\n"); + } + + @Test + public void testStructDictMembersAreImmutable() throws Exception { + checkErrorContains( + "can only assign to variables and tuples, not to 's.x['b']'", + "s = struct(x = {'a' : 1})", + "s.x['b'] = 2\n"); + } + + @Test + public void testNsetGoodCompositeItem() throws Exception { + eval("def func():", + " return set([struct(a='a')])", + "s = func()"); + Collection result = ((SkylarkNestedSet) lookup("s")).toCollection(); + assertThat(result).hasSize(1); + assertThat(result.iterator().next()).isInstanceOf(SkylarkClassObject.class); + } + + @Test + public void testNsetBadMutableItem() throws Exception { + checkEvalError("sets cannot contain mutable items", "set([([],)])"); + checkEvalError("sets cannot contain mutable items", "set([struct(a=[])])"); + } + + private static SkylarkClassObject makeStruct(String field, Object value) { + return new SkylarkClassObject(ImmutableMap.of(field, value)); + } + + private static SkylarkClassObject makeBigStruct(Environment env) { + // struct(a=[struct(x={1:1}), ()], b=(), c={2:2}) + return new SkylarkClassObject(ImmutableMap.of( + "a", MutableList.of(env, + new SkylarkClassObject(ImmutableMap.of( + "x", SkylarkDict.of(env, 1, 1))), + Tuple.of()), + "b", Tuple.of(), + "c", SkylarkDict.of(env, 2, 2))); + } + + @Test + public void testStructMutabilityShallow() throws Exception { + assertTrue(EvalUtils.isImmutable(makeStruct("a", 1))); + } + + private static MutableList makeList(Environment env) { + return MutableList.of(env, 1, 2, 3); + } + + + @Test + public void testStructMutabilityDeep() throws Exception { + assertTrue(EvalUtils.isImmutable(Tuple.of(makeList(null)))); + assertTrue(EvalUtils.isImmutable(makeStruct("a", makeList(null)))); + assertTrue(EvalUtils.isImmutable(makeBigStruct(null))); + + assertFalse(EvalUtils.isImmutable(Tuple.of(makeList(ev.getEnvironment())))); + assertFalse(EvalUtils.isImmutable(makeStruct("a", makeList(ev.getEnvironment())))); + assertFalse(EvalUtils.isImmutable(makeBigStruct(ev.getEnvironment()))); + } + } diff --git a/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java b/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java index cf17c9dbb3..5efd8a8209 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java @@ -149,6 +149,7 @@ public abstract class SkylarkTestCase extends BuildViewTestCase { } protected void checkErrorContains(String errorMsg, String... lines) throws Exception { + ev.setFailFast(false); try { eval(lines); fail("checkErrorContains(String, String...): There was no error"); diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java index 26763ea796..7ce40aa90c 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java @@ -19,8 +19,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import com.google.common.collect.ImmutableMap; -import com.google.devtools.build.lib.syntax.ClassObject.SkylarkClassObject; import com.google.devtools.build.lib.syntax.SkylarkList.MutableList; import com.google.devtools.build.lib.syntax.SkylarkList.Tuple; import com.google.devtools.build.lib.syntax.util.EvaluationTestCase; @@ -44,21 +42,6 @@ public class EvalUtilsTest extends EvaluationTestCase { return SkylarkDict.of(env, 1, 1, 2, 2); } - private static SkylarkClassObject makeStruct(String field, Object value) { - return new SkylarkClassObject(ImmutableMap.of(field, value)); - } - - private static SkylarkClassObject makeBigStruct(Environment env) { - // struct(a=[struct(x={1:1}), ()], b=(), c={2:2}) - return new SkylarkClassObject(ImmutableMap.of( - "a", MutableList.of(env, - new SkylarkClassObject(ImmutableMap.of( - "x", SkylarkDict.of(env, 1, 1))), - Tuple.of()), - "b", Tuple.of(), - "c", SkylarkDict.of(env, 2, 2))); - } - @Test public void testEmptyStringToIterable() throws Exception { assertThat(EvalUtils.toIterable("", null)).isEmpty(); @@ -88,7 +71,6 @@ public class EvalUtilsTest extends EvaluationTestCase { @Test public void testDatatypeMutabilityShallow() throws Exception { assertTrue(EvalUtils.isImmutable(Tuple.of(1, 2, 3))); - assertTrue(EvalUtils.isImmutable(makeStruct("a", 1))); // Mutability depends on the environment. assertTrue(EvalUtils.isImmutable(makeList(null))); @@ -100,12 +82,8 @@ public class EvalUtilsTest extends EvaluationTestCase { @Test public void testDatatypeMutabilityDeep() throws Exception { assertTrue(EvalUtils.isImmutable(Tuple.of(makeList(null)))); - assertTrue(EvalUtils.isImmutable(makeStruct("a", makeList(null)))); - assertTrue(EvalUtils.isImmutable(makeBigStruct(null))); assertFalse(EvalUtils.isImmutable(Tuple.of(makeList(env)))); - assertFalse(EvalUtils.isImmutable(makeStruct("a", makeList(env)))); - assertFalse(EvalUtils.isImmutable(makeBigStruct(env))); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java index 1eaecb7e46..5f994dbd1c 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.syntax.SkylarkList.MutableList; import com.google.devtools.build.lib.syntax.util.EvaluationTestCase; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -1661,9 +1660,6 @@ public class MethodLibraryTest extends EvaluationTestCase { .testStatement("str(False)", "False") .testStatement("str(None)", "None") .testStatement("str(str)", ""); - - new SkylarkTest() - .testStatement("str(struct(x = 2, y = 3, z = 4))", "struct(x = 2, y = 3, z = 4)"); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java index 2b6ebfc884..235968f7f2 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact; import com.google.devtools.build.lib.analysis.FileConfiguredTarget; @@ -30,7 +29,6 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.skylarkinterface.Param; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; -import com.google.devtools.build.lib.syntax.ClassObject.SkylarkClassObject; import com.google.devtools.build.lib.syntax.SkylarkList.MutableList; import com.google.devtools.build.lib.testutil.TestMode; import org.junit.Before; @@ -711,22 +709,6 @@ public class SkylarkEvaluationTest extends EvaluationTest { .testIfExactError("Object of type 'Mock' has no field \"function\"", "v = mock.function"); } - @Test - public void testConditionalStructConcatenation() throws Exception { - // TODO(fwe): cannot be handled by current testing suite - eval("def func():", - " x = struct(a = 1, b = 2)", - " if True:", - " x += struct(c = 1, d = 2)", - " return x", - "x = func()"); - SkylarkClassObject x = (SkylarkClassObject) lookup("x"); - assertEquals(1, x.getValue("a")); - assertEquals(2, x.getValue("b")); - assertEquals(1, x.getValue("c")); - assertEquals(2, x.getValue("d")); - } - @Test public void testJavaFunctionReturnsMutableObject() throws Exception { new SkylarkTest() @@ -824,93 +806,6 @@ public class SkylarkEvaluationTest extends EvaluationTest { "s = foo()").testLookup("s", "abc"); } - @Test - public void testStructCreation() throws Exception { - // TODO(fwe): cannot be handled by current testing suite - eval("x = struct(a = 1, b = 2)"); - assertThat(lookup("x")).isInstanceOf(ClassObject.class); - } - - @Test - public void testStructFields() throws Exception { - // TODO(fwe): cannot be handled by current testing suite - eval("x = struct(a = 1, b = 2)"); - ClassObject x = (ClassObject) lookup("x"); - assertEquals(1, x.getValue("a")); - assertEquals(2, x.getValue("b")); - } - - @Test - public void testStructAccessingFieldsFromSkylark() throws Exception { - new SkylarkTest() - .setUp("x = struct(a = 1, b = 2)", "x1 = x.a", "x2 = x.b") - .testLookup("x1", 1) - .testLookup("x2", 2); - } - - @Test - public void testStructAccessingUnknownField() throws Exception { - new SkylarkTest() - .testIfErrorContains( - "'struct' object has no attribute 'c'\n" + "Available attributes: a, b", - "x = struct(a = 1, b = 2)", - "y = x.c"); - } - - @Test - public void testStructAccessingUnknownFieldWithArgs() throws Exception { - new SkylarkTest().testIfExactError( - "struct has no method 'c'", "x = struct(a = 1, b = 2)", "y = x.c()"); - } - - @Test - public void testStructAccessingNonFunctionFieldWithArgs() throws Exception { - new SkylarkTest().testIfExactError( - "struct field 'a' is not a function", "x = struct(a = 1, b = 2)", "x1 = x.a(1)"); - } - - @Test - public void testStructAccessingFunctionFieldWithArgs() throws Exception { - new SkylarkTest() - .setUp("def f(x): return x+5", "x = struct(a = f, b = 2)", "x1 = x.a(1)") - .testLookup("x1", 6); - } - - @Test - public void testStructPosArgs() throws Exception { - new SkylarkTest().testIfExactError( - "struct(**kwargs) does not accept positional arguments, but got 1", "x = struct(1, b = 2)"); - } - - @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()); - } - - @Test - public void testStructConcatenationFieldValues() 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(1, z.getValue("a")); - assertEquals(2, z.getValue("b")); - assertEquals(1, z.getValue("c")); - assertEquals(2, z.getValue("d")); - } - - @Test - public void testStructConcatenationCommonFields() throws Exception { - new SkylarkTest().testIfExactError("Cannot concat structs with common field(s): a", - "x = struct(a = 1, b = 2)", "y = struct(c = 1, a = 2)", "z = x + y\n"); - } - @Test public void testDotExpressionOnNonStructObject() throws Exception { new SkylarkTest().testIfExactError("Object of type 'string' has no field \"field\"", @@ -1025,15 +920,6 @@ public class SkylarkEvaluationTest extends EvaluationTest { .testLookup("c", Boolean.FALSE); } - @Test - public void testHasattr() throws Exception { - new SkylarkTest().setUp("s = struct(a=1)", - "x = hasattr(s, 'a')", - "y = hasattr(s, 'b')\n") - .testLookup("x", Boolean.TRUE) - .testLookup("y", Boolean.FALSE); - } - @Test public void testHasattrMethods() throws Exception { new SkylarkTest() @@ -1048,23 +934,6 @@ public class SkylarkEvaluationTest extends EvaluationTest { .testLookup("e", Boolean.FALSE); } - @Test - public void testGetattr() throws Exception { - new SkylarkTest() - .setUp("s = struct(a='val')", "x = getattr(s, 'a')", "y = getattr(s, 'b', 'def')", - "z = getattr(s, 'b', default = 'def')", "w = getattr(s, 'a', default='ignored')") - .testLookup("x", "val") - .testLookup("y", "def") - .testLookup("z", "def") - .testLookup("w", "val"); - } - - @Test - public void testGetattrNoAttr() throws Exception { - new SkylarkTest().testIfExactError("Object of type 'struct' has no attribute \"b\"", - "s = struct(a='val')", "getattr(s, 'b')"); - } - @Test public void testListAnTupleConcatenationDoesNotWorkInSkylark() throws Exception { new SkylarkTest().testIfExactError("unsupported operand type(s) for +: 'list' and 'tuple'", diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java index 5c6535e8c9..a0d84206e8 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java @@ -18,19 +18,15 @@ import static org.junit.Assert.assertEquals; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.collect.nestedset.Order; -import com.google.devtools.build.lib.syntax.ClassObject.SkylarkClassObject; import com.google.devtools.build.lib.syntax.SkylarkList.Tuple; import com.google.devtools.build.lib.syntax.util.EvaluationTestCase; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - import java.util.Arrays; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; /** * Tests for SkylarkNestedSet. @@ -155,22 +151,6 @@ public class SkylarkNestedSetTest extends EvaluationTestCase { checkEvalError("cannot add value of type 'string' to a set", "l = ['a']\n" + "set() + l[0]"); } - @Test - public void testNsetGoodCompositeItem() throws Exception { - eval("def func():", - " return set([struct(a='a')])", - "s = func()"); - Collection result = get("s").toCollection(); - assertThat(result).hasSize(1); - assertThat(result.iterator().next()).isInstanceOf(SkylarkClassObject.class); - } - - @Test - public void testNsetBadMutableItem() throws Exception { - checkEvalError("sets cannot contain mutable items", "set([([],)])"); - checkEvalError("sets cannot contain mutable items", "set([struct(a=[])])"); - } - @Test public void testNsetToString() throws Exception { eval("s = set() + [2, 4, 6] + [3, 4, 5]", diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java index c44e5c918b..b7bd6f6306 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java @@ -18,11 +18,11 @@ import static com.google.common.truth.Truth.assertThat; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.RuleConfiguredTarget; import com.google.devtools.build.lib.events.Event; +import com.google.devtools.build.lib.packages.SkylarkClassObject; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; import com.google.devtools.build.lib.syntax.SkylarkList.MutableList; import com.google.devtools.build.lib.syntax.SkylarkList.Tuple; import com.google.devtools.build.lib.syntax.util.EvaluationTestCase; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -111,22 +111,6 @@ public class ValidationTest extends EvaluationTestCase { checkError("function 'foo' does not exist", "def bar(): a = foo() + 'a'"); } - @Test - public void testStructMembersAreImmutable() { - checkError( - "can only assign to variables and tuples, not to 's.x'", - "s = struct(x = 'a')", - "s.x = 'b'\n"); - } - - @Test - public void testStructDictMembersAreImmutable() { - checkError( - "can only assign to variables and tuples, not to 's.x['b']'", - "s = struct(x = {'a' : 1})", - "s.x['b'] = 2\n"); - } - @Test public void testTupleLiteralWorksForDifferentTypes() throws Exception { parse("('a', 1)"); @@ -299,11 +283,11 @@ public class ValidationTest extends EvaluationTestCase { // TODO(bazel-team): fix that? assertThat(ClassObject.class.isAnnotationPresent(SkylarkModule.class)).isFalse(); - assertThat(ClassObject.SkylarkClassObject.class.isAnnotationPresent(SkylarkModule.class)) + assertThat(SkylarkClassObject.class.isAnnotationPresent(SkylarkModule.class)) .isTrue(); assertThat( - EvalUtils.getParentWithSkylarkModule(ClassObject.SkylarkClassObject.class) - == ClassObject.SkylarkClassObject.class) + EvalUtils.getParentWithSkylarkModule(SkylarkClassObject.class) + == SkylarkClassObject.class) .isTrue(); assertThat(EvalUtils.getParentWithSkylarkModule(ClassObject.class)).isNull(); } @@ -320,8 +304,6 @@ public class ValidationTest extends EvaluationTestCase { assertThat(SkylarkType.of(tupleClass)).isEqualTo(SkylarkType.TUPLE); assertThat(SkylarkType.TUPLE).isNotEqualTo(SkylarkType.LIST); - // Also for ClassObject - assertThat(SkylarkType.of(ClassObject.SkylarkClassObject.class)).isEqualTo(SkylarkType.STRUCT); try { SkylarkType.of(ClassObject.class); throw new Exception("foo"); @@ -335,7 +317,7 @@ public class ValidationTest extends EvaluationTestCase { // TODO(bazel-team): move to some other place to remove dependency of syntax tests on Artifact? assertThat(SkylarkType.of(Artifact.SpecialArtifact.class)) .isEqualTo(SkylarkType.of(Artifact.class)); - assertThat(SkylarkType.of(RuleConfiguredTarget.class)).isNotEqualTo(SkylarkType.STRUCT); + assertThat(SkylarkType.of(RuleConfiguredTarget.class)).isNotEqualTo(SkylarkType.of(SkylarkClassObject.class)); } @Test @@ -348,9 +330,8 @@ public class ValidationTest extends EvaluationTestCase { assertThat(SkylarkType.LIST.includes(combo1)).isTrue(); SkylarkType union1 = - SkylarkType.Union.of(SkylarkType.DICT, SkylarkType.LIST, SkylarkType.STRUCT); + SkylarkType.Union.of(SkylarkType.DICT, SkylarkType.LIST); assertThat(union1.includes(SkylarkType.DICT)).isTrue(); - assertThat(union1.includes(SkylarkType.STRUCT)).isTrue(); assertThat(union1.includes(combo1)).isTrue(); assertThat(union1.includes(SkylarkType.STRING)).isFalse(); -- cgit v1.2.3