Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests for diktat-maven-plugin #607

Merged
merged 9 commits into from
Dec 7, 2020
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
4 changes: 2 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
${{ runner.os }}-maven-build-
- name: Maven Package
run: mvn -B clean package -DskipTests
- name: Maven Verify
run: mvn -B verify
- name: Maven Install
run: mvn -B install
- name: Code coverage report
uses: codecov/codecov-action@v1
with:
Expand Down
94 changes: 90 additions & 4 deletions diktat-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<properties>
<maven.api.version>3.6.3</maven.api.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.itf.version>0.9.0</maven.itf.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -48,9 +49,15 @@
<version>${ktlint.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
Copy link
Member

@orchestr7 orchestr7 Dec 7, 2020

Choose a reason for hiding this comment

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

why vintage engine, not junit5?

Copy link
Member Author

Choose a reason for hiding this comment

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

maven-testing-harness, maven library for unit testing, supports only junit 3 and 4

<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.soebes.itf.jupiter.extension</groupId>
<artifactId>itf-jupiter-extension</artifactId>
<version>${maven.itf.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -66,6 +73,11 @@
<version>${maven.api.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -78,7 +90,7 @@
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
Expand All @@ -91,6 +103,7 @@
</goals>
<configuration>
<sourceDirs>
<!-- for some weird reason this is essential to compile kotlin test sources despite testSourceDirectory is set -->
<source>src/test/kotlin</source>
</sourceDirs>
</configuration>
Expand All @@ -101,7 +114,80 @@
<languageVersion>1.4</languageVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>*IntegrationTest*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>com.soebes.itf.jupiter.extension</groupId>
<artifactId>itf-maven-plugin</artifactId>
<version>${maven.itf.version}</version>
<executions>
<execution>
<id>installing</id>
<phase>pre-integration-test</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemProperties>
<maven.version>${maven.version}</maven.version>
<maven.home>${maven.home}</maven.home>
</systemProperties>
<includes>
<include>**/*IntegrationTest*</include>
</includes>
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
<testClassesDirectory>${project.build.testOutputDirectory}</testClassesDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- override jacoco config to include integration test results -->
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<testResources>
<testResource>
<directory>../examples/maven</directory>
<!-- setting filtering to false keeps unresolved properties, which in diktat-examples do not depend on diktat properties -->
<filtering>false</filtering>
<targetPath>${project.build.testOutputDirectory}/org/cqfn/diktat/plugin/maven/DiktatMavenPluginIntegrationTest/maven</targetPath>
</testResource>
</testResources>
</build>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.cqfn.diktat.plugin.maven

import com.soebes.itf.jupiter.extension.MavenGoal
import com.soebes.itf.jupiter.extension.MavenJupiterExtension
import com.soebes.itf.jupiter.extension.MavenTest
import com.soebes.itf.jupiter.maven.MavenExecutionResult
import org.junit.jupiter.api.Assertions
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.readText

/**
* Integration tests for diktat-maven-plugin.
* Run against the project from diktat-examples.
* Note: for maven itf test name should equal example project's directory name, which we have in pom.xml.
*/
@OptIn(ExperimentalPathApi::class)
@MavenJupiterExtension
class DiktatMavenPluginIntegrationTest {
@MavenTest
@MavenGoal("diktat:check@diktat")
fun maven(result: MavenExecutionResult) {
Assertions.assertEquals(1, result.returnCode)
Assertions.assertFalse(result.isError)
Assertions.assertFalse(result.isSuccesful)
Assertions.assertTrue(result.isFailure)

val mavenLog = result.mavenLog.stdout.readText()
Assertions.assertTrue(
mavenLog.contains("[HEADER_MISSING_OR_WRONG_COPYRIGHT]")
)
}
}
2 changes: 2 additions & 0 deletions diktat-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
</goals>
<configuration>
<sourceDirs>
<source>src/main/kotlin</source>
<source>src/test/kotlin</source>
<source>${project.basedir}/src/main/kotlin</source>
<source>${project.basedir}/src/test/kotlin</source>
</sourceDirs>
Expand Down