Skip to content

Commit 703e8ce

Browse files
authored
Adding a small workaround in logging: --quiet option and small bug fixes (#276)
### What's done: - option --quiet will supress all warnings that are produced by save, only info would be availiable - removing assertion that covered the case with multiple extraFlags in test resource - filtering out directories from test resources
1 parent e24c4dc commit 703e8ce

File tree

7 files changed

+27
-6
lines changed

7 files changed

+27
-6
lines changed

OptionsTable.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Most (except for `-h` and `-prop`) of the options below can be passed to a SAVE
66
| parallel | parallel-mode | Whether to enable parallel mode | false |
77
| t | threads | Number of threads | 1 |
88
| d | debug | Turn on debug logging | false |
9-
| q | quiet | Do not log anything | false |
9+
| q | quiet | Log only test results (if `--result-output` is `stdout`) without any warnings (only with critical errors) | false |
1010
| - | report-type | Type of generated report with execution results | PLAIN |
1111
| b | baseline | Path to the file with baseline data | - |
1212
| e | exclude-suites | Test suites, which won't be checked | - |

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"kotlinType": "kotlin.Boolean",
2929
"fullName" : "quiet",
3030
"shortName" : "q",
31-
"description" : "Do not log anything",
31+
"description" : "Log only test results (if `--result-output` is `stdout`) without any warnings (only with critical errors)",
3232
"default" : "false"
3333
},
3434
"reportType" : {

examples/kotlin-diktat/warn/chapter1/MyTest/MyTest/MyTest.kt/EmptyFile.kt

Whitespace-only changes.

save-cli/src/nativeMain/kotlin/org/cqfn/save/cli/SaveConfigReader.kt

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package org.cqfn.save.cli
77
import org.cqfn.save.cli.logging.logErrorAndExit
88
import org.cqfn.save.core.config.SaveProperties
99
import org.cqfn.save.core.logging.isDebugEnabled
10+
import org.cqfn.save.core.logging.isQuietMode
1011
import org.cqfn.save.core.logging.logDebug
1112

1213
import okio.FileNotFoundException
@@ -132,6 +133,7 @@ fun readPropertiesFile(propertiesFileName: String?): SaveProperties {
132133

133134
private fun tryToUpdateDebugLevel(properties: SaveProperties) {
134135
isDebugEnabled = properties.debug ?: false
136+
isQuietMode = properties.quiet ?: false
135137
}
136138

137139
private fun errorAndExitNotFoundDir() {

save-common/src/commonMain/kotlin/org/cqfn/save/core/logging/Logger.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import kotlinx.datetime.Clock
1212
import kotlinx.datetime.TimeZone
1313
import kotlinx.datetime.toLocalDateTime
1414

15+
/**
16+
* Is debug logging enabled
17+
*/
18+
var isQuietMode: Boolean = false
19+
1520
/**
1621
* Is debug logging enabled
1722
*/
@@ -66,7 +71,11 @@ fun logInfo(msg: String): Unit = logMessage("INFO", msg)
6671
*
6772
* @param msg a message string
6873
*/
69-
fun logWarn(msg: String): Unit = logMessage("WARN", msg, OutputStreamType.STDERR)
74+
fun logWarn(msg: String): Unit {
75+
if (!isQuietMode) {
76+
logMessage("WARN", msg, OutputStreamType.STDERR)
77+
}
78+
}
7079

7180
/**
7281
* Log a message with error level

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ abstract class Plugin(
8484

8585
val rawTestFiles = rawDiscoverTestFiles(root.resourceDirectories())
8686
// removing excluded test resources
87-
.filterNot {
88-
isExcludedTest(it, excludedTests)
89-
}
87+
.filterNot { isExcludedTest(it, excludedTests) }
88+
.filterNot { fs.metadata(it.test).isDirectory }
9089

9190
return if (testFiles.isNotEmpty()) {
9291
val foundTests = rawTestFiles.filter { rawTestFile ->

save-core/src/commonNonJsTest/kotlin/org/cqfn/save/core/integration/ClassicWarnTest.kt

+11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ class ClassicWarnTest {
4141
), 3
4242
)
4343

44+
@Test
45+
@Ignore
46+
// FixMe: this test should be investigated, as resource discovery looks to be buggy
47+
// org.opentest4j.AssertionFailedError: expected: <3> but was: <8>
48+
fun `executing warn plugin on parental directory`() =
49+
runTestsWithDiktat(
50+
listOf(
51+
"warn"
52+
), 3
53+
)
54+
4455
@Test
4556
fun `executing warn plugin on save-toml file in directory`() =
4657
runTestsWithDiktat(

0 commit comments

Comments
 (0)