diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/MutabilityTest.java | 22 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java | 14 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MutabilityTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MutabilityTest.java index 67c3e0ec8b..b9b896f2bc 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/MutabilityTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/MutabilityTest.java @@ -233,4 +233,26 @@ public final class MutabilityTest { assertThat(expected).hasMessageThat().contains( "trying to check the lock of an object from a different context"); } + + @Test + public void checkUnsafeShallowFreezePrecondition_FailsWhenAlreadyFrozen() throws Exception { + Mutability mutability = Mutability.create("test").freeze(); + assertThrows( + IllegalArgumentException.class, + () -> Freezable.checkUnsafeShallowFreezePrecondition(new DummyFreezable(mutability))); + } + + @Test + public void checkUnsafeShallowFreezePrecondition_FailsWhenDisallowed() throws Exception { + Mutability mutability = Mutability.create("test"); + assertThrows( + IllegalArgumentException.class, + () -> Freezable.checkUnsafeShallowFreezePrecondition(new DummyFreezable(mutability))); + } + + @Test + public void checkUnsafeShallowFreezePrecondition_SucceedsWhenAllowed() throws Exception { + Mutability mutability = Mutability.createAllowingShallowFreeze("test"); + Freezable.checkUnsafeShallowFreezePrecondition(new DummyFreezable(mutability)); + } } diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java index b2768390da..016c30f85a 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java @@ -279,6 +279,20 @@ public class SkylarkListTest extends EvaluationTestCase { } @Test + public void testCannotMutateAfterShallowFreeze() throws Exception { + Mutability mutability = Mutability.createAllowingShallowFreeze("test"); + MutableList<Object> list = MutableList.copyOf(mutability, ImmutableList.of(1, 2, 3)); + list.unsafeShallowFreeze(); + + try { + list.add(4, null, mutability); + fail("expected exception"); + } catch (EvalException e) { + assertThat(e).hasMessage("trying to mutate a frozen object"); + } + } + + @Test public void testCopyOfTakesCopy() throws EvalException { ArrayList<String> copyFrom = Lists.newArrayList("hi"); Mutability mutability = Mutability.create("test"); |