Skip to content

Commit ff844eb

Browse files
authored
execCmd and batchSize on cli args (#433)
* added cli args * added EvaluatedToolConfig
1 parent f064588 commit ff844eb

File tree

24 files changed

+186
-90
lines changed

24 files changed

+186
-90
lines changed

OptionsTable.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ Most (except for `-h` and `-prop`) of the options below can be passed to a SAVE
1212
| i | include-suites | Test suites, only which ones will be checked | - |
1313
| l | language | Language that you are developing analyzer for | UNDEFINED |
1414
| out | result-output | Data output stream | STDOUT |
15-
| - | report-dir | Path to directory, where to store output (when `resultOutput` is set to `FILE`) | save-reports |
15+
| - | report-dir | Path to directory, where to store output (when `resultOutput` is set to `FILE`) | save-reports |
16+
| - | override-exec-cmd | A temporary workaround for save-cloud to override `execCmd` in `save.toml` | - |
17+
| - | override-exec-flags | A temporary workaround for save-cloud to override `execFlags` in `save.toml` | - |
18+
| - | batch-size | Number of files execCmd will process at a time | 1 |
19+
| - | batch-separator | A separator to join test files to string if the tested tool supports processing of file batches (`batch-size` > 1) | , |

buildSrc/src/main/resources/config-options.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,37 @@
7878
"shortName" : "",
7979
"description" : "Path to directory, where to store output (when `resultOutput` is set to `FILE`)",
8080
"default" : "save-reports"
81+
},
82+
"overrideExecCmd" : {
83+
"argType": "ArgType.String",
84+
"kotlinType": "kotlin.String",
85+
"fullName": "override-exec-cmd",
86+
"shortName" : "",
87+
"description" : "A temporary workaround for save-cloud to override `execCmd` in `save.toml`",
88+
"default" : null
89+
},
90+
"overrideExecFlags" : {
91+
"argType": "ArgType.String",
92+
"kotlinType": "kotlin.String",
93+
"fullName": "override-exec-flags",
94+
"shortName" : "",
95+
"description" : "A temporary workaround for save-cloud to override `execFlags` in `save.toml`",
96+
"default" : null
97+
},
98+
"batchSize" : {
99+
"argType" : "ArgType.Int",
100+
"kotlinType": "kotlin.Int",
101+
"fullName" : "batch-size",
102+
"shortName" : "",
103+
"description" : "Number of files execCmd will process at a time",
104+
"default" : "1"
105+
},
106+
"batchSeparator" : {
107+
"argType": "ArgType.String",
108+
"kotlinType": "kotlin.String",
109+
"fullName": "batch-separator",
110+
"shortName" : "",
111+
"description" : "A separator to join test files to string if the tested tool supports processing of file batches (`batch-size` > 1)",
112+
"default" : ", "
81113
}
82114
}

save-cli/src/commonNonJsMain/kotlin/com/saveourtool/save/cli/config/SavePropertiesExt.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package com.saveourtool.save.cli.config
77
import com.saveourtool.save.cli.ExitCodes
88
import com.saveourtool.save.cli.fs
99
import com.saveourtool.save.cli.logging.logErrorAndExit
10+
import com.saveourtool.save.cli.logging.logWarn
1011
import com.saveourtool.save.core.config.SaveProperties
1112
import com.saveourtool.save.core.config.resolveSaveTomlConfig
1213
import com.saveourtool.save.core.logging.logDebug
@@ -51,6 +52,23 @@ private fun SaveProperties.validate(): SaveProperties {
5152
" Please provide a valid path to the test config via command-line or using the file with properties."
5253
)
5354
}
55+
if (batchSize < 1) {
56+
return logErrorAndExit(
57+
ExitCodes.INVALID_CONFIGURATION, "Property `batch-size` should be more or equal to 1."
58+
)
59+
}
60+
overrideExecCmd?.also {
61+
logWarn {
62+
"Property `override-exec-cmd` is a temporary workaround for `save-cloud`, " +
63+
"please be aware this property can be removed in future versions"
64+
}
65+
}
66+
overrideExecFlags?.also {
67+
logWarn {
68+
"Property `override-exec-flags` is a temporary workaround for `save-cloud`, " +
69+
"please be aware this property can be removed in future versions"
70+
}
71+
}
5472

5573
return this
5674
}

save-cli/src/commonNonJsMain/kotlin/com/saveourtool/save/cli/logging/Logger.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ import com.saveourtool.save.cli.ExitCodes
1515
*/
1616
@Deprecated("never use this method in save-core as it can lead to a break of save-cloud application")
1717
expect fun logErrorAndExit(exitCode: ExitCodes, message: String): Nothing
18+
19+
/**
20+
* Log result of [messageSupplier] with level WARN
21+
*
22+
* @param messageSupplier supplier for message to log
23+
*/
24+
expect fun logWarn(messageSupplier: () -> String): Unit

save-cli/src/jvmMain/kotlin/com/saveourtool/save/cli/logging/Logger.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ package com.saveourtool.save.cli.logging
66

77
import com.saveourtool.save.cli.ExitCodes
88
import com.saveourtool.save.core.logging.logError
9+
import com.saveourtool.save.core.logging.logWarn
910
import kotlin.system.exitProcess
1011

1112
actual fun logErrorAndExit(exitCode: ExitCodes, message: String): Nothing {
1213
logError(message)
1314
exitProcess(exitCode.code)
1415
}
16+
17+
actual fun logWarn(messageSupplier: () -> String) {
18+
logWarn(messageSupplier())
19+
}

save-cli/src/nativeMain/kotlin/com/saveourtool/save/cli/logging/Logger.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ package com.saveourtool.save.cli.logging
66

77
import com.saveourtool.save.cli.ExitCodes
88
import com.saveourtool.save.core.logging.logError
9+
import com.saveourtool.save.core.logging.logWarn
910
import kotlin.system.exitProcess
1011

1112
actual fun logErrorAndExit(exitCode: ExitCodes, message: String): Nothing {
1213
logError(message)
1314
exitProcess(exitCode.code)
1415
}
16+
17+
actual fun logWarn(messageSupplier: () -> String) {
18+
logWarn(messageSupplier())
19+
}

save-common-test/src/commonNonJsMain/kotlin/com/saveourtool/save/plugin/MockPlugin.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.saveourtool.save.plugin
22

3+
import com.saveourtool.save.core.config.EvaluatedToolConfig
34
import com.saveourtool.save.core.config.TestConfig
45
import com.saveourtool.save.core.files.createFile
56
import com.saveourtool.save.core.plugin.Plugin
@@ -20,7 +21,7 @@ class MockPlugin(baseDir: Path, testFiles: List<String> = emptyList()) : Plugin(
2021
useInternalRedirections = true,
2122
redirectTo = null
2223
) {
23-
override fun handleFiles(files: Sequence<TestFiles>): Sequence<TestResult> = emptySequence()
24+
override fun handleFiles(evaluatedToolConfig: EvaluatedToolConfig, files: Sequence<TestFiles>): Sequence<TestResult> = emptySequence()
2425

2526
override fun rawDiscoverTestFiles(resourceDirectories: Sequence<Path>): Sequence<TestFiles> = emptySequence()
2627

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.saveourtool.save.core.config
2+
3+
/**
4+
* Configuration for an evaluated tool, that is read from test suite configuration file (toml config) or cli
5+
*
6+
* @property execCmd
7+
* @property execFlags
8+
* @property batchSize it controls how many files execCmd will process at a time
9+
* @property batchSeparator A separator to join test files to string if the tested tool supports processing of file batches (`batch-size` > 1)
10+
*/
11+
data class EvaluatedToolConfig(
12+
val execCmd: String?,
13+
val execFlags: String?,
14+
val batchSize: Int,
15+
val batchSeparator: String,
16+
)

save-common/src/commonMain/kotlin/com/saveourtool/save/core/plugin/Plugin.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.saveourtool.save.core.plugin
22

3+
import com.saveourtool.save.core.config.EvaluatedToolConfig
34
import com.saveourtool.save.core.config.TestConfig
45
import com.saveourtool.save.core.config.isSaveTomlConfig
56
import com.saveourtool.save.core.files.createRelativePathToTheRoot
@@ -20,6 +21,7 @@ import kotlinx.serialization.Serializable
2021

2122
/**
2223
* Plugin that can be injected into SAVE during execution. Plugins accept contents of configuration file and then perform some work.
24+
*
2325
* @property testConfig
2426
* @property testFiles a list of files (test resources or save.toml configs)
2527
* @property fs describes the current file system
@@ -42,9 +44,10 @@ abstract class Plugin(
4244
/**
4345
* Perform plugin's work.
4446
*
47+
* @param evaluatedToolConfig a configuration for evaluated tool
4548
* @return a sequence of [TestResult]s for each group of test resources
4649
*/
47-
fun execute(): Sequence<TestResult> {
50+
fun execute(evaluatedToolConfig: EvaluatedToolConfig): Sequence<TestResult> {
4851
clean()
4952
val testFilesList = discoverTestFiles(testConfig.directory).toList()
5053

@@ -68,7 +71,7 @@ abstract class Plugin(
6871
val excludedTestResults = excludedTestFiles.map {
6972
TestResult(it, Ignored("Excluded by configuration"))
7073
}
71-
handleFiles(actualTestFiles.asSequence()) + excludedTestResults
74+
handleFiles(evaluatedToolConfig, actualTestFiles.asSequence()) + excludedTestResults
7275
} else {
7376
emptySequence()
7477
}
@@ -77,10 +80,11 @@ abstract class Plugin(
7780
/**
7881
* Perform plugin's work on a set of files.
7982
*
83+
* @param evaluatedToolConfig a configuration for evaluated tool
8084
* @param files a sequence of file groups, corresponding to tests.
8185
* @return a sequence of [TestResult]s for each group of test resources
8286
*/
83-
abstract fun handleFiles(files: Sequence<TestFiles>): Sequence<TestResult>
87+
abstract fun handleFiles(evaluatedToolConfig: EvaluatedToolConfig, files: Sequence<TestFiles>): Sequence<TestResult>
8488

8589
/**
8690
* Discover groups of resource files which will be used to run tests, applying additional filtering

save-common/src/commonMain/kotlin/com/saveourtool/save/core/plugin/PluginConfig.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface PluginConfig {
4141
val resourceNamePatternStr: String
4242

4343
/**
44-
* @param otherConfig - 'this' will be merged with 'other'
44+
* @param otherConfig 'this' will be merged with 'other'
4545
* @return merged config
4646
*/
4747
fun mergeWith(otherConfig: PluginConfig): PluginConfig
@@ -60,13 +60,13 @@ interface PluginConfig {
6060
* of nested configs, we can't detect whether the value are passed by user, or taken from default.
6161
* The logic of the default value processing will be provided in stage of validation
6262
*
63-
* @property execCmd a command that will be executed to check resources and emit warnings
63+
* @property execCmd a command that will be executed to check resources
6464
* @property tags special labels that can be used for splitting tests into groups
6565
* @property description free text with a description
6666
* @property suiteName name of test suite that can be visible from save-cloud
6767
* @property language to tests
6868
* @property excludedTests excluded tests from the run
69-
* @property expectedWarningsPattern - pattern with warnings that are expected from the test file
69+
* @property expectedWarningsPattern pattern with warnings that are expected from the test file
7070
* @property runConfigPattern everything from the capture group will be split by comma and then by `=`
7171
* @property timeOutMillis command execution time for one test
7272
* @property expectedWarningsMiddlePattern

0 commit comments

Comments
 (0)