diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8e5bb6f..939eb899 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,9 +26,9 @@ jobs: java: [ '8', '11', '17' ] platform: ['windows-latest', 'ubuntu-latest'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'adopt' java-version: ${{ matrix.java }} @@ -47,11 +47,11 @@ jobs: java: [ '8', '11', '17' ] platform: ['windows-latest', 'ubuntu-latest'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Gradle wrapper validation - uses: gradle/wrapper-validation-action@v1 + uses: gradle/wrapper-validation-action@v3 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'adopt' java-version: ${{ matrix.java }} @@ -74,13 +74,15 @@ jobs: # https://stackoverflow.com/questions/57921325/gradle-signarchives-unable-to-read-secret-key ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_KEY_PASSWORD }} ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_SIGNING_PRIVATE_KEY }} - GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: persist-credentials: false # without this, all access tokens set later on will be ignored - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'adopt' java-version: 11 @@ -133,4 +135,4 @@ jobs: ./gradlew setSnapshotVersionSuffix --info git add gradle.properties git commit -m "Setting next snapshot version [skip ci]" - git push https://x-access-token:${GH_PERSONAL_ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git --follow-tags + git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git --follow-tags diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 67b7061d..3aca93c0 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -23,5 +23,5 @@ jobs: needs: [check_duplicate_workflows] if: ${{ needs.check_duplicate_workflows.outputs.should_skip != 'true' }} steps: - - uses: actions/checkout@v3 - - uses: gradle/wrapper-validation-action@v1 + - uses: actions/checkout@v4 + - uses: gradle/wrapper-validation-action@v3 diff --git a/README.md b/README.md index 6679d262..9213a24e 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ To test KSP processors, you need to use the KSP dependency: ```Groovy dependencies { - testImplementation("com.github.tschuchortdev:kotlin-compile-testing-ksp:1.5.0") + testImplementation("com.github.tschuchortdev:kotlin-compile-testing-ksp:1.6.0") } ``` @@ -167,6 +167,7 @@ All code generated by the KSP processor will be written into the `KotlinCompilat - [komapper/komapper](https://github.com/komapper/komapper) - [SimonMarquis/SealedObjectInstances](https://github.com/SimonMarquis/SealedObjectInstances) - [ansman/kotshi](https://github.com/ansman/kotshi) +- [mcarleio/konvert](https://github.com/mcarleio/konvert) - your project... ## Java 16 compatibility diff --git a/build.gradle b/build.gradle index 33df96e1..40150a27 100644 --- a/build.gradle +++ b/build.gradle @@ -150,10 +150,14 @@ subprojects { sign publishing.publications.mavenJava } + test { + useJUnitPlatform() + } + dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - testImplementation group: 'junit', name: 'junit', version: '4.13.2' + testImplementation "org.junit.jupiter:junit-jupiter:5.9.3" testImplementation "org.mockito:mockito-core:4.7.0" testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0" testImplementation "org.assertj:assertj-core:3.24.2" diff --git a/core/build.gradle b/core/build.gradle index 53b1dc35..a45ee2c0 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,4 +1,5 @@ //file:noinspection GroovyAssignabilityCheck +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType plugins { id "com.github.gmazzo.buildconfig" version "3.1.0" @@ -16,6 +17,35 @@ buildConfig { } } +/* Multiple variants are offered of the dependencies kotlin-dom-api-compat and kotlin-stdlib-js. Usually, Gradle picks +* them automatically based on what kind of build it is, i.e. it would look for a platform JVM variant for this JVM build. +* Naturally, there is no JVM version for JS libraries. We need to fix the variant attributes manually so the right variant +* will be picked for runtime use in the JS compile tests. */ +configurations.all { + resolutionStrategy.dependencySubstitution { + substitute(module("org.jetbrains.kotlin:kotlin-dom-api-compat")) + .using variant(module("org.jetbrains.kotlin:kotlin-dom-api-compat:$embedded_kotlin_version")) { + attributes { + attribute(Attribute.of("org.jetbrains.kotlin.platform.type", KotlinPlatformType.class), KotlinPlatformType.js) + attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage, "kotlin-runtime")) + } + } + } +} + +configurations.all { + resolutionStrategy.dependencySubstitution { + substitute(module("org.jetbrains.kotlin:kotlin-stdlib-js")) + .using variant(module("org.jetbrains.kotlin:kotlin-stdlib-js:$embedded_kotlin_version")) { + attributes { + attribute(Attribute.of("org.jetbrains.kotlin.platform.type", KotlinPlatformType.class), KotlinPlatformType.js) + attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage, "kotlin-runtime")) + attribute(Attribute.of("org.jetbrains.kotlin.js.compiler", String), "ir") + } + } + } +} + dependencies { compileOnly 'com.google.auto.service:auto-service:1.1.1' kapt "com.google.auto.service:auto-service:1.1.1" @@ -31,7 +61,9 @@ dependencies { // running compiler plugins passed via the pluginClasspath CLI option works testRuntimeOnly "org.jetbrains.kotlin:kotlin-scripting-compiler:$embedded_kotlin_version" - //testRuntimeOnly "org.jetbrains.kotlin:kotlin-stdlib-js:$embedded_kotlin_version" + // Include Kotlin/JS standard library in test classpath for auto loading + testRuntimeOnly "org.jetbrains.kotlin:kotlin-stdlib-js" + testRuntimeOnly "org.jetbrains.kotlin:kotlin-dom-api-compat" // The Kotlin compiler should be near the end of the list because its .jar file includes // an obsolete version of Guava diff --git a/core/src/main/kotlin/com/tschuchort/compiletesting/HostEnvironment.kt b/core/src/main/kotlin/com/tschuchort/compiletesting/HostEnvironment.kt index 428553f7..be6046f4 100644 --- a/core/src/main/kotlin/com/tschuchort/compiletesting/HostEnvironment.kt +++ b/core/src/main/kotlin/com/tschuchort/compiletesting/HostEnvironment.kt @@ -27,6 +27,10 @@ internal object HostEnvironment { findInClasspath(kotlinDependencyRegex("kotlin-stdlib-js")) } + val kotlinDomApiCompatKlib: File? by lazy { + findInClasspath(kotlinDependencyRegex("kotlin-dom-api-compat")) + } + val kotlinReflectJar: File? by lazy { findInClasspath(kotlinDependencyRegex("kotlin-reflect")) } @@ -40,7 +44,7 @@ internal object HostEnvironment { } private fun kotlinDependencyRegex(prefix: String): Regex { - return Regex("$prefix(-[0-9]+\\.[0-9]+(\\.[0-9]+)?)([-0-9a-zA-Z]+)?\\.jar") + return Regex("$prefix(-[0-9]+\\.[0-9]+(\\.[0-9]+)?)([-0-9a-zA-Z]+)?(\\.jar|\\.klib)") } /** Tries to find a file matching the given [regex] in the host process' classpath */ @@ -60,7 +64,11 @@ internal object HostEnvironment { val classpaths = classGraph.classpathFiles val modules = classGraph.modules.mapNotNull { it.locationFile } + val klibs = System.getProperty("java.class.path") + .split(File.pathSeparator) + .filter { it.endsWith(".klib") } + .map(::File) - return (classpaths + modules).distinctBy(File::getAbsolutePath) + return (classpaths + modules + klibs).distinctBy(File::getAbsolutePath) } } diff --git a/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt b/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt index 081092a1..414b844d 100644 --- a/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt +++ b/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt @@ -354,6 +354,33 @@ class KotlinCompilation : AbstractKotlinCompilation() { args.disableStandardScript = disableStandardScript } + private fun convertJavacArgumentsListToMap(options: List): Map { + val result = mutableMapOf() + var i = 0 + + while (i < options.size) { + val option = options[i] + if (option.startsWith("-") || option.startsWith("--")) { + if (option.contains("=")) { + val (key, value) = option.split("=", limit = 2) + result[key] = value + } else { + // Check if the next element is a value for this option + val value = if (i + 1 < options.size && !options[i + 1].startsWith("-")) { + i++ // Increment the index to skip the value in the next iteration + options[i] + } else { + "" + } + result[option] = value + } + } + i++ + } + + return result + } + /** Performs the 1st and 2nd compilation step to generate stubs and run annotation processors */ private fun stubsAndApt(sourceFiles: List): ExitCode { if(annotationProcessors.isEmpty()) { @@ -373,14 +400,16 @@ class KotlinCompilation : AbstractKotlinCompilation() { it.mode = AptMode.STUBS_AND_APT - it.flags.apply { + it.javacOptions.putAll(convertJavacArgumentsListToMap(javacArguments)) + + it.flags.apply { addAll(kaptFlags) if (verbose) { addAll(KaptFlag.MAP_DIAGNOSTIC_LOCATIONS, KaptFlag.VERBOSE) } } - } + } val compilerMessageCollector = PrintingMessageCollector( internalMessageStream, MessageRenderer.GRADLE_STYLE, verbose diff --git a/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinJsCompilation.kt b/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinJsCompilation.kt index a295ea4f..71ca9a84 100644 --- a/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinJsCompilation.kt +++ b/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinJsCompilation.kt @@ -52,6 +52,15 @@ class KotlinJsCompilation : AbstractKotlinCompilation() { HostEnvironment.kotlinStdLibJsJar } + /** + * Path to the kotlin-dom-api-compat.klib + * If none is given, it will be searched for in the host + * process' classpaths + */ + var kotlinStdLibDomApi: File? by default { + HostEnvironment.kotlinDomApiCompatKlib + } + /** * Generate TypeScript declarations .d.ts file alongside JS file. Available in IR backend only */ @@ -90,7 +99,7 @@ class KotlinJsCompilation : AbstractKotlinCompilation() { args.moduleName = moduleName // -ir-output-name args.outputFile = File(outputDir, outputFileName).absolutePath args.sourceMapBaseDirs = jsClasspath().joinToString(separator = File.pathSeparator) - args.libraries = listOfNotNull(kotlinStdLibJsJar).joinToString(separator = ":") + args.libraries = listOfNotNull(kotlinStdLibJsJar, kotlinStdLibDomApi).joinToString(separator = File.pathSeparator) args.irProduceKlibDir = irProduceKlibDir args.irProduceKlibFile = irProduceKlibFile diff --git a/core/src/test/kotlin/com/tschuchort/compiletesting/CompilerPluginsTest.kt b/core/src/test/kotlin/com/tschuchort/compiletesting/CompilerPluginsTest.kt index f4391f4b..a01cc97b 100644 --- a/core/src/test/kotlin/com/tschuchort/compiletesting/CompilerPluginsTest.kt +++ b/core/src/test/kotlin/com/tschuchort/compiletesting/CompilerPluginsTest.kt @@ -2,9 +2,8 @@ package com.tschuchort.compiletesting import org.assertj.core.api.Assertions import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar -import org.junit.Assert -import org.junit.Ignore -import org.junit.Test +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test import org.mockito.Mockito import java.net.URL import javax.annotation.processing.AbstractProcessor @@ -55,7 +54,7 @@ class CompilerPluginsTest { override fun process(p0: MutableSet?, p1: RoundEnvironment?): Boolean { p1?.getElementsAnnotatedWith(ProcessElem::class.java)?.forEach { - Assert.assertEquals("JSource", it?.simpleName.toString()) + Assertions.assertThat("JSource").isEqualTo(it?.simpleName.toString()) } return false } @@ -88,7 +87,7 @@ class CompilerPluginsTest { Assertions.assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) } - @Ignore("JS tests don't currently work with the new compiler IR") + //@Disabled("JS tests don't currently work with the new compiler IR") @Test fun `when JS compiler plugins are added they get executed`() { val mockLegacyPlugin = Mockito.mock(ComponentRegistrar::class.java) diff --git a/core/src/test/kotlin/com/tschuchort/compiletesting/JavacUtilsTest.kt b/core/src/test/kotlin/com/tschuchort/compiletesting/JavacUtilsTest.kt index 542901d5..76358a86 100644 --- a/core/src/test/kotlin/com/tschuchort/compiletesting/JavacUtilsTest.kt +++ b/core/src/test/kotlin/com/tschuchort/compiletesting/JavacUtilsTest.kt @@ -1,52 +1,52 @@ package com.tschuchort.compiletesting -import org.junit.Assert.* -import org.junit.Test +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test class JavacUtilsTest { @Test fun `Old version scheme less than 9 is parsed correctly`() { - assertFalse(isJavac9OrLater("1.8.0")) + Assertions.assertFalse(isJavac9OrLater("1.8.0")) } @Test fun `Old version scheme greater equal 9 is parsed correctly`() { - assertTrue(isJavac9OrLater("1.9.1")) - assertTrue(isJavac9OrLater("1.11.0")) + Assertions.assertTrue(isJavac9OrLater("1.9.1")) + Assertions.assertTrue(isJavac9OrLater("1.11.0")) } @Test fun `New version scheme less than 9 is parsed correctly`() { - assertFalse(isJavac9OrLater("8.1.0.1")) - assertFalse(isJavac9OrLater("8.1.0")) - assertFalse(isJavac9OrLater("8.1")) - assertFalse(isJavac9OrLater("8")) + Assertions.assertFalse(isJavac9OrLater("8.1.0.1")) + Assertions.assertFalse(isJavac9OrLater("8.1.0")) + Assertions.assertFalse(isJavac9OrLater("8.1")) + Assertions.assertFalse(isJavac9OrLater("8")) } @Test fun `New version scheme greater equal 9 is parsed correctly`() { - assertTrue(isJavac9OrLater("9.0.0.1")) - assertTrue(isJavac9OrLater("9.0.0")) - assertTrue(isJavac9OrLater("9.1.0")) - assertTrue(isJavac9OrLater("9.1")) - assertTrue(isJavac9OrLater("9")) - assertTrue(isJavac9OrLater("12")) + Assertions.assertTrue(isJavac9OrLater("9.0.0.1")) + Assertions.assertTrue(isJavac9OrLater("9.0.0")) + Assertions.assertTrue(isJavac9OrLater("9.1.0")) + Assertions.assertTrue(isJavac9OrLater("9.1")) + Assertions.assertTrue(isJavac9OrLater("9")) + Assertions.assertTrue(isJavac9OrLater("12")) } @Test fun `Old version scheme with extra info is parsed correctly`() { - assertTrue(isJavac9OrLater("1.11.0-bla")) + Assertions.assertTrue(isJavac9OrLater("1.11.0-bla")) } @Test fun `Standard javac -version output is parsed correctly`() { - assertEquals("1.8.0_252", parseVersionString("javac 1.8.0_252")) + Assertions.assertEquals("1.8.0_252", parseVersionString("javac 1.8.0_252")) } @Test fun `javac -version output with JAVA OPTIONS is parsed correctly`() { - assertEquals( + Assertions.assertEquals( "1.8.0_222", parseVersionString( "Picked up _JAVA_OPTIONS: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap javac 1.8.0_222" @@ -56,7 +56,7 @@ class JavacUtilsTest { @Test fun `Wrong javac -version output is returning null`() { - assertNull( + Assertions.assertNull( parseVersionString( "wrong javac" ) diff --git a/core/src/test/kotlin/com/tschuchort/compiletesting/KotlinCompilationTests.kt b/core/src/test/kotlin/com/tschuchort/compiletesting/KotlinCompilationTests.kt index 686c9ec8..d92039dc 100644 --- a/core/src/test/kotlin/com/tschuchort/compiletesting/KotlinCompilationTests.kt +++ b/core/src/test/kotlin/com/tschuchort/compiletesting/KotlinCompilationTests.kt @@ -6,10 +6,9 @@ import org.assertj.core.api.Assertions.assertThat import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption import org.jetbrains.kotlin.compiler.plugin.CliOption import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor -import org.junit.Ignore -import org.junit.Rule -import org.junit.Test -import org.junit.rules.TemporaryFolder +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.io.TempDir import java.io.ByteArrayOutputStream import java.io.File import java.nio.file.Files @@ -17,10 +16,14 @@ import javax.annotation.processing.AbstractProcessor import javax.annotation.processing.RoundEnvironment import javax.lang.model.element.TypeElement import org.mockito.kotlin.* +import java.nio.file.Path +import java.util.regex.Pattern +import kotlin.io.path.createDirectory +import kotlin.io.path.createFile +import kotlin.io.path.writeText @Suppress("MemberVisibilityCanBePrivate", "RemoveEmptyClassBody", "RedundantSemicolon", "RemoveEmptyPrimaryConstructor") class KotlinCompilationTests { - @Rule @JvmField val temporaryFolder = TemporaryFolder() val kotlinTestProc = KotlinTestProcessor() val javaTestProc = JavaTestProcessor() @@ -78,13 +81,13 @@ class KotlinCompilationTests { } @Test - fun `runs with SourceFile from path`() { - val sourceFile = temporaryFolder.newFile("KSource.kt").apply { + fun `runs with SourceFile from path`(@TempDir tempDir: Path) { + val sourceFile = tempDir.resolve("KSource.kt").createFile().apply { writeText("class KSource") } val result = defaultCompilerConfig().apply { - sources = listOf(SourceFile.fromPath(sourceFile)) + sources = listOf(SourceFile.fromPath(sourceFile.toFile())) }.compile() assertThat(result.exitCode).isEqualTo(ExitCode.OK) @@ -92,21 +95,21 @@ class KotlinCompilationTests { } @Test - fun `runs with SourceFile from paths with filename conflicts`() { - temporaryFolder.newFolder("a") - val sourceFileA = temporaryFolder.newFile("a/KSource.kt").apply { + fun `runs with SourceFile from paths with filename conflicts`(@TempDir tempDir: Path) { + tempDir.resolve("a").createDirectory() + val sourceFileA = tempDir.resolve("a/KSource.kt").createFile().apply { writeText("package a\n\nclass KSource") } - temporaryFolder.newFolder("b") - val sourceFileB = temporaryFolder.newFile("b/KSource.kt").apply { + tempDir.resolve("b").createDirectory() + val sourceFileB = tempDir.resolve("b/KSource.kt").createFile().apply { writeText("package b\n\nclass KSource") } val result = defaultCompilerConfig().apply { sources = listOf( - SourceFile.fromPath(sourceFileA), - SourceFile.fromPath(sourceFileB)) + SourceFile.fromPath(sourceFileA.toFile()), + SourceFile.fromPath(sourceFileB.toFile())) }.compile() assertThat(result.exitCode).isEqualTo(ExitCode.OK) @@ -867,20 +870,19 @@ class KotlinCompilationTests { ) } - @Ignore // Ignored because symlinks can't be created on Windows 7 without admin rights + @Disabled // Ignored because symlinks can't be created on Windows 7 without admin rights @Test - fun `java compilation runs in a sub-process when jdk is specified`() { + fun `java compilation runs in a sub-process when jdk is specified`(@TempDir tempDir: Path) { val source = SourceFile.java("JSource.java", """ class JSource {} """.trimIndent()) - val fakeJdkHome = temporaryFolder.newFolder("jdk-copy") - fakeJdkHome.mkdirs() - Files.createLink(fakeJdkHome.resolve("bin").toPath(), processJdkHome.toPath()) + val fakeJdkHome = tempDir.resolve("jdk-copy").createDirectory() + Files.createLink(fakeJdkHome.resolve("bin"), processJdkHome.toPath()) val logsStream = ByteArrayOutputStream() val compiler = defaultCompilerConfig().apply { sources = listOf(source) - jdkHome = fakeJdkHome + jdkHome = fakeJdkHome.toFile() messageOutputStream = logsStream } val result = compiler.compile() @@ -892,7 +894,6 @@ class KotlinCompilationTests { assertThat(logs).doesNotContain( "jdkHome is set to null, removing boot classpath from java compilation" ) - fakeJdkHome.delete() } @Test @@ -968,5 +969,28 @@ class KotlinCompilationTests { assertThat(result.exitCode).isEqualTo(ExitCode.OK) } + @Test + fun `javac arguments are passed to kapt`() { + val jSource = SourceFile.java( + "JSource.java", """ + package com.tschuchort.compiletesting; + + @ProcessElem + class JSource { + } + """ + ) + + val result = defaultCompilerConfig().apply { + sources = listOf(jSource) + annotationProcessors = listOf(kotlinTestProc) + inheritClassPath = true + javacArguments += listOf("-Xlint") + }.compile() + + assertThat(result.exitCode).isEqualTo(ExitCode.OK) + assertThat(result.messages).containsPattern(Pattern.compile("\\[kapt\\] All Javac options: \\{.*?-Xlint.*?\\}")) + } + class InheritedClass {} } diff --git a/core/src/test/kotlin/com/tschuchort/compiletesting/KotlinJsCompilationTests.kt b/core/src/test/kotlin/com/tschuchort/compiletesting/KotlinJsCompilationTests.kt index 6a659504..265e07b6 100644 --- a/core/src/test/kotlin/com/tschuchort/compiletesting/KotlinJsCompilationTests.kt +++ b/core/src/test/kotlin/com/tschuchort/compiletesting/KotlinJsCompilationTests.kt @@ -6,17 +6,19 @@ import org.assertj.core.api.Assertions.assertThat import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption import org.jetbrains.kotlin.compiler.plugin.CliOption import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor -import org.junit.Ignore -import org.junit.Rule -import org.junit.Test -import org.junit.rules.TemporaryFolder +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.io.TempDir import java.io.File import org.mockito.kotlin.* +import java.nio.file.Path +import kotlin.io.path.createDirectory +import kotlin.io.path.createFile +import kotlin.io.path.writeText -@Ignore("These JS tests don't currently work with the new compiler IR") +//@Disabled("These JS tests don't currently work with the new compiler IR") @Suppress("MemberVisibilityCanBePrivate") class KotlinJsCompilationTests { - @Rule @JvmField val temporaryFolder = TemporaryFolder() @Test fun `runs with only kotlin sources`() { @@ -40,13 +42,13 @@ class KotlinJsCompilationTests { } @Test - fun `runs with SourceFile from path`() { - val sourceFile = temporaryFolder.newFile("KSource.kt").apply { + fun `runs with SourceFile from path`(@TempDir tempDir: Path) { + val sourceFile = tempDir.resolve("KSource.kt").createFile().apply { writeText("class KSource") } val result = defaultJsCompilerConfig().apply { - sources = listOf(SourceFile.fromPath(sourceFile)) + sources = listOf(SourceFile.fromPath(sourceFile.toFile())) }.compile() assertThat(result.exitCode).isEqualTo(ExitCode.OK) @@ -56,21 +58,21 @@ class KotlinJsCompilationTests { } @Test - fun `runs with SourceFile from paths with filename conflicts`() { - temporaryFolder.newFolder("a") - val sourceFileA = temporaryFolder.newFile("a/KSource.kt").apply { + fun `runs with SourceFile from paths with filename conflicts`(@TempDir tempDir: Path) { + tempDir.resolve("a").createDirectory() + val sourceFileA = tempDir.resolve("a/KSource.kt").createFile().apply { writeText("package a\n\nclass KSource") } - temporaryFolder.newFolder("b") - val sourceFileB = temporaryFolder.newFile("b/KSource.kt").apply { + tempDir.resolve("b").createDirectory() + val sourceFileB = tempDir.resolve("b/KSource.kt").createFile().apply { writeText("package b\n\nclass KSource") } val result = defaultJsCompilerConfig().apply { sources = listOf( - SourceFile.fromPath(sourceFileA), - SourceFile.fromPath(sourceFileB)) + SourceFile.fromPath(sourceFileA.toFile()), + SourceFile.fromPath(sourceFileB.toFile())) }.compile() assertThat(result.exitCode).isEqualTo(ExitCode.OK) diff --git a/core/src/test/kotlin/com/tschuchort/compiletesting/StreamUtilTests.kt b/core/src/test/kotlin/com/tschuchort/compiletesting/StreamUtilTests.kt index 3bb28cec..67e9f209 100644 --- a/core/src/test/kotlin/com/tschuchort/compiletesting/StreamUtilTests.kt +++ b/core/src/test/kotlin/com/tschuchort/compiletesting/StreamUtilTests.kt @@ -2,7 +2,7 @@ package com.tschuchort.compiletesting import okio.Buffer import org.assertj.core.api.Assertions -import org.junit.Test +import org.junit.jupiter.api.Test import java.io.OutputStream import java.io.PrintStream import org.mockito.kotlin.mock diff --git a/gradle.properties b/gradle.properties index 25968c19..2bb1a1cc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,10 +1,10 @@ -#Sun, 05 Mar 2023 23:42:38 +0000 +#Sun, 26 May 2024 20:53:03 +0200 kotlin.code.style=official kotlin.incremental=false kapt.include.compile.classpath=false GROUP=com.github.tschuchortdev -VERSION_NAME=1.5.1-SNAPSHOT +VERSION_NAME=1.6.1-SNAPSHOT POM_DESCRIPTION=A library that enables testing of Kotlin annotation processors, compiler plugins and code generation. POM_INCEPTION_YEAR=2019 POM_URL=https\://github.com/tschuchortdev/kotlin-compile-testing diff --git a/ksp/src/test/kotlin/com/tschuchort/compiletesting/KspTest.kt b/ksp/src/test/kotlin/com/tschuchort/compiletesting/KspTest.kt index 18a3485c..6205832d 100644 --- a/ksp/src/test/kotlin/com/tschuchort/compiletesting/KspTest.kt +++ b/ksp/src/test/kotlin/com/tschuchort/compiletesting/KspTest.kt @@ -6,9 +6,7 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration import com.tschuchort.compiletesting.KotlinCompilation.ExitCode import org.assertj.core.api.Assertions.assertThat import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 +import org.junit.jupiter.api.Test import org.mockito.Mockito.`when` import java.util.concurrent.atomic.AtomicInteger import org.mockito.kotlin.any @@ -16,7 +14,6 @@ import org.mockito.kotlin.inOrder import org.mockito.kotlin.mock import kotlin.text.Typography.ellipsis -@RunWith(JUnit4::class) @ExperimentalCompilerApi class KspTest { @Test