Skip to content

Commit b30645c

Browse files
committed
KTNB-1129: Review fixes
1 parent 3be7037 commit b30645c

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

src/test/kotlin/org/jetbrains/kotlinx/jupyter/test/TestUtil.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,15 @@ fun Any?.shouldBeInstanceOf(kclass: KClass<*>) {
468468
}
469469
}
470470

471-
interface TempDirProvider {
471+
/**
472+
* A factory interface for creating temporary files and directories on the filesystem.
473+
*/
474+
interface TempFilesFactory {
475+
/**
476+
* Creates a new empty temporary directory.
477+
* Clients shouldn't care about the directory cleanup,
478+
* it's the responsibility of the exact implementation.
479+
*/
472480
fun newTempDir(): Path
473481
}
474482

@@ -480,13 +488,13 @@ interface TempDirProvider {
480488
@OptIn(ExperimentalPathApi::class)
481489
fun withTempDirectories(
482490
dirPrefix: String,
483-
action: TempDirProvider.() -> Unit,
491+
action: TempFilesFactory.() -> Unit,
484492
) {
485493
val directories: MutableList<Path> = mutableListOf()
486494

487495
try {
488496
val provider =
489-
object : TempDirProvider {
497+
object : TempFilesFactory {
490498
override fun newTempDir(): Path =
491499
createTempDirectory(dirPrefix).also {
492500
it.toFile().deleteOnExit()

src/test/kotlin/org/jetbrains/kotlinx/jupyter/test/repl/ReplTests.kt

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import org.jetbrains.kotlinx.jupyter.test.renderedValue
4343
import org.jetbrains.kotlinx.jupyter.test.withTempDirectories
4444
import org.jetbrains.kotlinx.jupyter.util.DelegatingClassLoader
4545
import org.jetbrains.kotlinx.jupyter.withPath
46-
import org.junit.jupiter.api.Assumptions.assumeTrue
4746
import org.junit.jupiter.api.Disabled
4847
import org.junit.jupiter.api.Test
4948
import org.junit.jupiter.api.condition.DisabledOnOs
@@ -1080,8 +1079,6 @@ class ReplTests : AbstractSingleReplTest() {
10801079
)
10811080

10821081
// Doesn't work in K2, see KT-80019
1083-
assumeTrue(repl.compilerMode == K1)
1084-
10851082
val res =
10861083
eval(
10871084
"""
@@ -1090,23 +1087,39 @@ class ReplTests : AbstractSingleReplTest() {
10901087
""".trimIndent(),
10911088
)
10921089

1093-
evalSuccess("great()").renderedValue shouldBe "Great result!"
1094-
1095-
withTempDirectories("customPackages") {
1096-
val scriptsDir = newTempDir()
1097-
val sourcesDir = newTempDir()
1090+
eval("great()").let { invocationResult ->
1091+
when (repl.compilerMode) {
1092+
K1 -> invocationResult.renderedValue shouldBe "Great result!"
1093+
K2 -> invocationResult.shouldBeInstanceOf<EvalResultEx.Error>()
1094+
}
1095+
}
10981096

1099-
val classNames =
1100-
CompiledScriptsSerializer().deserializeAndSave(
1101-
res.metadata.compiledData,
1102-
scriptsDir,
1103-
sourcesDir,
1104-
)
1097+
when (repl.compilerMode) {
1098+
K1 -> {
1099+
withTempDirectories("customPackages") {
1100+
val scriptsDir = newTempDir()
1101+
val sourcesDir = newTempDir()
1102+
1103+
val classNames =
1104+
CompiledScriptsSerializer().deserializeAndSave(
1105+
res.metadata.compiledData,
1106+
scriptsDir,
1107+
sourcesDir,
1108+
)
11051109

1106-
scriptsDir.resolve("com/xxx/pack/Line_1_jupyter.class").shouldExist()
1107-
sourcesDir.shouldContainFile("Line_1.kts")
1110+
scriptsDir.resolve("com/xxx/pack/Line_1_jupyter.class").shouldExist()
1111+
sourcesDir.shouldContainFile("Line_1.kts")
11081112

1109-
classNames shouldBe listOf("com.xxx.pack.Line_1_jupyter")
1113+
classNames shouldBe listOf("com.xxx.pack.Line_1_jupyter")
1114+
}
1115+
}
1116+
K2 -> {
1117+
res.shouldBeInstanceOf<EvalResultEx.Error>()
1118+
with(res.metadata.compiledData) {
1119+
scripts.shouldBeEmpty()
1120+
sources.shouldBeEmpty()
1121+
}
1122+
}
11101123
}
11111124
}
11121125
}

0 commit comments

Comments
 (0)