Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Tests from examples/kotlin-diktat/warn-dir are failing on Windows with diktat 1.1.0 #402

Open
orchestr7 opened this issue Jun 21, 2022 · 8 comments
Assignees
Labels
bug Something isn't working tests

Comments

@orchestr7
Copy link
Member

Probably we will need to delete all tests and simply test real scenarios on the executable save-cli

@orchestr7 orchestr7 added the bug Something isn't working label Jun 21, 2022
@petertrr
Copy link
Member

petertrr commented Jun 23, 2022

Do you mean WarnDirTest? As I can see from the latest CI run, this is the test that passes on Linux and fails on Windows

Looks like something is broken in ktlint's pattern matching. save-cli runs the following command:

java -jar ktlint --disabled_rules=standard -R diktat.jar  C:\Users\<user>\AppData\Local\Temp\WarnPlugin--1261806134\warn-dir\**\*.kt

which matches no files. I tried to experiment with forward slashes, but no luck. This, however

 java -jar ktlint --disabled_rules=standard --debug -R diktat.jar  C:\Users\<user>\AppData\Local\Temp\WarnPlugin--1261806134\warn-dir\chapter1\*.kt

works as expected.

Also, running tests by relative glob also works:

...\save\examples\kotlin-diktat> java -jar ktlint --disabled_rules=standard --debug -R diktat.jar warn-dir\**\*.kt

@orchestr7
Copy link
Member Author

Only on windows

@petertrr
Copy link
Member

I've opened saveourtool/diktat#1397 to investigate root cause and maybe even fix on ktlint's side. I'll disable these tests for now until this issue is resolved

@petertrr
Copy link
Member

petertrr commented Jun 23, 2022

Actually now that I investigated it a bit, I find behavior of wildCardInDirectoryMode quite confusing. Why, for example, for warn-dir/chapter1 we are passing pattern to the tested tool as warn-dir/**/*.kt instead of warn-dir/chapter1/**/*.kt? Here is the log:

[TRACE]: Discovered the following test resources: [Test(test=../examples/kotlin-diktat/warn-dir/chapter1/EnumValueSnakeCaseTest.kt), Test(test=../examples/kotlin-diktat/warn-dir/chapter1/GenericFunctionTest.kt), Test(test=../examples/kotlin-diktat/warn-dir/chapter1/SmallTest.kt)]
[DEBUG]: Validated plugin configuration for [../examples/kotlin-diktat/warn-dir/chapter1/save.toml] ([WARN])
...
[TRACE]: Constructed file names for execution for warn plugin: C:\Users\<user>\AppData\Local\Temp\WarnPlugin--89925833\warn-dir/**/*.kt
[..
[DEBUG]: Executing: CMD, /C, cd /d ../examples/kotlin-diktat && java -jar ktlint --disabled_rules=standard -R diktat.jar  C:\Users\<user>\AppData\Local\Temp\WarnPlugin--89925833\warn-dir/**/*.kt with timeout 90000 ms

I think we should append wildcard pattern to the root of test suite that is being currently executed.

Edit: this is because of this code:

var testRootPath = copyPaths[0].parent ?: ".".toPath()
while (testRootPath.parent != null && testRootPath.parent!!.name != tmpDirName) {
testRootPath = testRootPath.parent!!
}
"$testRootPath${getWildCardInDirectoryMode()}"

Edit 2: this logic even is fixed in this test:

@Test
fun `execute warn plugin on root directory`() {
val reporter = runTestsWithDiktat(listOf("warn-dir"), 6)
reporter.results.forEach { testResult ->
assertTrue(!testResult.debugInfo!!.execCmd!!.contains("chapter"))
}
}

but I can't neither remember nor understand why we implemented it this way :( @akuleshov7, do you remember if it's related to #350?

@orchestr7
Copy link
Member Author

orchestr7 commented Jun 24, 2022

As we discussed:

  1. [warn] plugin -> is simply processing separate files
  2. [warn] plugin + DIRECTORY flag -> run ONLY on this directory. Plugin uses from one single file with all warnings (no inline warnings). It will make the logic less complex. In this mode (with directory flag) we will ignore other nested save.toml files and detect tests from the file with expected warnings.

We need to create a logic on save-cloud for it also...

petertrr added a commit that referenced this issue Jun 24, 2022
* Disable tests that fails on Windows (`WarnDirTest`) 
* Overwrite existing test resources in gradle download tasks
* Fix matcher in `runTestWithDiktat` (`ClassicWarnTest` is now actually passing)

Tests are disabled until root cause of #402 is resolved
@petertrr petertrr changed the title Investigate save-cli test failures on Windows Tests from examples/kotlin-diktat/warn-dir are failing on Windows with diktat 1.1.0 Jun 24, 2022
@petertrr
Copy link
Member

To sum up, tests in save-cli are failing because of some issues with ktlint 0.45.x + diktat 1.1.x, as described in #402 (comment).
Let's create a separate issue for new logic of directory mode.

@kgevorkyan
Copy link
Member

Need to check the relevance of the problem, a lot of time have passed, and the versions of used tool were upgraded

@petertrr
Copy link
Member

We should try to re-enable tests disabled in #407 and see if they still fail. Otherwise, the problem is indeed resolved.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working tests
Projects
None yet
Development

No branches or pull requests

3 participants