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

Migrate diktat smoke tests to SAVE-cli mechanism #1388

Merged
merged 58 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3c2a4e4
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jun 21, 2022
d40ac6b
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jun 22, 2022
96abde1
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jun 22, 2022
660a7d1
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jun 23, 2022
4e6f391
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jun 23, 2022
963c456
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jun 23, 2022
71a9fd4
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jun 23, 2022
8287e61
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jun 23, 2022
9a27748
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jun 24, 2022
f045ee9
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jun 28, 2022
81b11b8
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jun 28, 2022
345bbb4
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jun 29, 2022
2e8f33c
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jun 29, 2022
355fd2b
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jun 30, 2022
e29f5d9
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 4, 2022
1764a4b
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jul 4, 2022
00628f7
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 5, 2022
e3e410e
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 5, 2022
33c5187
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 5, 2022
143d79e
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jul 5, 2022
5e610f3
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 5, 2022
ac59eca
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 5, 2022
b3456af
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 6, 2022
394d292
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jul 6, 2022
98dc4a2
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 6, 2022
c9ee5f4
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 7, 2022
7f5184a
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
703a37d
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jul 11, 2022
9f23ae5
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
289e135
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
abcdb8f
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
fa10731
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
3785fe8
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
f5127c0
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
756aa5e
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jul 11, 2022
ea5268c
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
80c375c
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
5ae5676
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
c1fb33a
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
d8a4e25
Fixing execution cmd
orchestr7 Jul 11, 2022
5122d82
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
95ba657
Fixing execution cmd
orchestr7 Jul 11, 2022
2464246
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
bb5a101
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 11, 2022
fe8f8eb
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 12, 2022
dd5e6be
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 12, 2022
18e08ff
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jul 12, 2022
4c8c223
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 12, 2022
3258081
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jul 12, 2022
ff780e4
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 12, 2022
f1e3878
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jul 14, 2022
91f3fd8
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 14, 2022
8e51f1e
Merge branch 'master' into feature/migrate_tests_to_save
Cheshiriks Jul 14, 2022
43a4de9
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 14, 2022
b6c3401
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 14, 2022
7fec3f3
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 14, 2022
04dc7ed
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 14, 2022
23ec13e
Migrate diktat smoke tests to SAVE-cli mechanism
Cheshiriks Jul 14, 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
20 changes: 17 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
restore-keys: |
maven-build-
- name: Maven Install
run: mvn -B clean install
run: mvn -B clean install -DskipTests
- name: Maven run test
run: mvn test
- name: Code coverage report
uses: codecov/codecov-action@v3
with:
Expand Down Expand Up @@ -141,13 +143,25 @@ jobs:
- name: Maven Install
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
run: |
mvn -B -T1C clean install
mvn -B -T1C clean install -DskipTests
shell: bash

- name: Maven run test
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
run: |
mvn test
shell: bash

- name: Maven Install on windows
if: runner.os == 'Windows'
run: |
mvn -B -T1C clean install
mvn -B -T1C clean install -DskipTests
shell: cmd

- name: Maven run test
if: runner.os == 'Windows'
run: |
mvn test
shell: cmd

# This step needs a Git repository, so it's impossible to extract it
Expand Down
6 changes: 6 additions & 0 deletions diktat-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<apache.httpclient.version>4.5.13</apache.httpclient.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -93,6 +94,11 @@
<groupId>com.bpodgursky</groupId>
<artifactId>jbool_expressions</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache.httpclient.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package org.cqfn.diktat.ruleset.smoke

import org.apache.commons.io.FileUtils
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.HttpClients
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeAll
import java.io.File
import java.io.FileOutputStream
import java.nio.file.Paths
import kotlin.io.path.exists
import kotlin.io.path.listDirectoryEntries
import kotlin.io.path.name
import kotlin.io.path.pathString

class DiktatSaveSmokeTest : DiktatSmokeTestBase() {
override fun fixAndCompare(
config: String,
test: String,
expected: String
) {
saveSmokeTest(config, test)
}

/**
* @param testPath path to file with code that will be transformed by formatter, relative to [resourceFilePath]
* @param configFilePath path of diktat-analysis file
*/
@Suppress("TOO_LONG_FUNCTION")
private fun saveSmokeTest(
configFilePath: String,
testPath: String
) {
val processBuilder = createProcessBuilderWithCmd(testPath)

val file = File("src/test/resources/test/smoke/tmpSave.txt")
val configFile = File("src/test/resources/test/smoke/diktat-analysis.yml")
val configFileFrom = File(configFilePath)

configFile.createNewFile()
file.createNewFile()

FileUtils.copyFile(configFileFrom, configFile)

processBuilder.redirectErrorStream(true)
processBuilder.redirectOutput(ProcessBuilder.Redirect.appendTo(file))

val process = processBuilder.start()
process.waitFor()

val output = file.readLines()
val saveOutput = output.joinToString("\n")

file.delete()

Assertions.assertTrue(
saveOutput.contains("SUCCESS")
)
}

companion object {
private const val KTLINT_VERSION = "0.46.1"
private const val SAVE_VERSION = "0.3.1"

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 -> ""
}

private fun downloadFile(url: String, file: File) {
val httpClient = HttpClients.createDefault()
val request = HttpGet(url)
httpClient.use {
val response: CloseableHttpResponse = httpClient.execute(request)
response.use {
val fileSave = response.entity
fileSave?.let {
FileOutputStream(file).use { outstream -> fileSave.writeTo(outstream) }
}
}
}
}

@BeforeAll
@JvmStatic
internal fun beforeAll() {
val diktatDir: String =
Paths.get("../diktat-ruleset/target")
.takeIf { it.exists() }
?.listDirectoryEntries()
?.single { it.name.contains("diktat") }
?.pathString ?: ""

val diktat = File("src/test/resources/test/smoke/diktat.jar")
val diktatFrom = File(diktatDir)
val save = File("src/test/resources/test/smoke/${getSaveForCurrentOs()}")
val ktlint = File("src/test/resources/test/smoke/ktlint")

ktlint.createNewFile()
save.createNewFile()
diktat.createNewFile()

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

FileUtils.copyFile(diktatFrom, diktat)
}

@AfterAll
@JvmStatic
internal fun afterAll() {
val diktat = File("src/test/resources/test/smoke/diktat.jar")
val configFile = File("src/test/resources/test/smoke/diktat-analysis.yml")
val save = File("src/test/resources/test/smoke/${getSaveForCurrentOs()}")
val ktlint = File("src/test/resources/test/smoke/ktlint")

diktat.delete()
configFile.delete()
ktlint.delete()
save.delete()
}
}
}
Loading