Skip to content

Commit 24279e9

Browse files
authored
Removing includedTests option and adding functionality for excludedTests (#238)
Removing includedTests option and adding functionality for excludedTests ### What's done: - added logic for excludedTests - updating test resources - removing includedTests option
1 parent 060d173 commit 24279e9

File tree

8 files changed

+50
-22
lines changed

8 files changed

+50
-22
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,8 @@ description = "My suite description"
139139
suiteName = DocsCheck, CaseCheck, NpeTests, e.t.c
140140
141141
# excluded tests in the suite (optional). Here you can provide names of excluded tests, separated by comma. By the default no tests are excluded.
142-
# names can have 'Test' postifix or can be without a postfix - this does not matter. Save will detect tests for both cases
143-
excludedTests = NameWithTestPostfix, NameWithoutPostfix, e.t.c
144-
145-
# tests included in the suite (optional). Here you can provide names of tests, that are included in this suite.
146-
By the default all tests in the same directory with 'save.toml' file are included in the suite.
147-
includedTests = NameWithTestPostfix, NameWithoutPostfix, e.t.c
142+
# to exclude tests use relative path to the root of test project (to the root directory of `save.toml`)
143+
excludedTests = ["warn/chapter1/GarbageTest.kt", "warn/otherDir/NewTest.kt"], e.t.c
148144
```
149145

150146
## <a name="plugins"></a> Using plugins for specific test-scenarios

examples/kotlin-diktat/warn/chapter1/GarbageTest.kt

Whitespace-only changes.

examples/kotlin-diktat/warn/chapter1/save.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
tags = ["tag1"]
33
description = "My suite description"
44
suiteName = "DocsCheck"
5+
excludedTests = ["warn/chapter1/GarbageTest.kt"]
56

67
[warn]

save-common/src/commonMain/kotlin/org/cqfn/save/core/plugin/Plugin.kt

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.cqfn.save.core.utils.ProcessBuilder
1010

1111
import okio.FileSystem
1212
import okio.Path
13+
import okio.Path.Companion.toPath
1314

1415
/**
1516
* Plugin that can be injected into SAVE during execution. Plugins accept contents of configuration file and then perform some work.
@@ -40,8 +41,8 @@ abstract class Plugin(
4041
*/
4142
fun execute(): Sequence<TestResult> {
4243
clean()
43-
// todo: pass individual groups of files to handleFiles? Or it will play bad with batch mode?
4444
val testFilesSequence = discoverTestFiles(testConfig.directory)
45+
4546
return if (testFilesSequence.any()) {
4647
logDebug("Discovered the following test resources: ${testFilesSequence.toList()}")
4748
handleFiles(testFilesSequence)
@@ -66,7 +67,23 @@ abstract class Plugin(
6667
* @return a sequence of files, grouped by test
6768
*/
6869
fun discoverTestFiles(root: Path): Sequence<List<Path>> {
70+
val excludedTests =
71+
testConfig
72+
.pluginConfigs
73+
.filterIsInstance<GeneralConfig>()
74+
.singleOrNull()
75+
?.excludedTests
76+
77+
if (!excludedTests.isNullOrEmpty()) {
78+
logDebug("Excluded tests for [${testConfig.location}] : $excludedTests")
79+
}
80+
6981
val rawTestFiles = rawDiscoverTestFiles(root.resourceDirectories())
82+
// removing excluded test resources
83+
.filterNot {
84+
isExcludedTest(it, excludedTests)
85+
}
86+
7087
return if (testFiles.isNotEmpty()) {
7188
rawTestFiles.filter { resourcesGroup ->
7289
// test can be specified by the name of one of it's files
@@ -79,6 +96,24 @@ abstract class Plugin(
7996
}
8097
}
8198

99+
private fun isExcludedTest(testFiles: List<Path>, excludedTests: List<String>?): Boolean {
100+
// common root of the test repository (not a location of a current test)
101+
val testRepositoryRoot = testConfig.getRootConfig().location
102+
// creating relative to root path from a test file
103+
// FixMe: https://github.com/cqfn/save/issues/241 here we are incorrectly using testFiles[0], as for example it is
104+
// "Expected" file for Fix plugin
105+
val testFileRelative =
106+
(testFiles[0].createRelativePathToTheRoot(testRepositoryRoot).toPath() / testFiles[0].name)
107+
.toString()
108+
.replace('\\', '/')
109+
110+
// excluding tests that are included in the excluded list
111+
return excludedTests
112+
?.map { it.replace('\\', '/') }
113+
?.contains(testFileRelative)
114+
?: false
115+
}
116+
82117
/**
83118
* Discover groups of resource files which will be used to run tests.
84119
*

save-common/src/commonMain/kotlin/org/cqfn/save/core/plugin/PluginConfig.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ interface PluginConfig {
5555
* @property description free text with a description
5656
* @property suiteName name of test suite that can be visible from save-cloud
5757
* @property excludedTests excluded tests from the run
58-
* @property includedTests if specified - only these tests will be run
5958
* @property expectedWarningsPattern - pattern with warnings that are expected from the test file
6059
*/
6160
@Serializable
@@ -65,7 +64,6 @@ data class GeneralConfig(
6564
val description: String? = null,
6665
val suiteName: String? = null,
6766
val excludedTests: List<String>? = null,
68-
val includedTests: List<String>? = null,
6967
val expectedWarningsPattern: Regex? = null,
7068
) : PluginConfig {
7169
override val type = TestConfigSections.GENERAL
@@ -87,7 +85,6 @@ data class GeneralConfig(
8785
this.description ?: other.description,
8886
this.suiteName ?: other.suiteName,
8987
this.excludedTests ?: other.excludedTests,
90-
this.includedTests ?: other.includedTests,
9188
this.expectedWarningsPattern ?: other.expectedWarningsPattern,
9289
)
9390
}
@@ -111,7 +108,6 @@ data class GeneralConfig(
111108
description,
112109
suiteName,
113110
excludedTests ?: emptyList(),
114-
includedTests ?: emptyList(),
115111
expectedWarningsPattern ?: defaultInputPattern,
116112
)
117113
}

save-core/src/commonNonJsMain/kotlin/org/cqfn/save/core/Save.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,13 @@ class Save(
118118
logDebug("=> Executing plugin: ${plugin::class.simpleName} for [${plugin.testConfig.location}]")
119119
reporter.onPluginExecutionStart(plugin)
120120
try {
121-
val rootDir = plugin.testConfig.getRootConfig().location
121+
val testRepositoryRootPath = plugin.testConfig.getRootConfig().location
122+
122123
plugin.execute()
123124
.onEach { event ->
124125
// calculate relative paths, because reporters don't need paths higher than root dir
125126
val resourcesRelative =
126-
event.resources.map { it.createRelativePathToTheRoot(rootDir).toPath() / it.name }
127+
event.resources.map { it.createRelativePathToTheRoot(testRepositoryRootPath).toPath() / it.name }
127128
reporter.onEvent(event.copy(resources = resourcesRelative))
128129
}
129130
.forEach(this::handleResult)

save-core/src/commonNonJsTest/kotlin/org/cqfn/save/core/MergeConfigsTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ internal val toml4 = nestedDir2 / "nestedDir3" / "nestedDir4" / "save.toml"
2626

2727
@Suppress("TOO_LONG_FUNCTION", "LOCAL_VARIABLE_EARLY_DECLARATION")
2828
class MergeConfigsTest {
29-
private val generalConfig1 = GeneralConfig("", listOf("Tag11", "Tag12"), "Description1", "suiteName1", listOf("excludedTests: test1"), listOf("includedTests: test2"))
30-
private val generalConfig2 = GeneralConfig("", listOf("Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"), listOf("includedTests: test4"))
29+
private val generalConfig1 = GeneralConfig("", listOf("Tag11", "Tag12"), "Description1", "suiteName1", listOf("excludedTests: test1"))
30+
private val generalConfig2 = GeneralConfig("", listOf("Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"))
3131
private val generalConfig3 = GeneralConfig("", listOf("Tag21", "Tag31", "Tag32"), "Description2", "suiteName3", listOf("excludedTests: test5", "includedTests: test6"))
32-
private val generalConfig4 = GeneralConfig("", listOf("Tag11", "Tag21"), "Description2", "suiteName4", listOf("excludedTests: test7"), listOf("includedTests: test8"))
32+
private val generalConfig4 = GeneralConfig("", listOf("Tag11", "Tag21"), "Description2", "suiteName4", listOf("excludedTests: test7"))
3333
private val warningsOutputPattern1 = Regex(".*")
3434
private val warningsOutputPattern2 = Regex("\\w+ - (\\d+)/(\\d+) - (.*)$")
3535
private val warnConfig1 = WarnPluginConfig("execCmd1", warningsOutputPattern2,
@@ -58,7 +58,7 @@ class MergeConfigsTest {
5858
assertEquals(1, config2.pluginConfigs.size)
5959

6060
val expectedGeneralConfig =
61-
GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"), listOf("includedTests: test4"))
61+
GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"))
6262

6363
val actualGeneralConfig = config2.pluginConfigs.filterIsInstance<GeneralConfig>().first()
6464

@@ -76,7 +76,7 @@ class MergeConfigsTest {
7676
assertEquals(2, config2.pluginConfigs.size)
7777

7878
val expectedGeneralConfig =
79-
GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"), listOf("includedTests: test4"))
79+
GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"))
8080

8181
val actualGeneralConfig = config2.pluginConfigs.filterIsInstance<GeneralConfig>().first()
8282
val actualWarnConfig = config2.pluginConfigs.filterIsInstance<WarnPluginConfig>().first()
@@ -113,7 +113,7 @@ class MergeConfigsTest {
113113
assertEquals(3, config2.pluginConfigs.size)
114114

115115
val expectedGeneralConfig =
116-
GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"), listOf("includedTests: test4"))
116+
GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"))
117117
val expectedWarnConfig = WarnPluginConfig("execCmd3", warningsOutputPattern2,
118118
true, false, 1, ", ", 3, 3, 3, 3, 3, 3, 3, true)
119119
val expectedFixConfig = FixPluginConfig("fixCmd2", 1, "Suffix")
@@ -139,7 +139,7 @@ class MergeConfigsTest {
139139

140140
assertEquals(3, config4.pluginConfigs.size)
141141
val expectedGeneralConfig =
142-
GeneralConfig("", listOf("Tag11", "Tag12", "Tag21", "Tag31", "Tag32"), "Description2", "suiteName4", listOf("excludedTests: test7"), listOf("includedTests: test8"))
142+
GeneralConfig("", listOf("Tag11", "Tag12", "Tag21", "Tag31", "Tag32"), "Description2", "suiteName4", listOf("excludedTests: test7"))
143143
val expectedWarnConfig = WarnPluginConfig("execCmd4", warningsOutputPattern2,
144144
true, false, 1, ", ", 4, 4, 4, 4, 4, 4, 4, true)
145145
val expectedFixConfig = FixPluginConfig("fixCmd4", 1, "Suffix")

save-core/src/commonNonJsTest/kotlin/org/cqfn/save/core/ValidationTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class ValidationTest {
2626

2727
val actualGeneralConfig1 = config.pluginConfigs.filterIsInstance<GeneralConfig>().first()
2828
assertEquals(emptyList(), actualGeneralConfig1.excludedTests)
29-
assertEquals(emptyList(), actualGeneralConfig1.includedTests)
3029
}
3130

3231
@Test
@@ -41,7 +40,7 @@ class ValidationTest {
4140
assertEquals(
4241
"""
4342
Error: Couldn't find `execCmd` in [general] section of `${generalConfig.configLocation}` config.
44-
Current configuration: execCmd=null, tags=null, description=null, suiteName=null, excludedTests=null, includedTests=null, expectedWarningsPattern=null
43+
Current configuration: execCmd=null, tags=null, description=null, suiteName=null, excludedTests=null, expectedWarningsPattern=null
4544
Please provide it in this, or at least in one of the parent configs.
4645
""".trimIndent(),
4746
ex.message

0 commit comments

Comments
 (0)