Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

1.18.1: Bazel based test runs fail in the KtTestCompiler #4140

Closed
davidburstromspotify opened this issue Sep 30, 2021 · 2 comments
Closed

1.18.1: Bazel based test runs fail in the KtTestCompiler #4140

davidburstromspotify opened this issue Sep 30, 2021 · 2 comments
Labels

Comments

@davidburstromspotify
Copy link
Contributor

When using Bazel as a test runner for Detekt extensions, the tests fail with

    => java.lang.ExceptionInInitializerError
       io.github.detekt.test.utils.CompileExtensionsKt.compileContentForTest(CompileExtensions.kt:14)
       io.github.detekt.test.utils.CompileExtensionsKt.compileContentForTest$default(CompileExtensions.kt:10)
       io.gitlab.arturbosch.detekt.test.RuleExtensionsKt.lint(RuleExtensions.kt:31)
       io.gitlab.arturbosch.detekt.test.RuleExtensionsKt.compileAndLint(RuleExtensions.kt:27)
       [...]
     Caused by: java.nio.file.FileSystemNotFoundException
       jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:169)
       jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:155)
       java.base/java.nio.file.Path.of(Path.java:208)
       java.base/java.nio.file.Paths.get(Paths.java:97)
       io.github.detekt.test.utils.ResourcesKt.resourceAsPath(Resources.kt:21)
       [...]

The difference between Gradle and Bazel in this case is that Gradle provides the test classes as file paths, whereas Bazel provides them in a JAR.

Since we're not using resource based tests in our consuming project, it's easy enough to fix this by deferring the root path calculation.

--- a/detekt-test-utils/src/main/kotlin/io/github/detekt/test/utils/KtTestCompiler.kt
+++ b/detekt-test-utils/src/main/kotlin/io/github/detekt/test/utils/KtTestCompiler.kt
@@ -23,7 +23,7 @@ import java.nio.file.Path
  */
 internal object KtTestCompiler : KtCompiler() {
 
-    private val root = resourceAsPath("/")
+    private val root by lazy { resourceAsPath("/") }
 
     fun compile(path: Path) = compile(root, path)
 

The question is, if we fix this, when might this be available in an upstream release?

@cortinico
Copy link
Member

The difference between Gradle and Bazel in this case is that Gradle provides the test classes as file paths, whereas Bazel provides them in a JAR.
Since we're not using resource based tests in our consuming project, it's easy enough to fix this by deferring the root path calculation.

Shouldn't we look into processing the resources as a JAR to address the Bazel scenario as well rather than excluding it?

The question is, if we fix this, when might this be available in an upstream release?

Discussed offline: This fix/patch will end up in Detekt 1.19.0 as it's basically a fix and not a regression 👍

@davidburstromspotify
Copy link
Contributor Author

The proposed patch fixes a real world issue. Maybe the resources based testing in Bazel can be fixed when it is a real world issue :)

davidburstromspotify added a commit to davidburstromspotify/detekt that referenced this issue Oct 8, 2021
It does not fix test cases that use resource files from the project, but it's a start at least.
davidburstromspotify added a commit to davidburstromspotify/detekt that referenced this issue Oct 12, 2021
It does not fix test cases that use resource files from the project, but it's a start at least.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants