diff --git a/diktat-common-test/build.gradle.kts b/diktat-common-test/build.gradle.kts index 05c1ec5aea..b464999d4c 100644 --- a/diktat-common-test/build.gradle.kts +++ b/diktat-common-test/build.gradle.kts @@ -8,11 +8,7 @@ project.description = "Diktat common for tests" dependencies { api(projects.diktatCommon) - implementation(libs.kotlin.stdlib.jdk8) - implementation(libs.apache.commons.cli) - implementation(libs.apache.commons.io) implementation(libs.kotlin.logging) - implementation(libs.kotlinx.coroutines.core) implementation(libs.junit.jupiter.api) implementation(libs.assertj.core) } diff --git a/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestArgumentsReader.kt b/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestArgumentsReader.kt deleted file mode 100644 index 11a7353d84..0000000000 --- a/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestArgumentsReader.kt +++ /dev/null @@ -1,96 +0,0 @@ -package com.saveourtool.diktat.test.framework.config - -import com.saveourtool.diktat.common.cli.CliArgument -import com.saveourtool.diktat.common.config.reader.AbstractConfigReader -import io.github.oshai.kotlinlogging.KotlinLogging - -import org.apache.commons.cli.CommandLine -import org.apache.commons.cli.CommandLineParser -import org.apache.commons.cli.DefaultParser -import org.apache.commons.cli.HelpFormatter -import org.apache.commons.cli.Options -import org.apache.commons.cli.ParseException - -import java.io.IOException -import java.io.InputStream - -import kotlin.system.exitProcess -import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.decodeFromStream - -/** - * Class that gives access to properties of a test - * - * @param args CLI arguments - * @param classLoader [ClassLoader] which is used to load properties file - * @property properties properties from properties file - */ -class TestArgumentsReader( - private val args: Array, - val properties: TestFrameworkProperties, - classLoader: ClassLoader -) : AbstractConfigReader>() { - private val cliArguments: List? = classLoader.getResourceAsStream(properties.testFrameworkArgsRelativePath)?.let { read(it) } - private val cmd: CommandLine by lazy { parseArguments() } - - /** - * List of tests provided by user - */ - val tests: List by lazy { - val tests: String? = cmd.getOptionValue("t") - tests - ?.split(",") - ?.map { it.trim() } - ?: run { - log.error { - "Missing option --test or -t. Not able to run tests, please provide test names or use --all option to run all available tests" - } - exitProcess(2) - } - } - private val declaredOptions: Options by lazy { - val options = Options() - cliArguments - ?.map { it.convertToOption() } - ?.forEach { opt -> options.addOption(opt) } - ?: exitProcess(1) - options - } - - private fun parseArguments(): CommandLine { - val parser: CommandLineParser = DefaultParser() - val formatter = HelpFormatter() - val options = declaredOptions - val cmd: CommandLine - try { - cmd = parser.parse(options, args) - } catch (e: ParseException) { - log.error(e) { "Cannot parse command line arguments due to" } - formatter.printHelp("utility-name", options) - exitProcess(1) - } - return cmd - } - - /** - * Whether all tests should be run - * - * @return true if command has option "all" - */ - fun shouldRunAllTests() = cmd.hasOption("all") - - /** - * Parse JSON to a list of [CliArgument]s - * - * @param inputStream a [InputStream] representing input JSON - * @return list of [CliArgument]s - */ - @OptIn(ExperimentalSerializationApi::class) - @Throws(IOException::class) - override fun parse(inputStream: InputStream): List = Json.decodeFromStream(inputStream) - - companion object { - private val log = KotlinLogging.logger {} - } -} diff --git a/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestConfig.kt b/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestConfig.kt deleted file mode 100644 index 4afa88548c..0000000000 --- a/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestConfig.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.saveourtool.diktat.test.framework.config - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -/** - * This class is used to serialize/deserialize json representation - * that is used to store command line arguments - * @property executionCommand command line execution command, use shell like "cmd", "bash" or other - * @property expectedResultFile expected result file can be a full path or a relative path to a resource - * @property testFile testFile can be a full path or a relative path to a resource - * @property executionType executionType that controls processing of the test (like COMPARE, MIXED, CHECK_WARN, e.t.c) - * @property testProfile - * @property inPlace option that controls if changes and automatic fix should be done directly in file - */ -@Serializable -@Suppress("ForbiddenComment") -class TestConfig internal constructor( - val executionCommand: String, - val expectedResultFile: String, - val testFile: String, - val executionType: ExecutionType, - @SerialName("profile") val testProfile: TestProfile, - val inPlace: Boolean = false -) { - /** - * test name - it is not included in config content, but is injected on runtime by setter - */ - var testName: String? = null - private set - - // FixMe: not used by for now, fix the description when the class will be ready - override fun toString() = - """(executionCommand: $executionCommand, expectedResultFile: $expectedResultFile, inPlace: $inPlace, - executionType: $executionCommand)""" - - /** - * @param testName - * @return [TestConfig] with updated [testName] - */ - fun setTestName(testName: String): TestConfig { - this.testName = testName - return this - } - - /** - * Different modes of tests execution - */ - enum class ExecutionType { - CHECK_WARN, COMPARE, MIXED - } - - /** - * different profiles that can be used to control common processing part for tests - * (processing differs for different programming languages) - */ - @Suppress("UNUSED") - enum class TestProfile { - CXX, JAVA, KT, PYTHON - } -} diff --git a/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestConfigReader.kt b/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestConfigReader.kt deleted file mode 100644 index d8351fd451..0000000000 --- a/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestConfigReader.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.saveourtool.diktat.test.framework.config - -import com.saveourtool.diktat.common.config.reader.AbstractConfigReader - -import java.io.IOException -import java.io.InputStream - -import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.decodeFromStream - -/** - * A [AbstractConfigReader] to read tests configuration as [TestConfig] - */ -class TestConfigReader(configFilePath: String, classLoader: ClassLoader) : AbstractConfigReader() { - /** - * The [TestConfig] which is read from - */ - val config: TestConfig? = classLoader.getResourceAsStream(configFilePath)?.let { read(it) } - - /** - * @param inputStream input stream of data from config file - * @return [TestConfig] read from file - */ - @OptIn(ExperimentalSerializationApi::class) - @Throws(IOException::class) - override fun parse(inputStream: InputStream): TestConfig = Json.decodeFromStream(inputStream) -} diff --git a/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestFrameworkProperties.kt b/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestFrameworkProperties.kt deleted file mode 100644 index c29b4d2c13..0000000000 --- a/diktat-common-test/src/main/kotlin/com/saveourtool/diktat/test/framework/config/TestFrameworkProperties.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.saveourtool.diktat.test.framework.config - -import com.saveourtool.diktat.common.config.reader.ApplicationProperties - -/** - * [ApplicationProperties] for running tests - */ -class TestFrameworkProperties(propertiesFileName: String) : ApplicationProperties(propertiesFileName) { - private val testFrameworkResourcePath: String by lazy { properties.getProperty("test.framework.dir") } - private val testFilesDir: String by lazy { properties.getProperty("test.files.dir") } - - /** - * Relative path to a file with arguments for tests runner - */ - val testFrameworkArgsRelativePath: String by lazy { testFrameworkResourcePath + "/" + properties.getProperty("test.framework.arguments") } - - /** - * Relative path to test files directory - */ - val testFilesRelativePath: String = "$testFrameworkResourcePath/$testFilesDir" - - /** - * Relative path to test configs directory - */ - val testConfigsRelativePath: String by lazy { testFrameworkResourcePath + "/" + properties.getProperty("test.configs.dir") } - - /** - * Whether tests should be run in parallel - */ - val isParallelMode: Boolean by lazy { java.lang.Boolean.getBoolean(properties.getProperty("parallel.mode")) } -}