Fixes a bug in CompileStrategy where it would throw an IllegalArgumentException if tests are run out of module order.
Patch by: jlabanca
Review by: jgw
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6157 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/junit/CompileStrategy.java b/user/src/com/google/gwt/junit/CompileStrategy.java
index 5828d7f..7b36739 100644
--- a/user/src/com/google/gwt/junit/CompileStrategy.java
+++ b/user/src/com/google/gwt/junit/CompileStrategy.java
@@ -20,6 +20,7 @@
import com.google.gwt.dev.cfg.ConfigurationProperty;
import com.google.gwt.dev.cfg.ModuleDef;
import com.google.gwt.dev.cfg.ModuleDefLoader;
+import com.google.gwt.dev.util.collect.HashSet;
import com.google.gwt.junit.JUnitShell.Strategy;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.junit.client.GWTTestCase.TestModuleInfo;
@@ -30,6 +31,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* An interface that specifies how modules should be compiled.
@@ -37,9 +39,10 @@
public abstract class CompileStrategy {
/**
- * The number of modules that have been compiled.
+ * The list of modules that have already been compiled. We use this to avoid
+ * adding test batches that have already been added.
*/
- private int compiledModuleCount;
+ private Set<String> compiledModuleNames = new HashSet<String>();
/**
* Let the compile strategy compile another module. This is called while
@@ -101,11 +104,14 @@
runStyle.maybeCompileModule(syntheticModuleName);
- // Add all test blocks for the module.
- compiledModuleCount++;
- boolean isFinalModule = compiledModuleCount == GWTTestCase.getModuleCount();
- List<TestInfo[]> testBlocks = batchingStrategy.getTestBlocks(syntheticModuleName);
- JUnitShell.getMessageQueue().addTestBlocks(testBlocks, isFinalModule);
+ // Add all test blocks for the module if we haven't seen this module before.
+ if (!compiledModuleNames.contains(syntheticModuleName)) {
+ compiledModuleNames.add(syntheticModuleName);
+ boolean isFinalModule = compiledModuleNames.size() == GWTTestCase.getModuleCount();
+ List<TestInfo[]> testBlocks = batchingStrategy.getTestBlocks(syntheticModuleName);
+ JUnitShell.getMessageQueue().addTestBlocks(testBlocks, isFinalModule);
+ }
+
return moduleDef;
}
}
diff --git a/user/test/com/google/gwt/junit/JUnitTest.gwt.xml b/user/test/com/google/gwt/junit/JUnitTest.gwt.xml
new file mode 100644
index 0000000..b9cd010
--- /dev/null
+++ b/user/test/com/google/gwt/junit/JUnitTest.gwt.xml
@@ -0,0 +1,17 @@
+<!-- -->
+<!-- Copyright 2009 Google Inc. -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License"); you -->
+<!-- may not use this file except in compliance with the License. You may -->
+<!-- may obtain a copy of the License at -->
+<!-- -->
+<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
+<!-- -->
+<!-- Unless required by applicable law or agreed to in writing, software -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -->
+<!-- implied. License for the specific language governing permissions and -->
+<!-- limitations under the License. -->
+
+<module>
+ <inherits name="com.google.gwt.user.User"/>
+</module>
diff --git a/user/test/com/google/gwt/junit/JUnitTest2.gwt.xml b/user/test/com/google/gwt/junit/JUnitTest2.gwt.xml
new file mode 100644
index 0000000..b9cd010
--- /dev/null
+++ b/user/test/com/google/gwt/junit/JUnitTest2.gwt.xml
@@ -0,0 +1,17 @@
+<!-- -->
+<!-- Copyright 2009 Google Inc. -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License"); you -->
+<!-- may not use this file except in compliance with the License. You may -->
+<!-- may obtain a copy of the License at -->
+<!-- -->
+<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
+<!-- -->
+<!-- Unless required by applicable law or agreed to in writing, software -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -->
+<!-- implied. License for the specific language governing permissions and -->
+<!-- limitations under the License. -->
+
+<module>
+ <inherits name="com.google.gwt.user.User"/>
+</module>
diff --git a/user/test/com/google/gwt/junit/TestSuiteTest.java b/user/test/com/google/gwt/junit/TestSuiteTest.java
new file mode 100644
index 0000000..89b6ba0
--- /dev/null
+++ b/user/test/com/google/gwt/junit/TestSuiteTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.junit;
+
+import com.google.gwt.junit.client.ModuleOneTest;
+import com.google.gwt.junit.client.ModuleOneTest2;
+import com.google.gwt.junit.client.ModuleTwoTest;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests that a normal test suite will run even if modules are out of order.
+ */
+public class TestSuiteTest {
+
+ public static Test suite() {
+ // This is intentionally not a GWTTestSuite.
+ TestSuite suite = new TestSuite();
+
+ suite.addTestSuite(ModuleOneTest.class);
+ suite.addTestSuite(ModuleTwoTest.class);
+ suite.addTestSuite(ModuleOneTest2.class);
+
+ return suite;
+ }
+}
diff --git a/user/test/com/google/gwt/junit/client/ModuleOneTest.java b/user/test/com/google/gwt/junit/client/ModuleOneTest.java
new file mode 100644
index 0000000..1d1c5a7
--- /dev/null
+++ b/user/test/com/google/gwt/junit/client/ModuleOneTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.junit.client;
+
+/**
+ * A test in the first module.
+ */
+public class ModuleOneTest extends GWTTestCase {
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.junit.JUnitTest";
+ }
+
+ public void testTrue() {
+ assertTrue(true);
+ }
+}
diff --git a/user/test/com/google/gwt/junit/client/ModuleOneTest2.java b/user/test/com/google/gwt/junit/client/ModuleOneTest2.java
new file mode 100644
index 0000000..f0fc271
--- /dev/null
+++ b/user/test/com/google/gwt/junit/client/ModuleOneTest2.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.junit.client;
+
+/**
+ * Another test in the first module.
+ */
+public class ModuleOneTest2 extends GWTTestCase {
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.junit.JUnitTest";
+ }
+
+ public void testTrue() {
+ assertTrue(true);
+ }
+}
diff --git a/user/test/com/google/gwt/junit/client/ModuleTwoTest.java b/user/test/com/google/gwt/junit/client/ModuleTwoTest.java
new file mode 100644
index 0000000..0d983dc
--- /dev/null
+++ b/user/test/com/google/gwt/junit/client/ModuleTwoTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.junit.client;
+
+/**
+ * A test in the second module.
+ */
+public class ModuleTwoTest extends GWTTestCase {
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.junit.JUnitTest2";
+ }
+
+ public void testTrue() {
+ assertTrue(true);
+ }
+}