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 12 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
45 changes: 0 additions & 45 deletions diktat-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,51 +259,6 @@
</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
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

This file was deleted.

87 changes: 25 additions & 62 deletions diktat-rules/src/test/kotlin/org/cqfn/diktat/util/FixTestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,57 @@ package org.cqfn.diktat.util
import org.cqfn.diktat.common.config.rules.RulesConfig
import org.cqfn.diktat.test.framework.processing.FileComparisonResult
import org.cqfn.diktat.test.framework.processing.TestComparatorUnit
import org.cqfn.diktat.test.framework.util.LintErrorCallback
import org.cqfn.diktat.test.framework.util.defaultCallback
import com.pinterest.ktlint.core.Rule
import com.pinterest.ktlint.core.RuleSetProvider
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.Assertions
import java.nio.file.Path
import kotlin.io.path.bufferedWriter
import kotlin.io.path.div

const val SAVE_VERSION: String = "0.3.2"

/**
* @property resourceFilePath path to files which will be compared in tests
* Base class for FixTest
*/
open class FixTestBase(
protected val resourceFilePath: String,
private val ruleSetProviderRef: (rulesConfigList: List<RulesConfig>?) -> RuleSetProvider,
private val cb: LintErrorCallback = defaultCallback,
private val rulesConfigList: List<RulesConfig>? = null,
resourceFilePath: String,
ruleSupplier: (rulesConfigList: List<RulesConfig>) -> Rule,
defaultRulesConfigList: List<RulesConfig>? = null,
cb: LintErrorCallback = defaultCallback,
) {
/**
* testComparatorUnit
*/
protected val testComparatorUnit = TestComparatorUnit(resourceFilePath) { text, fileName ->
format(ruleSetProviderRef, text, fileName, rulesConfigList, cb = cb)
private val testComparatorUnitSupplier = { overrideRulesConfigList: List<RulesConfig>? ->
TestComparatorUnit(
resourceFilePath = resourceFilePath,
ruleSetProviderSupplier = { DiktatRuleSetProvider4Test(ruleSupplier, overrideRulesConfigList ?: defaultRulesConfigList) },
cb = cb
)
}

constructor(resourceFilePath: String,
ruleSupplier: (rulesConfigList: List<RulesConfig>) -> Rule,
rulesConfigList: List<RulesConfig>? = null,
cb: LintErrorCallback = defaultCallback
) : this(
resourceFilePath,
{ overrideRulesConfigList -> DiktatRuleSetProvider4Test(ruleSupplier, overrideRulesConfigList) },
cb,
rulesConfigList
)

/**
* @param expectedPath path to file with expected result, relative to [resourceFilePath]
* @param testPath path to file with code that will be transformed by formatter, relative to [resourceFilePath]
* @param overrideRulesConfigList optional override to [rulesConfigList]
* @param overrideRulesConfigList optional override to [defaultRulesConfigList]
* @param trimLastEmptyLine whether the last (empty) line should be
* discarded when reading the content of [testPath].
* @see fixAndCompareContent
*/
protected fun fixAndCompare(
expectedPath: String,
testPath: String,
overrideRulesConfigList: List<RulesConfig> = emptyList()
) {
val testComparatorUnit = if (overrideRulesConfigList.isNotEmpty()) {
TestComparatorUnit(resourceFilePath) { text, fileName ->
format(ruleSetProviderRef, text, fileName, overrideRulesConfigList)
}
} else {
testComparatorUnit
}

overrideRulesConfigList: List<RulesConfig>? = null,
trimLastEmptyLine: Boolean = false,
) {
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
val testComparatorUnit = testComparatorUnitSupplier(overrideRulesConfigList)
Assertions.assertTrue(
testComparatorUnit
.compareFilesFromResources(expectedPath, testPath)
.compareFilesFromResources(expectedPath, testPath, trimLastEmptyLine)
.isSuccessful
)
}

private fun getSaveForCurrentOs() = when {
System.getProperty("os.name").startsWith("Linux", ignoreCase = true) -> "save-$SAVE_VERSION-linuxX64.kexe"
System.getProperty("os.name").startsWith("Mac", ignoreCase = true) -> "save-$SAVE_VERSION-macosX64.kexe"
System.getProperty("os.name").startsWith("Windows", ignoreCase = true) -> "save-$SAVE_VERSION-mingwX64.exe"
else -> ""
}

/**
* @param testPath path to file with code that will be transformed by formatter, relative to [resourceFilePath]
* @return ProcessBuilder
*/
protected fun createProcessBuilderWithCmd(testPath: String): ProcessBuilder {
val filesDir = "src/test/resources/test/smoke"
val savePath = "$filesDir/${getSaveForCurrentOs()}"

val systemName = System.getProperty("os.name")
val result = when {
systemName.startsWith("Linux", ignoreCase = true) || systemName.startsWith("Mac", ignoreCase = true) ->
ProcessBuilder("sh", "-c", "chmod 777 $savePath ; ./$savePath $filesDir/src/main/kotlin $testPath --log all")
else -> ProcessBuilder(savePath, "$filesDir/src/main/kotlin", testPath)
}
return result
}

/**
* Unlike [fixAndCompare], this method doesn't perform any assertions.
*
Expand Down Expand Up @@ -119,10 +84,8 @@ open class FixTestBase(
out.write(expectedContent)
}

val testComparatorUnit = TestComparatorUnit(tempDir.toString()) { text, fileName ->
format(ruleSetProviderRef, text, fileName, overrideRulesConfigList ?: rulesConfigList, cb)
}

return testComparatorUnit.compareFilesFromFileSystem(expected, actual)
val testComparatorUnit = testComparatorUnitSupplier(overrideRulesConfigList)
return testComparatorUnit
.compareFilesFromFileSystem(expected, actual, false)
}
}
Loading