Skip to content

Commit 9f829bf

Browse files
committed
Merge remote-tracking branch 'refs/remotes/dariuszkuc/junit5'
# Conflicts: # core/src/test/kotlin/com/tschuchort/compiletesting/CompilerPluginsTest.kt # core/src/test/kotlin/com/tschuchort/compiletesting/KotlinJsCompilationTests.kt
2 parents 2b149d9 + 0e11049 commit 9f829bf

File tree

7 files changed

+70
-68
lines changed

7 files changed

+70
-68
lines changed

build.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,14 @@ subprojects {
150150
sign publishing.publications.mavenJava
151151
}
152152

153+
test {
154+
useJUnitPlatform()
155+
}
156+
153157
dependencies {
154158
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
155159

156-
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
160+
testImplementation "org.junit.jupiter:junit-jupiter:5.9.3"
157161
testImplementation "org.mockito:mockito-core:4.7.0"
158162
testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0"
159163
testImplementation "org.assertj:assertj-core:3.24.2"

core/src/test/kotlin/com/tschuchort/compiletesting/CompilerPluginsTest.kt

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ package com.tschuchort.compiletesting
22

33
import org.assertj.core.api.Assertions
44
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
5-
import org.junit.Assert
6-
import org.junit.Ignore
7-
import org.junit.Test
5+
import org.junit.jupiter.api.Disabled
6+
import org.junit.jupiter.api.Test
87
import org.mockito.Mockito
98
import java.net.URL
109
import javax.annotation.processing.AbstractProcessor
@@ -55,7 +54,7 @@ class CompilerPluginsTest {
5554

5655
override fun process(p0: MutableSet<out TypeElement>?, p1: RoundEnvironment?): Boolean {
5756
p1?.getElementsAnnotatedWith(ProcessElem::class.java)?.forEach {
58-
Assert.assertEquals("JSource", it?.simpleName.toString())
57+
Assertions.assertThat("JSource").isEqualTo(it?.simpleName.toString())
5958
}
6059
return false
6160
}
@@ -88,7 +87,7 @@ class CompilerPluginsTest {
8887
Assertions.assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
8988
}
9089

91-
@Ignore("JS tests don't currently work with the new compiler IR")
90+
@Disabled("JS tests don't currently work with the new compiler IR")
9291
@Test
9392
fun `when JS compiler plugins are added they get executed`() {
9493
val mockLegacyPlugin = Mockito.mock(ComponentRegistrar::class.java)

core/src/test/kotlin/com/tschuchort/compiletesting/JavacUtilsTest.kt

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
package com.tschuchort.compiletesting
22

3-
import org.junit.Assert.*
4-
import org.junit.Test
3+
import org.junit.jupiter.api.Assertions
4+
import org.junit.jupiter.api.Test
55

66
class JavacUtilsTest {
77

88
@Test
99
fun `Old version scheme less than 9 is parsed correctly`() {
10-
assertFalse(isJavac9OrLater("1.8.0"))
10+
Assertions.assertFalse(isJavac9OrLater("1.8.0"))
1111
}
1212

1313
@Test
1414
fun `Old version scheme greater equal 9 is parsed correctly`() {
15-
assertTrue(isJavac9OrLater("1.9.1"))
16-
assertTrue(isJavac9OrLater("1.11.0"))
15+
Assertions.assertTrue(isJavac9OrLater("1.9.1"))
16+
Assertions.assertTrue(isJavac9OrLater("1.11.0"))
1717
}
1818

1919
@Test
2020
fun `New version scheme less than 9 is parsed correctly`() {
21-
assertFalse(isJavac9OrLater("8.1.0.1"))
22-
assertFalse(isJavac9OrLater("8.1.0"))
23-
assertFalse(isJavac9OrLater("8.1"))
24-
assertFalse(isJavac9OrLater("8"))
21+
Assertions.assertFalse(isJavac9OrLater("8.1.0.1"))
22+
Assertions.assertFalse(isJavac9OrLater("8.1.0"))
23+
Assertions.assertFalse(isJavac9OrLater("8.1"))
24+
Assertions.assertFalse(isJavac9OrLater("8"))
2525
}
2626

2727
@Test
2828
fun `New version scheme greater equal 9 is parsed correctly`() {
29-
assertTrue(isJavac9OrLater("9.0.0.1"))
30-
assertTrue(isJavac9OrLater("9.0.0"))
31-
assertTrue(isJavac9OrLater("9.1.0"))
32-
assertTrue(isJavac9OrLater("9.1"))
33-
assertTrue(isJavac9OrLater("9"))
34-
assertTrue(isJavac9OrLater("12"))
29+
Assertions.assertTrue(isJavac9OrLater("9.0.0.1"))
30+
Assertions.assertTrue(isJavac9OrLater("9.0.0"))
31+
Assertions.assertTrue(isJavac9OrLater("9.1.0"))
32+
Assertions.assertTrue(isJavac9OrLater("9.1"))
33+
Assertions.assertTrue(isJavac9OrLater("9"))
34+
Assertions.assertTrue(isJavac9OrLater("12"))
3535
}
3636

3737
@Test
3838
fun `Old version scheme with extra info is parsed correctly`() {
39-
assertTrue(isJavac9OrLater("1.11.0-bla"))
39+
Assertions.assertTrue(isJavac9OrLater("1.11.0-bla"))
4040
}
4141

4242
@Test
4343
fun `Standard javac -version output is parsed correctly`() {
44-
assertEquals("1.8.0_252", parseVersionString("javac 1.8.0_252"))
44+
Assertions.assertEquals("1.8.0_252", parseVersionString("javac 1.8.0_252"))
4545
}
4646

4747
@Test
4848
fun `javac -version output with JAVA OPTIONS is parsed correctly`() {
49-
assertEquals(
49+
Assertions.assertEquals(
5050
"1.8.0_222",
5151
parseVersionString(
5252
"Picked up _JAVA_OPTIONS: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap javac 1.8.0_222"
@@ -56,7 +56,7 @@ class JavacUtilsTest {
5656

5757
@Test
5858
fun `Wrong javac -version output is returning null`() {
59-
assertNull(
59+
Assertions.assertNull(
6060
parseVersionString(
6161
"wrong javac"
6262
)

core/src/test/kotlin/com/tschuchort/compiletesting/KotlinCompilationTests.kt

+22-22
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ import org.assertj.core.api.Assertions.assertThat
66
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
77
import org.jetbrains.kotlin.compiler.plugin.CliOption
88
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
9-
import org.junit.Ignore
10-
import org.junit.Rule
11-
import org.junit.Test
12-
import org.junit.rules.TemporaryFolder
9+
import org.junit.jupiter.api.Disabled
10+
import org.junit.jupiter.api.Test
11+
import org.junit.jupiter.api.io.TempDir
1312
import java.io.ByteArrayOutputStream
1413
import java.io.File
1514
import java.nio.file.Files
1615
import javax.annotation.processing.AbstractProcessor
1716
import javax.annotation.processing.RoundEnvironment
1817
import javax.lang.model.element.TypeElement
1918
import org.mockito.kotlin.*
19+
import java.nio.file.Path
20+
import kotlin.io.path.createDirectory
21+
import kotlin.io.path.createFile
22+
import kotlin.io.path.writeText
2023

2124
@Suppress("MemberVisibilityCanBePrivate", "RemoveEmptyClassBody", "RedundantSemicolon", "RemoveEmptyPrimaryConstructor")
2225
class KotlinCompilationTests {
23-
@Rule @JvmField val temporaryFolder = TemporaryFolder()
2426

2527
val kotlinTestProc = KotlinTestProcessor()
2628
val javaTestProc = JavaTestProcessor()
@@ -78,35 +80,35 @@ class KotlinCompilationTests {
7880
}
7981

8082
@Test
81-
fun `runs with SourceFile from path`() {
82-
val sourceFile = temporaryFolder.newFile("KSource.kt").apply {
83+
fun `runs with SourceFile from path`(@TempDir tempDir: Path) {
84+
val sourceFile = tempDir.resolve("KSource.kt").createFile().apply {
8385
writeText("class KSource")
8486
}
8587

8688
val result = defaultCompilerConfig().apply {
87-
sources = listOf(SourceFile.fromPath(sourceFile))
89+
sources = listOf(SourceFile.fromPath(sourceFile.toFile()))
8890
}.compile()
8991

9092
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
9193
assertClassLoadable(result, "KSource")
9294
}
9395

9496
@Test
95-
fun `runs with SourceFile from paths with filename conflicts`() {
96-
temporaryFolder.newFolder("a")
97-
val sourceFileA = temporaryFolder.newFile("a/KSource.kt").apply {
97+
fun `runs with SourceFile from paths with filename conflicts`(@TempDir tempDir: Path) {
98+
tempDir.resolve("a").createDirectory()
99+
val sourceFileA = tempDir.resolve("a/KSource.kt").createFile().apply {
98100
writeText("package a\n\nclass KSource")
99101
}
100102

101-
temporaryFolder.newFolder("b")
102-
val sourceFileB = temporaryFolder.newFile("b/KSource.kt").apply {
103+
tempDir.resolve("b").createDirectory()
104+
val sourceFileB = tempDir.resolve("b/KSource.kt").createFile().apply {
103105
writeText("package b\n\nclass KSource")
104106
}
105107

106108
val result = defaultCompilerConfig().apply {
107109
sources = listOf(
108-
SourceFile.fromPath(sourceFileA),
109-
SourceFile.fromPath(sourceFileB))
110+
SourceFile.fromPath(sourceFileA.toFile()),
111+
SourceFile.fromPath(sourceFileB.toFile()))
110112
}.compile()
111113

112114
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
@@ -867,20 +869,19 @@ class KotlinCompilationTests {
867869
)
868870
}
869871

870-
@Ignore // Ignored because symlinks can't be created on Windows 7 without admin rights
872+
@Disabled // Ignored because symlinks can't be created on Windows 7 without admin rights
871873
@Test
872-
fun `java compilation runs in a sub-process when jdk is specified`() {
874+
fun `java compilation runs in a sub-process when jdk is specified`(@TempDir tempDir: Path) {
873875
val source = SourceFile.java("JSource.java",
874876
"""
875877
class JSource {}
876878
""".trimIndent())
877-
val fakeJdkHome = temporaryFolder.newFolder("jdk-copy")
878-
fakeJdkHome.mkdirs()
879-
Files.createLink(fakeJdkHome.resolve("bin").toPath(), processJdkHome.toPath())
879+
val fakeJdkHome = tempDir.resolve("jdk-copy").createDirectory()
880+
Files.createLink(fakeJdkHome.resolve("bin"), processJdkHome.toPath())
880881
val logsStream = ByteArrayOutputStream()
881882
val compiler = defaultCompilerConfig().apply {
882883
sources = listOf(source)
883-
jdkHome = fakeJdkHome
884+
jdkHome = fakeJdkHome.toFile()
884885
messageOutputStream = logsStream
885886
}
886887
val result = compiler.compile()
@@ -892,7 +893,6 @@ class KotlinCompilationTests {
892893
assertThat(logs).doesNotContain(
893894
"jdkHome is set to null, removing boot classpath from java compilation"
894895
)
895-
fakeJdkHome.delete()
896896
}
897897

898898
@Test

core/src/test/kotlin/com/tschuchort/compiletesting/KotlinJsCompilationTests.kt

+18-16
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ import org.assertj.core.api.Assertions.assertThat
66
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
77
import org.jetbrains.kotlin.compiler.plugin.CliOption
88
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
9-
import org.junit.Ignore
10-
import org.junit.Rule
11-
import org.junit.Test
12-
import org.junit.rules.TemporaryFolder
9+
import org.junit.jupiter.api.Disabled
10+
import org.junit.jupiter.api.Test
11+
import org.junit.jupiter.api.io.TempDir
1312
import java.io.File
1413
import org.mockito.kotlin.*
14+
import java.nio.file.Path
15+
import kotlin.io.path.createDirectory
16+
import kotlin.io.path.createFile
17+
import kotlin.io.path.writeText
1518

16-
@Ignore("These JS tests don't currently work with the new compiler IR")
19+
@Disabled("These JS tests don't currently work with the new compiler IR")
1720
@Suppress("MemberVisibilityCanBePrivate")
1821
class KotlinJsCompilationTests {
19-
@Rule @JvmField val temporaryFolder = TemporaryFolder()
2022

2123
@Test
2224
fun `runs with only kotlin sources`() {
@@ -40,13 +42,13 @@ class KotlinJsCompilationTests {
4042
}
4143

4244
@Test
43-
fun `runs with SourceFile from path`() {
44-
val sourceFile = temporaryFolder.newFile("KSource.kt").apply {
45+
fun `runs with SourceFile from path`(@TempDir tempDir: Path) {
46+
val sourceFile = tempDir.resolve("KSource.kt").createFile().apply {
4547
writeText("class KSource")
4648
}
4749

4850
val result = defaultJsCompilerConfig().apply {
49-
sources = listOf(SourceFile.fromPath(sourceFile))
51+
sources = listOf(SourceFile.fromPath(sourceFile.toFile()))
5052
}.compile()
5153

5254
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
@@ -56,21 +58,21 @@ class KotlinJsCompilationTests {
5658
}
5759

5860
@Test
59-
fun `runs with SourceFile from paths with filename conflicts`() {
60-
temporaryFolder.newFolder("a")
61-
val sourceFileA = temporaryFolder.newFile("a/KSource.kt").apply {
61+
fun `runs with SourceFile from paths with filename conflicts`(@TempDir tempDir: Path) {
62+
tempDir.resolve("a").createDirectory()
63+
val sourceFileA = tempDir.resolve("a/KSource.kt").createFile().apply {
6264
writeText("package a\n\nclass KSource")
6365
}
6466

65-
temporaryFolder.newFolder("b")
66-
val sourceFileB = temporaryFolder.newFile("b/KSource.kt").apply {
67+
tempDir.resolve("b").createDirectory()
68+
val sourceFileB = tempDir.resolve("b/KSource.kt").createFile().apply {
6769
writeText("package b\n\nclass KSource")
6870
}
6971

7072
val result = defaultJsCompilerConfig().apply {
7173
sources = listOf(
72-
SourceFile.fromPath(sourceFileA),
73-
SourceFile.fromPath(sourceFileB))
74+
SourceFile.fromPath(sourceFileA.toFile()),
75+
SourceFile.fromPath(sourceFileB.toFile()))
7476
}.compile()
7577

7678
assertThat(result.exitCode).isEqualTo(ExitCode.OK)

core/src/test/kotlin/com/tschuchort/compiletesting/StreamUtilTests.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.tschuchort.compiletesting
22

33
import okio.Buffer
44
import org.assertj.core.api.Assertions
5-
import org.junit.Test
5+
import org.junit.jupiter.api.Test
66
import java.io.OutputStream
77
import java.io.PrintStream
88
import org.mockito.kotlin.mock

ksp/src/test/kotlin/com/tschuchort/compiletesting/KspTest.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration
66
import com.tschuchort.compiletesting.KotlinCompilation.ExitCode
77
import org.assertj.core.api.Assertions.assertThat
88
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
9-
import org.junit.Test
10-
import org.junit.runner.RunWith
11-
import org.junit.runners.JUnit4
9+
import org.junit.jupiter.api.Test
1210
import org.mockito.Mockito.`when`
1311
import java.util.concurrent.atomic.AtomicInteger
1412
import org.mockito.kotlin.any
1513
import org.mockito.kotlin.inOrder
1614
import org.mockito.kotlin.mock
1715
import kotlin.text.Typography.ellipsis
1816

19-
@RunWith(JUnit4::class)
2017
@ExperimentalCompilerApi
2118
class KspTest {
2219
@Test

0 commit comments

Comments
 (0)