Skip to content

Commit

Permalink
Include information about test environment in test title
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Eysholdt <[email protected]>
  • Loading branch information
meysholdt committed Jun 30, 2017
1 parent ef2af46 commit 4bc9fb5
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 24 deletions.
20 changes: 8 additions & 12 deletions org.eclipse.xtext.example.arithmetics.xpect.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<systemProperties>
<xpectTestTitlePostfix>.${target-platform}</xpectTestTitlePostfix>
<xpectTestTitleShowEnvironment>true</xpectTestTitleShowEnvironment>
</systemProperties>
<reportsDirectory>${project.build.directory}/surefire-reports-standalone</reportsDirectory>
</configuration>
<executions>
Expand All @@ -127,18 +131,10 @@
</dependency>
</dependencies>
</plugin>
<!--
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports-plugin</reportsDirectory>
<useUIHarness>true</useUIHarness>
<useUIThread>false</useUIThread>
<argLine>${memory-settings} ${os-jvm-flags}</argLine>
</configuration>
</plugin> -->
<!-- <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version> <configuration> <reportsDirectory>${project.build.directory}/surefire-reports-plugin</reportsDirectory>
<useUIHarness>true</useUIHarness> <useUIThread>false</useUIThread> <argLine>${memory-settings}
${os-jvm-flags}</argLine> </configuration> </plugin> -->
</plugins>
</build>
</project>
12 changes: 12 additions & 0 deletions org.eclipse.xtext.example.domainmodel.xpect.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<systemProperties>
<xpectTestTitlePostfix>.${target-platform}</xpectTestTitlePostfix>
<xpectTestTitleShowEnvironment>true</xpectTestTitleShowEnvironment>
</systemProperties>
<reportsDirectory>${project.build.directory}/surefire-reports-plugin</reportsDirectory>
<useUIHarness>true</useUIHarness>
<useUIThread>false</useUIThread>
Expand Down Expand Up @@ -126,6 +130,10 @@
<useUIHarness>true</useUIHarness>
<useUIThread>false</useUIThread>
<argLine>${memory-settings} -XstartOnFirstThread</argLine>
<systemProperties>
<xpectTestTitlePostfix>.${target-platform}</xpectTestTitlePostfix>
<xpectTestTitleShowEnvironment>true</xpectTestTitleShowEnvironment>
</systemProperties>
<dependencies>
<dependency>
<type>eclipse-plugin</type>
Expand Down Expand Up @@ -195,6 +203,10 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<systemProperties>
<xpectTestTitlePostfix>.${target-platform}</xpectTestTitlePostfix>
<xpectTestTitleShowEnvironment>true</xpectTestTitleShowEnvironment>
</systemProperties>
<reportsDirectory>${project.build.directory}/surefire-reports-standalone</reportsDirectory>
</configuration>
<executions>
Expand Down
8 changes: 8 additions & 0 deletions org.xpect.releng/maven-test-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<systemProperties>
<xpectTestTitlePostfix>.${target-platform}</xpectTestTitlePostfix>
<xpectTestTitleShowEnvironment>true</xpectTestTitleShowEnvironment>
</systemProperties>
<reportsDirectory>${project.build.directory}/surefire-reports-plugin</reportsDirectory>
<useUIHarness>true</useUIHarness>
<useUIThread>true</useUIThread>
Expand All @@ -51,6 +55,10 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<systemProperties>
<xpectTestTitlePostfix>.${target-platform}</xpectTestTitlePostfix>
<xpectTestTitleShowEnvironment>true</xpectTestTitleShowEnvironment>
</systemProperties>
<!-- <debugForkedProcess>true</debugForkedProcess> -->
<reportsDirectory>${project.build.directory}/surefire-reports-standalone</reportsDirectory>
</configuration>
Expand Down
48 changes: 36 additions & 12 deletions org.xpect/src/org/xpect/runner/DescriptionFactory.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.xpect.runner;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.util.XtextVersion;
import org.junit.runner.Description;
import org.xpect.XpectFile;
import org.xpect.XpectInvocation;

import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

public class DescriptionFactory {

Expand All @@ -17,19 +20,19 @@ public static Description createFileDescription(Class<?> clazz, IXpectURIProvide
return result;
}

public static Description createFileDescription(String pathInProject, String fileName) {
String name = fileName + ": " + pathInProject;
Description result = Description.createSuiteDescription(name);
return result;
}

public static Description createFileDescription(XpectFile file) {
URI uri = file.eResource().getURI();
Preconditions.checkArgument(uri.isPlatform());
String pathInProject = Joiner.on('/').join(uri.segmentsList().subList(2, uri.segmentCount() - 1));
return createFileDescription(pathInProject, uri.lastSegment());
}

public static Description createFileDescription(String pathInProject, String fileName) {
String name = fileName + ": " + pathInProject;
Description result = Description.createSuiteDescription(name);
return result;
}

public static Description createFileDescriptionForError(Class<?> clazz, IXpectURIProvider uriProvider, URI uri) {
URI deresolved = uriProvider.deresolveToProject(uri);
String name = deresolved.lastSegment() + ": " + deresolved.trimSegments(1).toString();
Expand All @@ -39,9 +42,9 @@ public static Description createFileDescriptionForError(Class<?> clazz, IXpectUR

public static Description createTestDescription(Class<?> javaClass, IXpectURIProvider uriProvider, XpectInvocation invocation) {
URI uri = uriProvider.deresolveToProject(EcoreUtil.getURI(invocation));
TestTitleRegion titleRegion = invocation.getRelatedRegion(TestTitleRegion.class);
if (titleRegion != null && titleRegion.getTitle() != null)
return Description.createTestDescription(javaClass, uri.toString() + ": " + titleRegion.getTitle());
String title = getTitle(invocation);
if (!Strings.isNullOrEmpty(title))
return Description.createTestDescription(javaClass, uri.toString() + ": " + title);
else
return Description.createTestDescription(javaClass, uri.toString());
}
Expand All @@ -51,10 +54,31 @@ public static Description createTestDescription(XpectInvocation invocation) {
Preconditions.checkArgument(uri.isPlatform());
String className = invocation.getFile().getJavaModel().getTestOrSuite().getJvmClass().getQualifiedName();
String text = Joiner.on('/').join(uri.segmentsList().subList(2, uri.segmentCount())) + "#" + uri.fragment();
TestTitleRegion titleRegion = invocation.getRelatedRegion(TestTitleRegion.class);
if (titleRegion != null && titleRegion.getTitle() != null)
return Description.createTestDescription(className, text + ": " + titleRegion.getTitle());
String title = getTitle(invocation);
if (!Strings.isNullOrEmpty(title))
return Description.createTestDescription(className, text + ": " + title);
else
return Description.createTestDescription(className, text);
}

public static String getTitle(XpectInvocation inv) {
String postfix = System.getProperty("xpectTestTitlePostfix");
String env = System.getProperty("xpectTestTitleShowEnvironment");
TestTitleRegion titleRegion = inv.getRelatedRegion(TestTitleRegion.class);
StringBuilder result = new StringBuilder();
if (titleRegion != null) {
String title = titleRegion.getTitle();
if (!Strings.isNullOrEmpty(title)) {
result.append(title);
}
}
if (!Strings.isNullOrEmpty(postfix)) {
result.append(postfix);
}
if (!Strings.isNullOrEmpty(env)) {
result.append(EcorePlugin.IS_ECLIPSE_RUNNING ? ".plugin" : ".standalone");
result.append(".xtext_" + XtextVersion.getCurrent().getVersion());
}
return result.toString();
}
}

0 comments on commit 4bc9fb5

Please sign in to comment.