Bug 366493 - SteppingTests.testStepOverAntCallSepVM fails on Mac
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java
index 364d5c5..07b2ac8 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -170,7 +170,9 @@
 			}
 		}
 		setEventSet(waiter.getEventSet());
-		assertNotNull("Program did not suspend, launch terminated.", suspendee);
+		if (suspendee == null) {
+			throw new TestAgainException("Retest - Program did not suspend, launch terminated");
+		}
 		return suspendee;		
 	}	
 	
@@ -389,7 +391,9 @@
 
 		Object suspendee= waiter.waitForEvent();
 		setEventSet(waiter.getEventSet());
-		assertNotNull("Program did not suspend.", suspendee);
+		if (suspendee == null) {
+			throw new TestAgainException("Retest - Program did not suspend");
+		}
 		return (AntThread)suspendee;
 	}	
 	
@@ -409,7 +413,9 @@
 
 		Object suspendee= waiter.waitForEvent();
 		setEventSet(waiter.getEventSet());
-		assertNotNull("Program did not suspend.", suspendee);
+		if (suspendee == null) {
+			throw new TestAgainException("Retest - Program did not suspend");
+		}
 		assertTrue("suspendee was not an AntThread", suspendee instanceof AntThread);
 		AntThread thread = (AntThread) suspendee;
 		IBreakpoint hit = getBreakpoint(thread);
@@ -579,7 +585,9 @@
 		
 		Object suspendee= waiter.waitForEvent();
 		setEventSet(waiter.getEventSet());
-		assertNotNull("Program did not suspend.", suspendee);
+		if (suspendee == null) {
+			throw new TestAgainException("Retest - Program did not suspend");
+		}
 		return (AntThread) suspendee;
 	}
 	
@@ -598,7 +606,9 @@
 		
 		Object suspendee= waiter.waitForEvent();
 		setEventSet(waiter.getEventSet());
-		assertNotNull("Program did not suspend.", suspendee);
+		if (suspendee == null) {
+			throw new TestAgainException("Retest - Program did not suspend");
+		}
 		return (AntThread) suspendee;
 	}
 
@@ -615,7 +625,9 @@
 		
 		Object suspendee= waiter.waitForEvent();
 		setEventSet(waiter.getEventSet());
-		assertNotNull("Program did not suspend.", suspendee);
+		if (suspendee == null) {
+			throw new TestAgainException("Retest - Program did not suspend");
+		}
 		return (AntThread) suspendee;		
 	}
 	
@@ -632,7 +644,9 @@
 		
 		Object suspendee= waiter.waitForEvent();
 		setEventSet(waiter.getEventSet());
-		assertNotNull("Program did not suspend.", suspendee);
+		if (suspendee == null) {
+			throw new TestAgainException("Retest - Program did not suspend");
+		}
 		return (AntThread) suspendee;
 	}	
 	
@@ -658,7 +672,9 @@
 		
 		Object suspendee= waiter.waitForEvent();
 		setEventSet(waiter.getEventSet());
-		assertNotNull("Program did not suspend.", suspendee);
+		if (suspendee == null) {
+			throw new TestAgainException("Retest - Program did not suspend");
+		}
 		return (AntThread) suspendee;		
 	}	
 
@@ -684,7 +700,9 @@
 		
 		Object suspendee= waiter.waitForEvent();
 		setEventSet(waiter.getEventSet());
-		assertNotNull("Program did not suspend.", suspendee);
+		if (suspendee == null) {
+			throw new TestAgainException("Retest - Program did not suspend");
+		}
 		return (AntThread) suspendee;		
 	}	
 	
@@ -710,7 +728,9 @@
 		
 		Object suspendee= waiter.waitForEvent();
 		setEventSet(waiter.getEventSet());
-		assertNotNull("Program did not suspend.", suspendee);
+		if (suspendee == null) {
+			throw new TestAgainException("Retest - Program did not suspend");
+		}
 		return (AntThread) suspendee;		
 	}	
     
@@ -744,6 +764,28 @@
          debugUIPreferences.setValue(IDebugUIConstants.PREF_ACTIVATE_WORKBENCH, activate);
 	}
 	
+	/**
+	 * When a test throws the 'try again' exception, try it again.
+	 * @see junit.framework.TestCase#runBare()
+	 */
+	public void runBare() throws Throwable {
+		boolean tryAgain = true;
+		int attempts = 0;
+		while (tryAgain) {
+			try {
+				attempts++;
+				super.runBare();
+				tryAgain = false;
+			} catch (TestAgainException e) {
+				System.err.println("Test failed attempt " + attempts + ". Re-testing: " + this.getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+				e.printStackTrace();
+				if (attempts > 5) {
+					tryAgain = false;
+				}
+			}
+		}
+	}
+	
 	/* (non-Javadoc)
 	 * @see junit.framework.TestCase#tearDown()
 	 */
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/RunToLineTests.java b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/RunToLineTests.java
index c8b826c..1086f43 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/RunToLineTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/RunToLineTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2005, 2009 IBM Corporation and others.
+ *  Copyright (c) 2005, 2012 IBM Corporation and others.
  *  All rights reserved. This program and the accompanying materials
  *  are made available under the terms of the Eclipse Public License v1.0
  *  which accompanies this distribution, and is available at
@@ -202,7 +202,9 @@
             DebugElementEventWaiter waiter = new DebugElementEventWaiter(DebugEvent.SUSPEND, thread);
             DebugUIPlugin.getStandardDisplay().syncExec(r);
             Object event = waiter.waitForEvent();
-            assertNotNull("no suspend event was recieved", event);
+            if (event == null) {
+    			throw new TestAgainException("Retest - no suspend event was recieved");
+    		}
             IStackFrame topStackFrame = thread.getTopStackFrame();
             assertNotNull("There must be a top stack frame", topStackFrame);
             assertEquals("wrong line", expectedLineNumber, topStackFrame.getLineNumber());
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/TestAgainException.java b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/TestAgainException.java
new file mode 100644
index 0000000..925aeb0
--- /dev/null
+++ b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/TestAgainException.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ant.tests.ui.debug;
+
+/**
+ * Exception to indicate a test should be run again when it fails.
+ * 
+ * @since 3.8
+ */
+public class TestAgainException extends RuntimeException {
+
+	/**
+	 * Generated serial version id
+	 */
+	private static final long serialVersionUID = -7743450644051812955L;
+
+	/**
+	 * Constructor
+	 * @param string
+	 */
+	public TestAgainException(String string) {
+		super(string);
+	}
+
+
+}
\ No newline at end of file