Skip to content

Commit

Permalink
Add support for maven.test.redirectTestOutputToFile
Browse files Browse the repository at this point in the history
 - disable ANSI codes if enabled
 - allow customization of the output file name
 - fix IT verify scripts to catch empty line case
 - upgrade java version to 8
 - IT which verifies output is redirected
  • Loading branch information
metteo committed Sep 1, 2020
1 parent 4afcce5 commit c156aec
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 116 deletions.
180 changes: 97 additions & 83 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0"?>
<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">
<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>

<parent>
Expand All @@ -12,17 +14,21 @@
<artifactId>scalatest-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>2.0.1-SNAPSHOT</version>

<name>ScalaTest Maven Plugin</name>
<description>Integrates ScalaTest into Maven</description>

<properties>
<scala.major.version>2.11</scala.major.version>
<scala.minor.version>12</scala.minor.version>
<scala.version>${scala.major.version}.${scala.minor.version}</scala.version>

<scalatest.version>3.0.1</scalatest.version>
<scala.maven.plugin.version>4.3.0</scala.maven.plugin.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<build.timestamp>${maven.build.timestamp}</build.timestamp>
<maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format>
<maven.gpg.plugin.version>1.6</maven.gpg.plugin.version>
Expand All @@ -32,7 +38,8 @@
<junit.version>4.12</junit.version>
<maven.reporting.api.version>3.0</maven.reporting.api.version>
<maven.enforcer.plugin.version>1.4.1</maven.enforcer.plugin.version>
<java.version>6</java.version>

<java.version>8</java.version>
</properties>

<licenses>
Expand Down Expand Up @@ -129,16 +136,6 @@
</pluginManagement>

<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>

<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
Expand All @@ -161,8 +158,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.${java.version}</source>
<target>1.${java.version}</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -194,6 +191,7 @@
<pomIncludes>
<pomInclude>lift/pom.xml</pomInclude>
<pomInclude>spaces in path/pom.xml</pomInclude>
<pomInclude>redirect-output/pom.xml</pomInclude>
</pomIncludes>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<streamLogs>true</streamLogs>
Expand All @@ -206,21 +204,6 @@
</goals>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven.gpg.plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
Expand All @@ -245,58 +228,89 @@
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>
<version>2.6</version>
<configuration>
<filteringChanges>true</filteringChanges>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<charset>UTF-8</charset>
<docencoding>UTF-8</docencoding>
<docfilessubdirs>true</docfilessubdirs>
<show>package</show>
<source>1.${java.version}</source>
<detectLinks>true</detectLinks>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.2</version>
<configuration>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</reporting>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven.gpg.plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>
<version>2.6</version>
<configuration>
<filteringChanges>true</filteringChanges>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<charset>UTF-8</charset>
<docencoding>UTF-8</docencoding>
<docfilessubdirs>true</docfilessubdirs>
<show>package</show>
<source>${java.version}</source>
<detectLinks>true</detectLinks>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.2</version>
<configuration>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</reporting>
</profile>
</profiles>
</project>
8 changes: 7 additions & 1 deletion src/it/lift/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ if (testSummaryLines.size == 0) {
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")) {
def theLine = testSummaryLines[0]

if (theLine.isEmpty()) {
throw new Exception("Could not find scalatest's non empty summary line in build.log")
}

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

Expand Down
3 changes: 3 additions & 0 deletions src/it/redirect-output/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# redirect output

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 use test output redirect.
3 changes: 3 additions & 0 deletions src/it/redirect-output/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
96 changes: 96 additions & 0 deletions src/it/redirect-output/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

<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>redirect-output-it</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>redirect-output</name>
<description>Runs the plugin for a project that uses test output redirect.</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>[email protected]@</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>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</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/redirect-output/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/redirect-output/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!"
}
}
Loading

0 comments on commit c156aec

Please sign in to comment.