@@ -6,21 +6,23 @@ import org.assertj.core.api.Assertions.assertThat
6
6
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
7
7
import org.jetbrains.kotlin.compiler.plugin.CliOption
8
8
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
13
12
import java.io.ByteArrayOutputStream
14
13
import java.io.File
15
14
import java.nio.file.Files
16
15
import javax.annotation.processing.AbstractProcessor
17
16
import javax.annotation.processing.RoundEnvironment
18
17
import javax.lang.model.element.TypeElement
19
18
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
20
23
21
24
@Suppress(" MemberVisibilityCanBePrivate" , " RemoveEmptyClassBody" , " RedundantSemicolon" , " RemoveEmptyPrimaryConstructor" )
22
25
class KotlinCompilationTests {
23
- @Rule @JvmField val temporaryFolder = TemporaryFolder ()
24
26
25
27
val kotlinTestProc = KotlinTestProcessor ()
26
28
val javaTestProc = JavaTestProcessor ()
@@ -78,35 +80,35 @@ class KotlinCompilationTests {
78
80
}
79
81
80
82
@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 {
83
85
writeText(" class KSource" )
84
86
}
85
87
86
88
val result = defaultCompilerConfig().apply {
87
- sources = listOf (SourceFile .fromPath(sourceFile))
89
+ sources = listOf (SourceFile .fromPath(sourceFile.toFile() ))
88
90
}.compile()
89
91
90
92
assertThat(result.exitCode).isEqualTo(ExitCode .OK )
91
93
assertClassLoadable(result, " KSource" )
92
94
}
93
95
94
96
@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 {
98
100
writeText(" package a\n\n class KSource" )
99
101
}
100
102
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 {
103
105
writeText(" package b\n\n class KSource" )
104
106
}
105
107
106
108
val result = defaultCompilerConfig().apply {
107
109
sources = listOf (
108
- SourceFile .fromPath(sourceFileA),
109
- SourceFile .fromPath(sourceFileB))
110
+ SourceFile .fromPath(sourceFileA.toFile() ),
111
+ SourceFile .fromPath(sourceFileB.toFile() ))
110
112
}.compile()
111
113
112
114
assertThat(result.exitCode).isEqualTo(ExitCode .OK )
@@ -867,20 +869,19 @@ class KotlinCompilationTests {
867
869
)
868
870
}
869
871
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
871
873
@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 ) {
873
875
val source = SourceFile .java(" JSource.java" ,
874
876
"""
875
877
class JSource {}
876
878
""" .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())
880
881
val logsStream = ByteArrayOutputStream ()
881
882
val compiler = defaultCompilerConfig().apply {
882
883
sources = listOf (source)
883
- jdkHome = fakeJdkHome
884
+ jdkHome = fakeJdkHome.toFile()
884
885
messageOutputStream = logsStream
885
886
}
886
887
val result = compiler.compile()
@@ -892,7 +893,6 @@ class KotlinCompilationTests {
892
893
assertThat(logs).doesNotContain(
893
894
" jdkHome is set to null, removing boot classpath from java compilation"
894
895
)
895
- fakeJdkHome.delete()
896
896
}
897
897
898
898
@Test
0 commit comments