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

Smoke tests in diktat #1534

Merged
merged 43 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5479d9b
Smoke tests in diktat
nulls Oct 26, 2022
f220666
split TestUtils.kt
nulls Oct 26, 2022
ce9a66e
refactored smoke tests
nulls Oct 26, 2022
24a376c
fixed test with kts
nulls Oct 26, 2022
8565768
diktatFix
nulls Oct 26, 2022
3ae8383
removed shade plugin
nulls Oct 27, 2022
9c73968
fixed default value for rulesConfig
nulls Oct 27, 2022
a5a048e
fixed default value for rulesConfig
nulls Oct 27, 2022
55d6f7d
unlink smoke tests
nulls Oct 27, 2022
d3319c5
removed test jar for diktat-rules
nulls Oct 27, 2022
c7c0e2d
reverted changes in FixTestBase
nulls Oct 27, 2022
a26f39a
refactored FixTestBase
nulls Oct 27, 2022
0cb6c92
diktatFix
nulls Oct 27, 2022
d994cf1
diktatFix #2
nulls Oct 27, 2022
a613a43
Merge branch 'master' into feature/move-intergration-test#1518
nulls Oct 27, 2022
1e73aa0
added logging in save-cli for windows too
nulls Oct 27, 2022
6e8e64a
Bugfix for fix mode of `AVOID_NULL_CHECK` (#1535)
sanyavertolet Oct 27, 2022
b89368b
Merge remote-tracking branch 'origin/master' into feature/move-interg…
nulls Oct 27, 2022
5257287
WIP
nulls Oct 27, 2022
0b96349
removed debug logging
nulls Oct 28, 2022
49b7d84
moved test run in maven
nulls Oct 28, 2022
0be5071
added **/DiktatSaveSmokeTest.* as include to failsafe
nulls Oct 28, 2022
6d24041
Merge branch 'master' into feature/move-intergration-test#1518
nulls Oct 28, 2022
61da8b2
fixed file name for save-cli tests
nulls Oct 28, 2022
3c3c706
timeout for save-cli smoke tests
nulls Oct 28, 2022
3883dbe
added tree reporter for failsafe too
nulls Oct 28, 2022
82df88b
set big timeout for save-cli process
nulls Oct 28, 2022
845b327
reverted to waitFor for further investigation
nulls Oct 28, 2022
92b7330
set maven.compiler.release only for JDK 11 and more
nulls Oct 28, 2022
1045c24
Merge remote-tracking branch 'origin/master' into feature/move-interg…
nulls Oct 28, 2022
cab2eed
fixed after merge resolving
nulls Oct 28, 2022
e4fa18b
diktatFix + review note
nulls Oct 28, 2022
29d8f51
upgraded save-cli version to 0.3.4
nulls Oct 28, 2022
caee1ac
removed unused methods
nulls Oct 28, 2022
044ada4
removed unused methods #2
nulls Oct 28, 2022
7f36ea1
diktatFix
nulls Oct 28, 2022
e1af678
diktatFix #2
nulls Oct 28, 2022
058e8b9
java exception
nulls Oct 28, 2022
15486d1
diktatFix
nulls Oct 28, 2022
ac8932f
diktatFix #2
nulls Oct 28, 2022
6748f91
diktatFix #3
nulls Oct 28, 2022
fe3696b
diktatFix #4
nulls Oct 28, 2022
a257547
set big timeout for save-cli process
nulls Oct 28, 2022
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
56 changes: 0 additions & 56 deletions diktat-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,37 +142,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>${junit-tree-reporter.version}</version>
</dependency>
</dependencies>
<configuration>
<excludes>
<exclude>*IntegrationTest*</exclude>
</excludes>
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<!-- Prefer @DisplayName & friends, if any. -->
<usePhrasedFileName>true</usePhrasedFileName>
<usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
<usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
</statelessTestsetReporter>
<!-- For the console output, use the tree reporter from
https://github.com/fabriciorby/maven-surefire-junit5-tree-reporter. -->
<reportFormat>plain</reportFormat>
<consoleOutputReporter>
<disable>true</disable>
</consoleOutputReporter>
<statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<!-- Prefer @DisplayName & friends, if any. -->
<usePhrasedFileName>true</usePhrasedFileName>
<usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
<!-- Avoid null's in *.txt summary -->
<usePhrasedClassNameInTestCaseSummary>false</usePhrasedClassNameInTestCaseSummary>
</statelessTestsetInfoReporter>
</configuration>
</plugin>
<plugin>
Expand All @@ -192,13 +165,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<dependencies>
<dependency>
<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>${junit-tree-reporter.version}</version>
</dependency>
</dependencies>
<configuration>
<systemProperties>
<maven.version>${maven.version}</maven.version>
Expand All @@ -207,28 +173,6 @@
<includes>
<include>**/*IntegrationTest*</include>
</includes>
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
<testClassesDirectory>${project.build.testOutputDirectory}</testClassesDirectory>
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<!-- Prefer @DisplayName & friends, if any. -->
<usePhrasedFileName>true</usePhrasedFileName>
<usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
<usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
</statelessTestsetReporter>
<!-- For the console output, use the tree reporter from
https://github.com/fabriciorby/maven-surefire-junit5-tree-reporter. -->
<reportFormat>plain</reportFormat>
<consoleOutputReporter>
<disable>true</disable>
</consoleOutputReporter>
<statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<!-- Prefer @DisplayName & friends, if any. -->
<usePhrasedFileName>true</usePhrasedFileName>
<usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
<!-- Avoid null's in *.txt summary -->
<usePhrasedClassNameInTestCaseSummary>false</usePhrasedClassNameInTestCaseSummary>
</statelessTestsetInfoReporter>
</configuration>
<executions>
<execution>
Expand Down
143 changes: 0 additions & 143 deletions diktat-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
<version>1.2.4-SNAPSHOT</version>
</parent>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<!-- kotlinpoet is needed only during build, but maven doesn't have such scope. -->
Expand Down Expand Up @@ -165,144 +160,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>${junit-tree-reporter.version}</version>
</dependency>
</dependencies>
<configuration>
<excludes>
<exclude>**/DiktatSaveSmokeTest.*</exclude>
</excludes>
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<!-- Prefer @DisplayName & friends, if any. -->
<usePhrasedFileName>true</usePhrasedFileName>
<usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
<usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
</statelessTestsetReporter>
<!-- For the console output, use the tree reporter from
https://github.com/fabriciorby/maven-surefire-junit5-tree-reporter. -->
<reportFormat>plain</reportFormat>
<consoleOutputReporter>
<disable>true</disable>
</consoleOutputReporter>
<statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<!-- Prefer @DisplayName & friends, if any. -->
<usePhrasedFileName>true</usePhrasedFileName>
<usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
<!-- Avoid null's in *.txt summary -->
<usePhrasedClassNameInTestCaseSummary>false</usePhrasedClassNameInTestCaseSummary>
</statelessTestsetInfoReporter>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>**/DiktatSaveSmokeTest.*</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<!-- These executions complement those defined in the parent pom.xml. -->
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>default-merge</id>
<phase>post-integration-test</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<includes>
<include>jacoco.exec</include>
<include>jacoco-it.exec</include>
</includes>
</fileSet>
</fileSets>
<destFile>${project.build.directory}/jacoco-merged.exec</destFile>
</configuration>
</execution>
<execution>
<id>default-report-merged</id>
<goals>
<goal>report-integration</goal>
</goals>
<configuration>
<outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
<dataFile>${project.build.directory}/jacoco-merged.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>

<!-- Create a fat JAR to be used in smoke tests, removing the
circular dependency between `diktat-rules` and `diktat-ruleset`. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<!-- Suppress the generation of `dependency-reduced-pom.xml`,
because it will also get installed under `~/.m2`,
resulting in the `diktat-maven-plugin` build failure
(the plug-in depends on `diktat-rules`). -->
<createDependencyReducedPom>false</createDependencyReducedPom>
<!-- Should be `false`: otherwise, the generated JAR, even
with a custom classifier, will still be installed/deployed. -->
<shadedArtifactAttached>false</shadedArtifactAttached>
<!-- Necessary: otherwise, the artifact produced by the JAR
plug-in will be overwritten by the fat JAR. -->
<finalName>${project.name}-${project.version}-fat-jar-for-smoke-tests</finalName>
<artifactSet>
<excludes>
<exclude>com.squareup:kotlinpoet</exclude>
<exclude>net.java.dev.jna:jna</exclude>
<exclude>org.jetbrains.intellij.deps:trove4j</exclude>
<exclude>org.jetbrains.kotlin:kotlin-compiler-embeddable</exclude>
<exclude>org.jetbrains.kotlin:kotlin-daemon-embeddable</exclude>
<exclude>org.jetbrains.kotlin:kotlin-reflect</exclude>
<exclude>org.jetbrains.kotlin:kotlin-script-runtime</exclude>
<exclude>org.jetbrains.kotlin:kotlin-stdlib-common</exclude>
<exclude>org.jetbrains.kotlin:kotlin-stdlib-jdk7</exclude>
<exclude>org.jetbrains.kotlin:kotlin-stdlib-jdk8</exclude>
<exclude>org.jetbrains.kotlin:kotlin-stdlib</exclude>
<exclude>org.jetbrains:annotations</exclude>
</excludes>
</artifactSet>
</configuration>
<executions>
<execution>
<id>fat-jar-for-smoke-tests</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
@file:Suppress("HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE")
@file:Suppress(
"HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE",
"Deprecation",
)

package org.cqfn.diktat.ruleset.utils

import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import com.pinterest.ktlint.core.KtLint
import com.pinterest.ktlint.core.KtLint.ExperimentalParams
import com.pinterest.ktlint.core.LintError
import com.pinterest.ktlint.core.RuleSetProvider
import mu.KotlinLogging
import org.intellij.lang.annotations.Language

@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}

@Suppress("TYPE_ALIAS")
val defaultCallback: (lintError: LintError, corrected: Boolean) -> Unit = { lintError, _ ->
log.warn("Received linting error: $lintError")
}

typealias LintErrorCallback = (LintError, Boolean) -> Unit

/**
* Enables ignoring autocorrected errors when in "fix" mode (i.e. when
Expand All @@ -27,3 +44,30 @@ fun ExperimentalParams.ignoreCorrectedErrors(): ExperimentalParams =
cb(error, false)
}
})

/**
Fixed Show fixed Hide fixed
* @param ruleSetProviderRef
* @param text
* @param fileName
* @param cb callback to be called on unhandled [LintError]s
* @return formatted code
*/
@Suppress("LAMBDA_IS_NOT_LAST_PARAMETER")
fun format(
ruleSetProviderRef: () -> RuleSetProvider,
@Language("kotlin") text: String,
fileName: String,
cb: LintErrorCallback = defaultCallback
): String {
val ruleSets = listOf(ruleSetProviderRef().get())
return KtLint.format(
ExperimentalParams(
text = text,
ruleSets = ruleSets,
fileName = fileName.removeSuffix("_copy"),
script = fileName.removeSuffix("_copy").endsWith("kts"),
cb = cb,
debug = true,
).ignoreCorrectedErrors()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.cqfn.diktat.common.config.rules.RuleConfiguration
/**
* [RuleConfiguration] for indentation logic
*/
internal class IndentationConfig(config: Map<String, String>) : RuleConfiguration(config) {
class IndentationConfig(config: Map<String, String>) : RuleConfiguration(config) {
/**
* Is newline at the end of a file needed
*/
Expand Down Expand Up @@ -87,20 +87,20 @@ internal class IndentationConfig(config: Map<String, String>) : RuleConfiguratio
override fun toString(): String =
"${javaClass.simpleName}$configWithExplicitDefaults"

internal companion object {
companion object {
internal const val ALIGNED_PARAMETERS = "alignedParameters"

/**
* The default indent size (space characters), configurable via
* `indentationSize`.
*/
private const val DEFAULT_INDENTATION_SIZE = 4
internal const val EXTENDED_INDENT_AFTER_OPERATORS = "extendedIndentAfterOperators"
internal const val EXTENDED_INDENT_BEFORE_DOT = "extendedIndentBeforeDot"
internal const val EXTENDED_INDENT_FOR_EXPRESSION_BODIES = "extendedIndentForExpressionBodies"
internal const val EXTENDED_INDENT_OF_PARAMETERS = "extendedIndentOfParameters"
internal const val INDENTATION_SIZE = "indentationSize"
internal const val NEWLINE_AT_END = "newlineAtEnd"
const val EXTENDED_INDENT_AFTER_OPERATORS = "extendedIndentAfterOperators"
const val EXTENDED_INDENT_BEFORE_DOT = "extendedIndentBeforeDot"
const val EXTENDED_INDENT_FOR_EXPRESSION_BODIES = "extendedIndentForExpressionBodies"
const val EXTENDED_INDENT_OF_PARAMETERS = "extendedIndentOfParameters"
const val INDENTATION_SIZE = "indentationSize"
const val NEWLINE_AT_END = "newlineAtEnd"

@Suppress("CUSTOM_GETTERS_SETTERS")
private val IndentationConfig.configWithExplicitDefaults: Map<String, String>
Expand Down
Loading