After r658, GWTCompiler.main always exits with a call to System.exit making
it impossible to call from within unit tests. PublicTagTest was calling main
directly which prevented the test from finishing properly. This patch fixes
that by invoking the compiler through the appropriate instance methods.
Review by: mmendez
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@669 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/test/com/google/gwt/dev/cfg/PublicTagTest.java b/user/test/com/google/gwt/dev/cfg/PublicTagTest.java
index 471525d..6f0b54c 100644
--- a/user/test/com/google/gwt/dev/cfg/PublicTagTest.java
+++ b/user/test/com/google/gwt/dev/cfg/PublicTagTest.java
@@ -15,8 +15,11 @@
*/
package com.google.gwt.dev.cfg;
+import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.dev.GWTCompiler;
import com.google.gwt.dev.util.Util;
+import com.google.gwt.dev.util.log.AbstractTreeLogger;
+import com.google.gwt.dev.util.log.PrintWriterTreeLogger;
import junit.framework.TestCase;
@@ -28,6 +31,32 @@
*/
public class PublicTagTest extends TestCase {
+ /**
+ * Provides a convienent interface to the {@link GWTCompiler}. This test
+ * cannot simply call {@link GWTCompiler#main(String[])} since it always
+ * terminates with a call to {@link System#exit(int)}.
+ */
+ private static class Compiler extends GWTCompiler {
+ /**
+ * Run the {@link GWTCompiler} with the specified arguments.
+ *
+ * @param args arguments passed to the compiler.
+ */
+ static void compile(String[] args) {
+ try {
+ final Compiler compiler = new Compiler();
+ if (compiler.processArgs(args)) {
+ final AbstractTreeLogger logger = new PrintWriterTreeLogger();
+ logger.setMaxDetail(compiler.getLogLevel());
+ compiler.distill(logger, ModuleDefLoader.loadFromClassPath(logger,
+ compiler.getModuleName()));
+ }
+ } catch (UnableToCompleteException e) {
+ throw new RuntimeException("Compilation failed.", e);
+ }
+ }
+ }
+
public void testPublicTag() {
// Find the current directory
String userDir = System.getProperty("user.dir");
@@ -46,7 +75,7 @@
assertFalse(moduleDir.exists());
// Compile the dummy app; suppress output to stdout
- GWTCompiler.main(new String[]{moduleName, "-logLevel", "ERROR"});
+ Compiler.compile(new String[] {moduleName, "-logLevel", "ERROR"});
// Check the output folder
assertTrue(new File(moduleDir, "good0.html").exists());