Skip to content

Migrated smoke test to diktat cli #1782

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

Merged
merged 5 commits into from
Nov 8, 2023
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
2 changes: 2 additions & 0 deletions diktat-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ dependencies {
implementation(projects.diktatRules)
implementation(libs.kotlinx.cli)
implementation(libs.kotlin.logging)
implementation(libs.slf4j.api)
implementation(libs.log4j2.core)
implementation(libs.log4j2.slf4j2)

testImplementation(projects.diktatTestFramework)
testImplementation(libs.junit.jupiter)
testImplementation(libs.junit.platform.suite)
testImplementation(libs.assertj.core)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.saveourtool.diktat.ruleset.smoke
package com.saveourtool.diktat.smoke

import com.saveourtool.diktat.api.DiktatError
import com.saveourtool.diktat.test.framework.processing.TestComparatorUnit
import com.saveourtool.diktat.test.framework.util.checkForkedJavaHome
import com.saveourtool.diktat.test.framework.util.deleteIfExistsRecursively
import com.saveourtool.diktat.test.framework.util.deleteIfExistsSilently
import com.saveourtool.diktat.test.framework.util.inheritJavaHome
import com.saveourtool.diktat.test.framework.util.isWindows
import com.saveourtool.diktat.test.framework.util.temporaryDirectory
import generated.KTLINT_VERSION

import io.github.oshai.kotlinlogging.KotlinLogging
import org.assertj.core.api.Assertions.fail
import org.assertj.core.api.SoftAssertions.assertSoftly
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.condition.DisabledOnOs
import org.junit.jupiter.api.condition.OS
Expand Down Expand Up @@ -73,15 +70,6 @@ class DiktatSaveSmokeTest : DiktatSmokeTestBase() {
*/
inheritJavaHome()

/*
* On Windows, ktlint is often unable to relativize paths
* (see https://github.com/pinterest/ktlint/issues/1608).
*
* Also, ktlint needs `.editorconfig` to disable standard rules
*
* So let's force the temporary directory to be the
* sub-directory of the project root.
*/
temporaryDirectory(baseDirectoryPath / TEMP_DIRECTORY)
}

Expand Down Expand Up @@ -152,9 +140,9 @@ class DiktatSaveSmokeTest : DiktatSmokeTestBase() {
}

/*
* The fat JAR should reside in the same directory as `ktlint` and
* `save*` and be named `diktat.jar`
* (see `diktat-rules/src/test/resources/test/smoke/save.toml`).
* The fat JAR should reside in the same directory as `save*` and
* be named `diktat.jar`
* (see `diktat-cli/src/test/resources/test/smoke/save.toml`).
*/
val buildDirectory = Path(BUILD_DIRECTORY)
softly.assertThat(buildDirectory)
Expand All @@ -170,10 +158,8 @@ class DiktatSaveSmokeTest : DiktatSmokeTestBase() {

val diktat = baseDirectoryPath / DIKTAT_FAT_JAR
val save = baseDirectoryPath / getSaveForCurrentOs()
val ktlint = baseDirectoryPath / KTLINT_FAT_JAR

downloadFile(URL("https://github.com/saveourtool/save-cli/releases/download/v$SAVE_VERSION/${getSaveForCurrentOs()}"), save)
downloadFile(URL("https://github.com/pinterest/ktlint/releases/download/$KTLINT_VERSION/ktlint"), ktlint)

diktatFrom?.copyTo(diktat, overwrite = true)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.saveourtool.diktat.ruleset.smoke
package com.saveourtool.diktat.smoke

import com.saveourtool.diktat.api.DiktatError
import com.saveourtool.diktat.ktlint.format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"BACKTICKS_PROHIBITED",
)

package com.saveourtool.diktat.ruleset.smoke
package com.saveourtool.diktat.smoke

import com.saveourtool.diktat.api.DiktatError
import com.saveourtool.diktat.common.config.rules.DIKTAT_COMMON
Expand Down Expand Up @@ -414,7 +414,6 @@ abstract class DiktatSmokeTestBase {
"Example1Test.kt" -> dest.copyTo(dest.parent.resolve("Example1-2Test.kt"))
}
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:Suppress("HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE")

package com.saveourtool.diktat.ruleset.smoke
package com.saveourtool.diktat.smoke

import com.saveourtool.diktat.test.framework.util.retry
import io.github.oshai.kotlinlogging.KotlinLogging
Expand All @@ -13,8 +13,7 @@ import kotlin.system.measureNanoTime

internal const val BUILD_DIRECTORY = "build/libs"
internal const val DIKTAT_FAT_JAR = "diktat.jar"
internal const val DIKTAT_FAT_JAR_GLOB = "diktat-*.jar"
internal const val KTLINT_FAT_JAR = "ktlint"
internal const val DIKTAT_FAT_JAR_GLOB = "diktat-cli-*.jar"

private val logger = KotlinLogging.logger {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[general]
execCmd="java -showversion -jar ktlint --log-level=debug -R diktat.jar"
execCmd="java -showversion -jar diktat.jar --log-level debug"
tags = ["smokeTest"]
description = "SmokeTest"
suiteName = "SmokeTest"
Expand All @@ -9,7 +9,7 @@ timeOutMillis = 3600000

["fix and warn"]
["fix and warn".fix]
execFlags="-F"
execFlags="--mode fix"
["fix and warn".warn]
lineCaptureGroup = 1
columnCaptureGroup = 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[general]
execCmd="java -showversion -jar ktlint --log-level=debug -R diktat.jar"
execCmd="java -showversion -jar diktat.jar --log-level debug"
tags = ["smokeTest"]
description = "SmokeTest"
suiteName = "SmokeTest"
Expand All @@ -8,7 +8,7 @@ expectedWarningsPattern = "// ;warn:?(.*):(\\d*): (.+)"

["fix and warn"]
["fix and warn".fix]
execFlags="-F"
execFlags="--mode fix"
["fix and warn".warn]
actualWarningsPattern = "(\\w+\\..+):(\\d+):(\\d+): (\\[.*\\].*)$"
exactWarningsMatch = false
12 changes: 0 additions & 12 deletions diktat-ruleset/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ dependencies {
implementation(libs.ktlint.cli.ruleset.core)
implementation(libs.ktlint.logger)
implementation(libs.slf4j.api)
testImplementation(projects.diktatTestFramework)
testImplementation(projects.diktatKtlintEngine)
testImplementation(libs.log4j2.slf4j2)
testImplementation(libs.kotlin.stdlib.common)
testImplementation(libs.kotlin.stdlib.jdk7)
testImplementation(libs.kotlin.stdlib.jdk8)
testImplementation(libs.kotlin.stdlib)
testImplementation(libs.kotlin.compiler.embeddable)
testImplementation(libs.junit.jupiter)
testImplementation(libs.junit.platform.suite)
testImplementation(libs.assertj.core)
testImplementation(libs.mockito)
}

tasks.named<ShadowJar>("shadowJar") {
Expand Down