Revision: 5755
Author: [email protected]
Date: Mon Jul 20 11:52:26 2009
Log: Reinstating assertions default on in web tests, with -da to turn it  
off, from r5726, but this time with test fixes for IE-specific assertion  
trips.

Patch by: flin, except CoverageTest.java & HandlerManagerTest.java
           fabbott, for those two test files
Review by: fabbott, except CoverageTest.java and HandlerManagerTest.java
            jat, for those two test files
http://code.google.com/p/google-web-toolkit/source/detail?r=5755

Added:
   
/trunk/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerDisableAssertions.java
Modified:
  /trunk/dev/core/src/com/google/gwt/dev/GWTShell.java
  /trunk/dev/core/src/com/google/gwt/dev/HostedModeBase.java
  /trunk/dev/core/src/com/google/gwt/dev/Precompile.java
   
/trunk/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerEnableAssertions.java
  /trunk/dev/core/test/com/google/gwt/dev/GWTShellTest.java
  /trunk/user/src/com/google/gwt/junit/JUnitShell.java
  /trunk/user/test/com/google/gwt/dev/jjs/test/CoverageTest.java
  /trunk/user/test/com/google/gwt/event/shared/HandlerManagerTest.java

=======================================
--- /dev/null
+++  
/trunk/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerDisableAssertions.java
         
Mon Jul 20 11:52:26 2009
@@ -0,0 +1,47 @@
+/*
+ * 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.dev.util.arg;
+
+import com.google.gwt.util.tools.ArgHandlerFlag;
+
+/**
+ * Handler for -da arg to disable assertions in compiled code.
+ */
+public final class ArgHandlerDisableAssertions extends ArgHandlerFlag {
+
+  private final OptionEnableAssertions option;
+
+  public ArgHandlerDisableAssertions(OptionEnableAssertions option) {
+    this.option = option;
+  }
+
+  @Override
+  public String getPurpose() {
+    return "Debugging: disables checking assertion statements in the  
compiled output.";
+  }
+
+  @Override
+  public String getTag() {
+    return "-da";
+  }
+
+  @Override
+  public boolean setFlag() {
+    option.setEnableAssertions(false);
+    return true;
+  }
+
+}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/GWTShell.java        Tue Jul 14  
07:15:19 2009
+++ /trunk/dev/core/src/com/google/gwt/dev/GWTShell.java        Mon Jul 20  
11:52:26 2009
@@ -90,7 +90,7 @@
    /**
     * Concrete class to implement all shell options.
     */
-  static class ShellOptionsImpl extends HostedModeBaseOptionsImpl  
implements
+  protected static class ShellOptionsImpl extends  
HostedModeBaseOptionsImpl implements
        HostedModeBaseOptions, WorkDirs, LegacyCompilerOptions {
      private int localWorkers;
      private File outDir;
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/HostedModeBase.java  Tue Jul 14  
07:15:19 2009
+++ /trunk/dev/core/src/com/google/gwt/dev/HostedModeBase.java  Mon Jul 20  
11:52:26 2009
@@ -32,6 +32,7 @@
  import com.google.gwt.dev.shell.ShellModuleSpaceHost;
  import com.google.gwt.dev.util.Util;
  import com.google.gwt.dev.util.arg.ArgHandlerDisableAggressiveOptimization;
+import com.google.gwt.dev.util.arg.ArgHandlerDisableAssertions;
  import com.google.gwt.dev.util.arg.ArgHandlerDisableCastChecking;
  import com.google.gwt.dev.util.arg.ArgHandlerDisableClassMetadata;
  import com.google.gwt.dev.util.arg.ArgHandlerDraftCompile;
@@ -321,6 +322,7 @@
        registerHandler(new ArgHandlerGenDir(options));
        registerHandler(new ArgHandlerScriptStyle(options));
        registerHandler(new ArgHandlerEnableAssertions(options));
+      registerHandler(new ArgHandlerDisableAssertions(options));
        registerHandler(new  
ArgHandlerDisableAggressiveOptimization(options));
        registerHandler(new ArgHandlerDisableClassMetadata(options));
        registerHandler(new ArgHandlerDisableCastChecking(options));
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/Precompile.java      Tue Jul 14  
07:15:19 2009
+++ /trunk/dev/core/src/com/google/gwt/dev/Precompile.java      Mon Jul 20  
11:52:26 2009
@@ -43,6 +43,7 @@
  import com.google.gwt.dev.util.PerfLogger;
  import com.google.gwt.dev.util.Util;
  import com.google.gwt.dev.util.arg.ArgHandlerDisableAggressiveOptimization;
+import com.google.gwt.dev.util.arg.ArgHandlerDisableAssertions;
  import com.google.gwt.dev.util.arg.ArgHandlerDisableCastChecking;
  import com.google.gwt.dev.util.arg.ArgHandlerDisableClassMetadata;
  import com.google.gwt.dev.util.arg.ArgHandlerDisableRunAsync;
@@ -94,6 +95,7 @@
        registerHandler(new ArgHandlerGenDir(options));
        registerHandler(new ArgHandlerScriptStyle(options));
        registerHandler(new ArgHandlerEnableAssertions(options));
+      registerHandler(new ArgHandlerDisableAssertions(options));
        registerHandler(new  
ArgHandlerDisableAggressiveOptimization(options));
        registerHandler(new ArgHandlerDisableClassMetadata(options));
        registerHandler(new ArgHandlerDisableCastChecking(options));
=======================================
---  
/trunk/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerEnableAssertions.java 
 
Tue Jul 14 07:15:19 2009
+++  
/trunk/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerEnableAssertions.java 
 
Mon Jul 20 11:52:26 2009
@@ -30,7 +30,7 @@

    @Override
    public String getPurpose() {
-    return "Debugging: causes the compiled output to check assert  
statements.";
+    return "Debugging: enables checking assertion statements in the  
compiled output.";
    }

    @Override
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/GWTShellTest.java   Tue Jul 14  
07:15:19 2009
+++ /trunk/dev/core/test/com/google/gwt/dev/GWTShellTest.java   Mon Jul 20  
11:52:26 2009
@@ -75,6 +75,16 @@
      assertEquals("http://www.google.com/";,  
options.getStartupURLs().get(0));
      assertEquals("foo", options.getStartupURLs().get(1));
    }
+
+  public void testAssertionsArgs() {
+    // Assertion is enabled by default in web mode, i.e. -ea flag.
+    assertProcessSuccess(argProcessor, "-ea");
+    assertTrue(options.isEnableAssertions());
+    assertProcessSuccess(argProcessor, "-da");
+    assertFalse(options.isEnableAssertions());
+    assertProcessSuccess(argProcessor, "-ea");
+    assertTrue(options.isEnableAssertions());
+  }

    public void testDefaultArgs() {
      assertProcessSuccess(argProcessor);
=======================================
--- /trunk/user/src/com/google/gwt/junit/JUnitShell.java        Tue Jul 14  
07:15:19 2009
+++ /trunk/user/src/com/google/gwt/junit/JUnitShell.java        Mon Jul 20  
11:52:26 2009
@@ -1,12 +1,12 @@
  /*
   * Copyright 2008 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
@@ -52,26 +52,26 @@
  /**
   * This class is responsible for hosting JUnit test case execution. There  
are
   * three main pieces to the JUnit system.
- *
+ *
   * <ul>
   * <li>Test environment</li>
   * <li>Client classes</li>
   * <li>Server classes</li>
   * </ul>
- *
+ *
   * <p>
   * The test environment consists of this class and the non-translatable  
version
   * of {...@link com.google.gwt.junit.client.GWTTestCase}. These two classes
   * integrate directly into the real JUnit test process.
   * </p>
- *
+ *
   * <p>
   * The client classes consist of the translatable version of {...@link
   * com.google.gwt.junit.client.GWTTestCase}, translatable JUnit classes,  
and the
   * user's own {...@link com.google.gwt.junit.client.GWTTestCase}-derived  
class.
   * The client communicates to the server via RPC.
   * </p>
- *
+ *
   * <p>
   * The server consists of {...@link  
com.google.gwt.junit.server.JUnitHostImpl}, an
   * RPC servlet which communicates back to the test environment through a
@@ -330,15 +330,15 @@

    /**
     * The amount of time to wait for all clients to have contacted the  
server and
-   * begin running the test.  "Contacted" does not necessarily mean "the  
test
-   * has begun," e.g. for linker errors stopping the test initialization.
+   * begin running the test. "Contacted" does not necessarily mean "the  
test has
+   * begun," e.g. for linker errors stopping the test initialization.
     */
    private static final int TEST_BEGIN_TIMEOUT_MILLIS = 60000;

    /**
     * The amount of time to wait for all clients to complete a single test
-   * method, in milliseconds, measured from when the <i>last</i> client
-   * connects (and thus starts the test).  5 minutes.
+   * method, in milliseconds, measured from when the <i>last</i> client
+   * connects (and thus starts the test). 5 minutes.
     */
    private static final long TEST_METHOD_TIMEOUT_MILLIS = 300000;

@@ -351,7 +351,7 @@
    /**
     * Called by {...@link com.google.gwt.junit.server.JUnitHostImpl} to get an
     * interface into the test process.
-   *
+   *
     * @return The {...@link JUnitMessageQueue} interface that belongs to the
     *         singleton {...@link JUnitShell}, or <code>null</code> if no such
     *         singleton exists.
@@ -503,9 +503,9 @@
    private long testBeginTimeout;

    /**
-   * Timeout for individual test method.  If System.currentTimeMillis() is  
later
-   * than this timestamp, then we need to pack up and go home.  Zero  
for "not
-   * yet set" (at the start of a test).  This interval begins when the
+   * Timeout for individual test method. If System.currentTimeMillis() is  
later
+   * than this timestamp, then we need to pack up and go home. Zero  
for "not yet
+   * set" (at the start of a test). This interval begins when the
     * testBeginTimeout interval is done.
     */
    private long testMethodTimeout;
@@ -522,6 +522,9 @@
      if (System.getProperty(PROP_JUNIT_HYBRID_MODE) != null) {
        runStyle = new RunStyleLocalWeb(this);
      }
+    // If no explicit disable argument presented,
+    // Enables assertions by default in all tests
+    options.setEnableAssertions(true);
    }

    @Override
@@ -586,11 +589,12 @@
        } else if (testMethodTimeout < currentTimeMillis) {
          double elapsed = (currentTimeMillis - testBeginTime) / 1000.0;
          throw new TimeoutException(
-            "The browser did not complete the test method "
+            "The browser did not complete the test method "
                  + messageQueue.getCurrentTestName() + " in "
-                + TEST_METHOD_TIMEOUT_MILLIS + "ms.\n  We have no results  
from: "
-                + messageQueue.getWorkingClients()
-                + "\n Actual time elapsed: " + elapsed + " seconds.\n");
+                + TEST_METHOD_TIMEOUT_MILLIS
+                + "ms.\n  We have no results from: "
+                + messageQueue.getWorkingClients() + "\n Actual time  
elapsed: "
+                + elapsed + " seconds.\n");
        }
      } else if (testBeginTimeout < currentTimeMillis) {
        double elapsed = (currentTimeMillis - testBeginTime) / 1000.0;
@@ -668,9 +672,8 @@
        currentModule.clearEntryPoints();
        currentModule.addEntryPointTypeName(GWTRunner.class.getName());
        // Squirrel away the name of the active module for GWTRunnerGenerator
-      ConfigurationProperty moduleNameProp
-          = currentModule.getProperties().createConfiguration(
-              "junit.moduleName", false);
+      ConfigurationProperty moduleNameProp =  
currentModule.getProperties().createConfiguration(
+          "junit.moduleName", false);
        moduleNameProp.setValue(moduleName);
        runStyle.maybeCompileModule(syntheticModuleName);
      }
@@ -701,7 +704,7 @@
        // contacted; something probably went wrong (the module failed to  
load?)
        testBeginTime = System.currentTimeMillis();
        testBeginTimeout = testBeginTime + TEST_BEGIN_TIMEOUT_MILLIS;
-      testMethodTimeout = 0;  // wait until test execution begins
+      testMethodTimeout = 0; // wait until test execution begins
        pumpEventLoop();
      } catch (TimeoutException e) {
        lastLaunchFailed = true;
=======================================
--- /trunk/user/test/com/google/gwt/dev/jjs/test/CoverageTest.java      Mon May 
 
18 11:47:32 2009
+++ /trunk/user/test/com/google/gwt/dev/jjs/test/CoverageTest.java      Mon Jul 
 
20 11:52:26 2009
@@ -22,9 +22,10 @@
   * possible in the Java to JavaScript compiler. This test is not at all  
intended
   * to execute correctly.
   */
-...@suppresswarnings("hiding")
  public class CoverageTest extends CoverageBase {

+  private static final double EPSILON = 0.000001;
+
    /**
     * TODO: document me.
     */
@@ -196,7 +197,8 @@
          assert i == 3 : 1.2f;
          fail();
        } catch (AssertionError e) {
-        assertEquals("1.2", e.getMessage());
+        double val = Double.parseDouble(e.getMessage());
+        assertTrue(Math.abs(1.2f - val) < EPSILON);
        }

        try {
@@ -514,6 +516,7 @@
        o = new CoverageTest().new Inner();
      }

+    @SuppressWarnings("static-access")
      private void testQualifiedNameReference() {
        // QualifiedNameReference
        CoverageTest m = new CoverageTest();
@@ -533,6 +536,7 @@
        assertEquals("D", 4, new CoverageTest().getNext().y);
      }

+    @SuppressWarnings("static-access")
      private void testReferenceCalls() {
        // MessageSend, QualifiedSuperReference, QualifiedThisReference,
        // SuperReference, ThisReference
@@ -557,6 +561,7 @@
        CoverageTest.super.sfoo();
      }

+    @SuppressWarnings("static-access")
      private Inner testReferences() {
        // FieldReference, QualifiedSuperReference, QualifiedThisReference,
        // SuperReference, ThisReference
@@ -598,6 +603,7 @@
        fail();
      }

+    @SuppressWarnings("static-access")
      private void testSynchronizedStatement() {
        // SynchronizedStatement
        synchronized (inner) {
=======================================
--- /trunk/user/test/com/google/gwt/event/shared/HandlerManagerTest.java        
 
Tue Apr 21 10:27:39 2009
+++ /trunk/user/test/com/google/gwt/event/shared/HandlerManagerTest.java        
 
Mon Jul 20 11:52:26 2009
@@ -202,24 +202,22 @@
      };
      manager.addHandler(MouseDownEvent.getType(), one);

-    if (!GWT.isScript()) {
+    if (HandlerManagerTest.class.desiredAssertionStatus()) {
        try {
          manager.fireEvent(new MouseDownEvent() {
          });
          fail("Should have thrown on remove");
        } catch (AssertionError e) { /* pass */
        }
-      return;
-    }
-
-    // Web mode, no asserts, so remove will quietly succeed.
-    manager.fireEvent(new MouseDownEvent() {
-    });
-    assertFired(one);
-    reset();
-    manager.fireEvent(new MouseDownEvent() {
-    });
-    assertFired(one, mouse1);
+    } else {
+      manager.fireEvent(new MouseDownEvent() {
+      });
+      assertFired(one);
+      reset();
+      manager.fireEvent(new MouseDownEvent() {
+      });
+      assertFired(one, mouse1);
+    }
    }

    public void testMultiFiring() {


--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to