Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>lift/pom.xml</pomInclude>
<pomInclude>spaces in path/pom.xml</pomInclude>
</pomIncludes>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<streamLogs>true</streamLogs>
<settingsFile>src/it/settings.xml</settingsFile>
<postBuildHookScript>verify</postBuildHookScript>
<goals>
<goal>clean</goal>
<goal>test</goal>
Expand Down
21 changes: 21 additions & 0 deletions src/it/lift/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>@scala.maven.plugin.version@</version>
<configuration>
<recompileMode>incremental</recompileMode>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
<executions>
<execution>
<id>scala-compile</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
Expand Down
24 changes: 24 additions & 0 deletions src/it/lift/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

def logsFile = new File(basedir, "build.log")

if (!logsFile.exists()) {
throw new Exception("Could not find build.log. Searched: " + logsFile)
}

def testSummaryLines = []

logsFile.filterLine {
it ==~ /.*Tests: succeeded [0-9]*, failed [0-9]*, canceled [0-9]*, ignored [0-9]*, pending [0-9]*.*/
}.each { line -> testSummaryLines << "" + line }

if (testSummaryLines.size == 0) {
throw new Exception("Could not find scalatest's summary line in build.log")
} else if (testSummaryLines.size > 1) {
throw new Exception("Found more than one scalatest summary line in build.log")
}

if (testSummaryLines[0].contains("Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0")) {
throw new Exception("No tests were run by scalatest!")
}

return true
3 changes: 3 additions & 0 deletions src/it/spaces in path/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# spaces in path

This project is part of scalatest-maven-plugin's suite of integration tests. It is meant to check that scalatest-maven-plugin can run for projects that contain spaces in their file path.
3 changes: 3 additions & 0 deletions src/it/spaces in path/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# A comma or space separated list of goals/phases to execute, may
# specify an empty list to execute the default goal of the IT project
invoker.goals = clean test
95 changes: 95 additions & 0 deletions src/it/spaces in path/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spaces-in-path-it</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spaces-in-path-it</name>
<description>Runs the plugin for a project that contains spaces in the path.</description>

<parent>
<groupId>maven.scalatest.plugin.its</groupId>
<artifactId>it-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../it-parent</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>@scala.version@</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_@scala.major.version@</artifactId>
<version>@scalatest.version@</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>@scala.maven.plugin.version@</version>
<configuration>
<recompileMode>incremental</recompileMode>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
<executions>
<execution>
<id>scala-compile</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- disable surefire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<configuration>
<logForkedProcessCommand>true</logForkedProcessCommand>
</configuration>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
</project>
7 changes: 7 additions & 0 deletions src/it/spaces in path/src/main/scala/org/example/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example

class App {
def runApp(): String = {
"It ran!"
}
}
10 changes: 10 additions & 0 deletions src/it/spaces in path/src/test/scala/org/example/AppTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.example

import org.scalatest.{FlatSpec, Matchers}

class AppTest extends FlatSpec with Matchers {
"Our example App" should "run" in {
val app = new App
app.runApp() shouldBe "It ran!"
}
}
24 changes: 24 additions & 0 deletions src/it/spaces in path/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

def logsFile = new File(basedir, "build.log")

if (!logsFile.exists()) {
throw new Exception("Could not find build.log. Searched: " + logsFile)
}

def testSummaryLines = []

logsFile.filterLine {
it ==~ /.*Tests: succeeded [0-9]*, failed [0-9]*, canceled [0-9]*, ignored [0-9]*, pending [0-9]*.*/
}.each { line -> testSummaryLines << "" + line }

if (testSummaryLines.size == 0) {
throw new Exception("Could not find scalatest's summary line in build.log")
} else if (testSummaryLines.size > 1) {
throw new Exception("Found more than one scalatest summary line in build.log")
}

if (testSummaryLines[0].contains("Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0")) {
throw new Exception("No tests were run by scalatest!")
}

return true
29 changes: 27 additions & 2 deletions src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,37 @@ private List<String> config() {
}

private List<String> runpath() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main fix is in this method.

checkRunpathArgument("Output", outputDirectory);
checkRunpathArgument("Test output", testOutputDirectory);

String outputPath = outputDirectory.getAbsolutePath();
if(outputPath.contains(" ")) {
outputPath = outputPath.replaceAll(" ","\\\\ ");
getLog().debug(String.format("Escaped output directory path: %s", outputPath));
}

String testOutputPath = testOutputDirectory.getAbsolutePath();
if(testOutputPath.contains(" ")) {
testOutputPath = testOutputPath.replaceAll(" ","\\\\ ");
getLog().debug(String.format("Escaped test output directory path: %s", testOutputPath));
}

return compoundArg("-R",
outputDirectory.getAbsolutePath(),
testOutputDirectory.getAbsolutePath(),
outputPath,
testOutputPath,
runpath);
}

private void checkRunpathArgument(String directoryName, File directory) {
if(!directory.exists()) {
getLog().warn(String.format("%s directory does not exist: %s", directoryName, directory.getAbsolutePath()));
} else if(!directory.isDirectory()) {
getLog().warn(String.format("%s is not a directory: %s", directoryName, directory.getAbsolutePath()));
} else if(!directory.canRead()) {
getLog().warn(String.format("%s directory is not readable: %s", directoryName, directory.getAbsolutePath()));
}
}

private List<String> tagsToInclude() {
return compoundArg("-n", tagsToInclude);
}
Expand Down
12 changes: 10 additions & 2 deletions src/test/scala/org/scalatest/tools/maven/PluginTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ final class PluginTest
val tmpDir = new File(System.getProperty("java.io.tmpdir"))
val reportsDirectory = new File(tmpDir, "reportsDirectory")
val baseDir = new File(tmpDir, "basedir");
val testOutputDirectory = new File(reportsDirectory, "testOutputDirectory").getAbsolutePath
val outputDirectory = new File(reportsDirectory, "outputDirectory").getAbsolutePath
val testOutputDirectory = {
val dir = new File(reportsDirectory, "testOutputDirectory")
dir.mkdirs()
dir.getAbsolutePath
}
val outputDirectory = {
val dir = new File(reportsDirectory, "outputDirectory")
dir.mkdirs()
dir.getAbsolutePath
}

override def afterAll {
def delete(it: File) {
Expand Down