bazel syntax: rename Environment -> StarlarkThread
The environment features are about to be removed.
This is inevitably a breaking API change (sorry copybara).
PiperOrigin-RevId: 271339546
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 dfa82d5..2cccb8b 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
@@ -45,9 +45,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/**
- * Evaluation tests with Skylark Environment.
- */
+/** Evaluation tests with Skylark StarlarkThread. */
@RunWith(JUnit4.class)
public class SkylarkEvaluationTest extends EvaluationTest {
@@ -314,16 +312,16 @@
documented = false,
useLocation = true,
useAst = true,
- useEnvironment = true,
+ useStarlarkThread = true,
useStarlarkSemantics = true)
public String withExtraInterpreterParams(
- Location location, FuncallExpression func, Environment env, StarlarkSemantics sem) {
+ Location location, FuncallExpression func, StarlarkThread thread, StarlarkSemantics sem) {
return "with_extra("
+ location.getStartLine()
+ ", "
+ func.getArguments().size()
+ ", "
- + env.isGlobal()
+ + thread.isGlobal()
+ ", "
+ (sem != null)
+ ")";
@@ -375,7 +373,7 @@
},
useAst = true,
useLocation = true,
- useEnvironment = true,
+ useStarlarkThread = true,
useStarlarkSemantics = true)
public String withParamsAndExtraInterpreterParams(
Integer pos1,
@@ -388,7 +386,7 @@
Object multi,
Location location,
FuncallExpression func,
- Environment env,
+ StarlarkThread thread,
StarlarkSemantics sem) {
return "with_params_and_extra("
+ pos1
@@ -409,7 +407,7 @@
+ ", "
+ func.getArguments().size()
+ ", "
- + env.isGlobal()
+ + thread.isGlobal()
+ ", "
+ (sem != null)
+ ")";
@@ -427,21 +425,20 @@
}
@SkylarkCallable(
- name = "with_args_and_env",
- documented = false,
- parameters = {
- @Param(name = "pos1", type = Integer.class),
- @Param(name = "pos2", defaultValue = "False", type = Boolean.class),
- @Param(name = "named", type = Boolean.class, positional = false, named = true),
- },
- extraPositionals = @Param(name = "args"),
- useEnvironment = true
- )
- public String withArgsAndEnv(
- Integer pos1, boolean pos2, boolean named, SkylarkList<?> args, Environment env) {
+ name = "with_args_and_thread",
+ documented = false,
+ parameters = {
+ @Param(name = "pos1", type = Integer.class),
+ @Param(name = "pos2", defaultValue = "False", type = Boolean.class),
+ @Param(name = "named", type = Boolean.class, positional = false, named = true),
+ },
+ extraPositionals = @Param(name = "args"),
+ useStarlarkThread = true)
+ public String withArgsAndThread(
+ Integer pos1, boolean pos2, boolean named, SkylarkList<?> args, StarlarkThread thread) {
String argsString =
"args(" + args.stream().map(Printer::debugPrint).collect(joining(", ")) + ")";
- return "with_args_and_env("
+ return "with_args_and_thread("
+ pos1
+ ", "
+ pos2
@@ -450,7 +447,7 @@
+ ", "
+ argsString
+ ", "
- + env.isGlobal()
+ + thread.isGlobal()
+ ")";
}
@@ -1079,7 +1076,7 @@
" modified_list = v + ['extra_string']",
" return modified_list",
"m = func(mock)")
- .testLookup("m", MutableList.of(env, "b", "c", "extra_string"));
+ .testLookup("m", MutableList.of(thread, "b", "c", "extra_string"));
}
@Test
@@ -1331,19 +1328,19 @@
}
@Test
- public void testJavaFunctionWithExtraArgsAndEnv() throws Exception {
+ public void testJavaFunctionWithExtraArgsAndThread() throws Exception {
new SkylarkTest()
.update("mock", new Mock())
- .setUp("b = mock.with_args_and_env(1, True, 'extraArg1', 'extraArg2', named=True)")
- .testLookup("b", "with_args_and_env(1, true, true, args(extraArg1, extraArg2), true)");
+ .setUp("b = mock.with_args_and_thread(1, True, 'extraArg1', 'extraArg2', named=True)")
+ .testLookup("b", "with_args_and_thread(1, true, true, args(extraArg1, extraArg2), true)");
// Use an args list.
new SkylarkTest()
.update("mock", new Mock())
.setUp(
"myargs = ['extraArg2']",
- "b = mock.with_args_and_env(1, True, 'extraArg1', named=True, *myargs)")
- .testLookup("b", "with_args_and_env(1, true, true, args(extraArg1, extraArg2), true)");
+ "b = mock.with_args_and_thread(1, True, 'extraArg1', named=True, *myargs)")
+ .testLookup("b", "with_args_and_thread(1, true, true, args(extraArg1, extraArg2), true)");
}
@Test
@@ -1553,28 +1550,30 @@
@Test
public void testAugmentedAssignmentHasNoSideEffects() throws Exception {
// Check object position.
- new SkylarkTest().setUp(
- "counter = [0]",
- "value = [1, 2]",
- "",
- "def f():",
- " counter[0] = counter[0] + 1",
- " return value",
- "",
- "f()[1] += 1") // `f()` should be called only once here
- .testLookup("counter", MutableList.of(env, 1));
+ new SkylarkTest()
+ .setUp(
+ "counter = [0]",
+ "value = [1, 2]",
+ "",
+ "def f():",
+ " counter[0] = counter[0] + 1",
+ " return value",
+ "",
+ "f()[1] += 1") // `f()` should be called only once here
+ .testLookup("counter", MutableList.of(thread, 1));
// Check key position.
- new SkylarkTest().setUp(
- "counter = [0]",
- "value = [1, 2]",
- "",
- "def f():",
- " counter[0] = counter[0] + 1",
- " return 1",
- "",
- "value[f()] += 1") // `f()` should be called only once here
- .testLookup("counter", MutableList.of(env, 1));
+ new SkylarkTest()
+ .setUp(
+ "counter = [0]",
+ "value = [1, 2]",
+ "",
+ "def f():",
+ " counter[0] = counter[0] + 1",
+ " return 1",
+ "",
+ "value[f()] += 1") // `f()` should be called only once here
+ .testLookup("counter", MutableList.of(thread, 1));
}
@Test
@@ -1594,23 +1593,24 @@
@Test
public void testAssignmentEvaluationOrder() throws Exception {
- new SkylarkTest().setUp(
- "ordinary = []",
- "augmented = []",
- "value = [1, 2]",
- "",
- "def f(record):",
- " record.append('f')",
- " return value",
- "",
- "def g(record):",
- " record.append('g')",
- " return value",
- "",
- "f(ordinary)[0] = g(ordinary)[1]",
- "f(augmented)[0] += g(augmented)[1]")
- .testLookup("ordinary", MutableList.of(env, "g", "f")) // This order is consistent
- .testLookup("augmented", MutableList.of(env, "f", "g")); // with Python
+ new SkylarkTest()
+ .setUp(
+ "ordinary = []",
+ "augmented = []",
+ "value = [1, 2]",
+ "",
+ "def f(record):",
+ " record.append('f')",
+ " return value",
+ "",
+ "def g(record):",
+ " record.append('g')",
+ " return value",
+ "",
+ "f(ordinary)[0] = g(ordinary)[1]",
+ "f(augmented)[0] += g(augmented)[1]")
+ .testLookup("ordinary", MutableList.of(thread, "g", "f")) // This order is consistent
+ .testLookup("augmented", MutableList.of(thread, "f", "g")); // with Python
}
@Test
@@ -1950,8 +1950,8 @@
"struct_field_with_extra",
"value_of",
"voidfunc",
- "with_args_and_env",
"with_args_and_kwargs",
+ "with_args_and_thread",
"with_extra",
"with_kwargs",
"with_params",