This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid use of xtext.junit4 in xtext tests
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
- Loading branch information
Showing
55 changed files
with
829 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...t.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/util/StopwatchRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012 itemis AG (http://www.itemis.eu) and others. | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.xtext.common.types.util; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.util.Date; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
import org.eclipse.xtext.util.internal.Stopwatches; | ||
import org.eclipse.xtext.util.internal.Stopwatches.NumbersForTask; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
/** | ||
* @author Sven Efftinge - Initial contribution and API | ||
*/ | ||
public class StopwatchRule implements TestRule { | ||
|
||
private boolean watchAll = false; | ||
|
||
public StopwatchRule() { | ||
} | ||
|
||
/** | ||
* @param watchAll <code>true</code> if all tests should be timed, <code>false</code> | ||
* if only tests should be considered which are annotated with {@link Timed @Timed} | ||
*/ | ||
public StopwatchRule(boolean watchAll) { | ||
this.watchAll = watchAll; | ||
} | ||
|
||
public static Date DATE = new Date(); | ||
|
||
public void printStopwatchData(Description description, Map<String, Stopwatches.NumbersForTask> data, long timeSpend) { | ||
String property = System.getProperty("stopwatch.file"); | ||
String isJson = System.getProperty("stopwatch.json"); | ||
PrintStream out = System.out; | ||
FileOutputStream outputStream = null; | ||
if (property != null) { | ||
try { | ||
outputStream = new FileOutputStream(new File(property), true); | ||
out = new PrintStream(outputStream); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
try { | ||
if (isJson == null) { | ||
out.println("-------------------------------------------------------------------------------------------------------------------------\n"); | ||
out.println("Test '" + description.getDisplayName() + "' :"); | ||
out.println(getStopwatchDataAsReadableString(data)); | ||
} else { | ||
out.println(",{"); | ||
out.println(" \"name\" : \""+description.getDisplayName()+"\","); | ||
out.println(" \"date\" : \""+DATE+"\","); | ||
out.println(" \"time\" : \""+timeSpend+"\","); | ||
out.println(" \"tasks\" : ["); | ||
Iterator<Entry<String, NumbersForTask>> iter = data.entrySet().iterator(); | ||
while (iter.hasNext()) { | ||
Entry<String, NumbersForTask> task = iter.next(); | ||
out.print(" {\"name\" : \""+task.getKey()+"\",\"time\" : "+task.getValue().getMilliseconds()+",\"measurements\" : "+task.getValue().getNumberOfMeasurements()); | ||
if (iter.hasNext()) { | ||
out.println("},"); | ||
} else { | ||
out.println("}"); | ||
} | ||
} | ||
out.println(" ]"); | ||
out.println("}"); | ||
} | ||
} finally { | ||
// out.flush(); | ||
if (outputStream != null) | ||
try { | ||
outputStream.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
public String getStopwatchDataAsReadableString(Map<String, NumbersForTask> data) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("-------------------------------------------------------------------------------------------------------------------------\n"); | ||
for (Entry<String, NumbersForTask> task : data.entrySet()) { | ||
sb.append("Task '" + task.getKey() + "' took " + task.getValue().getMilliseconds() + "ms (" | ||
+ task.getValue().getNumberOfMeasurements() + " measurements).\n"); | ||
} | ||
sb.append("-------------------------------------------------------------------------------------------------------------------------\n"); | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public Statement apply(final Statement base, final Description description) { | ||
if (!watchAll && description.getAnnotation(Timed.class) == null) | ||
return base; | ||
return new Statement() { | ||
@Override | ||
public void evaluate() throws Throwable { | ||
long timeSpend = -1; | ||
try { | ||
Stopwatches.setEnabled(true); | ||
Stopwatches.resetAll(); | ||
long before = System.currentTimeMillis(); | ||
base.evaluate(); | ||
timeSpend = System.currentTimeMillis()-before; | ||
} finally { | ||
printStopwatchData(description, Stopwatches.allNumbers(), timeSpend); | ||
Stopwatches.resetAll(); | ||
Stopwatches.setEnabled(false); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...pse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/util/Timed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012 itemis AG (http://www.itemis.eu) and others. | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.xtext.common.types.util; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* @author Sven Efftinge - Initial contribution and API | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
@Documented | ||
public @interface Timed { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.