Migrated EvaluationTestCase (and all tests depending on it) to JUnit 4.
--
MOS_MIGRATED_REVID=109064201
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java b/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
index 7c5a582..6cda0b7 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
@@ -52,7 +52,7 @@
private void checkBaseFunction(BaseFunction func, String callExpression, String expectedOutput)
throws Exception {
- setUp();
+ initialize();
update(func.getName(), func);
if (expectedOutput.charAt(0) == '[') { // a tuple => expected to pass
@@ -132,8 +132,8 @@
"unexpected keyword 'wiz' in call to mixed(*, foo, bar = ?)");
}
- @Test
@SuppressWarnings("unchecked")
+ @Test
public void testKwParam() throws Exception {
eval("def foo(a, b, c=3, d=4, *args, e, f, g=7, h=8, **kwargs):\n"
+ " return (a, b, c, d, e, f, g, h, args, kwargs)\n"
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
index be1cf6d..7a10338 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
@@ -38,8 +38,9 @@
*/
@RunWith(JUnit4.class)
public class EvaluationTest extends EvaluationTestCase {
+
@Before
- public void setBuildMode() throws Exception {
+ public final void setBuildMode() throws Exception {
super.setMode(TestMode.BUILD);
}
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 eee12f7..a3f71fa 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
@@ -35,9 +35,7 @@
public class MethodLibraryTest extends EvaluationTestCase {
@Before
- @Override
- public void setUp() throws Exception {
- super.setUp();
+ public final void setFailFast() throws Exception {
setFailFast(true);
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
index e5d6769..fac46d4 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
@@ -43,9 +43,7 @@
Environment buildEnvironment;
@Before
- @Override
- public void setUp() throws Exception {
- super.setUp();
+ public final void createBuildEnvironment() throws Exception {
buildEnvironment = newBuildEnvironment();
}
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 1412c5a..59ba5c3 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
@@ -40,8 +40,9 @@
*/
@RunWith(JUnit4.class)
public class SkylarkEvaluationTest extends EvaluationTest {
+
@Before
- public void setup() throws Exception {
+ public final void setup() throws Exception {
setMode(TestMode.SKYLARK);
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java b/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
index 1f7586a..a67a453 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
@@ -24,7 +24,6 @@
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.EventKind;
import com.google.devtools.build.lib.events.util.EventCollectionApparatus;
-import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Expression;
@@ -33,7 +32,6 @@
import com.google.devtools.build.lib.syntax.ParserInputSource;
import com.google.devtools.build.lib.syntax.Statement;
import com.google.devtools.build.lib.testutil.TestMode;
-import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import org.junit.Before;
@@ -46,17 +44,23 @@
public class EvaluationTestCase {
private EventCollectionApparatus eventCollectionApparatus =
new EventCollectionApparatus(EventKind.ALL_EVENTS);
- private PackageFactory factory;
private TestMode testMode = TestMode.SKYLARK;
protected Environment env;
protected Mutability mutability = Mutability.create("test");
@Before
- public void setUp() throws Exception {
- factory = new PackageFactory(TestRuleClassProvider.getRuleClassProvider());
+ public final void initialize() throws Exception {
+ beforeInitialization();
env = newEnvironment();
}
+ protected void beforeInitialization() throws Exception {
+ // This method exists so that it can be overriden in MakeEnvironmentTest.
+ // The problem is that MakeEnvironmentTest's initialization code (setting up makeEnvBuilder)
+ // needs to run before initialize(), otherwise some tests fail with an NPE.
+ // Consequently, we need this hack to ensure the right order of methods.
+ }
+
/**
* Creates a standard Environment for tests in the BUILD language.
* No PythonPreprocessing, mostly empty mutable Environment.