diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java | 30 |
1 files changed, 30 insertions, 0 deletions
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 d00c1bd50a..81fa580ecb 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 @@ -1490,4 +1490,34 @@ public class SkylarkEvaluationTest extends EvaluationTest { // TODO(bazel-team): This should probably match the error above better. "struct has no method 'nonexistent_method'", "v = val.nonexistent_method()"); } + + @Test + public void testListComprehensionsDoNotLeakVariables() throws Exception { + env = + newEnvironmentWithSkylarkOptions("--incompatible_comprehension_variables_do_not_leak=true"); + checkEvalErrorContains( + "name 'a' is not defined", + "def foo():", + " a = 10", + " b = [a for a in range(3)]", + " return a", + "x = foo()"); + } + + @Test + public void testListComprehensionsShadowGlobalVariable() throws Exception { + env = + newEnvironmentWithSkylarkOptions("--incompatible_comprehension_variables_do_not_leak=true"); + eval("a = 18", "def foo():", " b = [a for a in range(3)]", " return a", "x = foo()"); + assertThat(lookup("x")).isEqualTo(18); + } + + @Test + public void testListComprehensionsLeakVariables() throws Exception { + env = + newEnvironmentWithSkylarkOptions( + "--incompatible_comprehension_variables_do_not_leak=false"); + eval("def foo():", " a = 10", " b = [a for a in range(3)]", " return a", "x = foo()"); + assertThat(lookup("x")).isEqualTo(2); + } } |