diff --git a/pom.xml b/pom.xml index 9556a1a..35518d9 100644 --- a/pom.xml +++ b/pom.xml @@ -186,10 +186,12 @@ ${project.build.directory}/it lift/pom.xml + spaces in path/pom.xml ${project.build.directory}/local-repo true src/it/settings.xml + verify clean test diff --git a/src/it/lift/pom.xml b/src/it/lift/pom.xml index 7a954bd..808c582 100644 --- a/src/it/lift/pom.xml +++ b/src/it/lift/pom.xml @@ -75,6 +75,27 @@ net.alchim31.maven scala-maven-plugin @scala.maven.plugin.version@ + + incremental + ${scala.version} + + + + scala-compile + process-resources + + add-source + compile + + + + scala-test-compile + process-test-resources + + testCompile + + + org.mortbay.jetty diff --git a/src/it/lift/verify.groovy b/src/it/lift/verify.groovy new file mode 100644 index 0000000..9844e29 --- /dev/null +++ b/src/it/lift/verify.groovy @@ -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 diff --git a/src/it/spaces in path/README.md b/src/it/spaces in path/README.md new file mode 100644 index 0000000..86387bc --- /dev/null +++ b/src/it/spaces in path/README.md @@ -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. \ No newline at end of file diff --git a/src/it/spaces in path/invoker.properties b/src/it/spaces in path/invoker.properties new file mode 100644 index 0000000..e94ef0b --- /dev/null +++ b/src/it/spaces in path/invoker.properties @@ -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 diff --git a/src/it/spaces in path/pom.xml b/src/it/spaces in path/pom.xml new file mode 100644 index 0000000..b4c2a41 --- /dev/null +++ b/src/it/spaces in path/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + spaces-in-path-it + 1.0-SNAPSHOT + jar + spaces-in-path-it + Runs the plugin for a project that contains spaces in the path. + + + maven.scalatest.plugin.its + it-parent + 1.0-SNAPSHOT + ../it-parent + + + + + org.scala-lang + scala-library + @scala.version@ + + + org.scalatest + scalatest_@scala.major.version@ + @scalatest.version@ + test + + + + + src/main/scala + src/test/scala + + + net.alchim31.maven + scala-maven-plugin + @scala.maven.plugin.version@ + + incremental + ${scala.version} + + + + scala-compile + process-resources + + add-source + compile + + + + scala-test-compile + process-test-resources + + testCompile + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.7 + + true + + + + + org.scalatest + scalatest-maven-plugin + + true + + + + + test + + + + + + + + + + org.scalatest + scalatest-maven-plugin + + + + diff --git a/src/it/spaces in path/src/main/scala/org/example/App.scala b/src/it/spaces in path/src/main/scala/org/example/App.scala new file mode 100644 index 0000000..f7404a2 --- /dev/null +++ b/src/it/spaces in path/src/main/scala/org/example/App.scala @@ -0,0 +1,7 @@ +package org.example + +class App { + def runApp(): String = { + "It ran!" + } +} \ No newline at end of file diff --git a/src/it/spaces in path/src/test/scala/org/example/AppTest.scala b/src/it/spaces in path/src/test/scala/org/example/AppTest.scala new file mode 100644 index 0000000..d0024b6 --- /dev/null +++ b/src/it/spaces in path/src/test/scala/org/example/AppTest.scala @@ -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!" + } +} diff --git a/src/it/spaces in path/verify.groovy b/src/it/spaces in path/verify.groovy new file mode 100644 index 0000000..9844e29 --- /dev/null +++ b/src/it/spaces in path/verify.groovy @@ -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 diff --git a/src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java b/src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java index 129037d..ad1d007 100644 --- a/src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java +++ b/src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java @@ -431,12 +431,37 @@ private List config() { } private List runpath() { + 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 tagsToInclude() { return compoundArg("-n", tagsToInclude); } diff --git a/src/test/scala/org/scalatest/tools/maven/PluginTest.scala b/src/test/scala/org/scalatest/tools/maven/PluginTest.scala index b776f72..cecfab6 100644 --- a/src/test/scala/org/scalatest/tools/maven/PluginTest.scala +++ b/src/test/scala/org/scalatest/tools/maven/PluginTest.scala @@ -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) {