Skip to content

Commit

Permalink
Load dependencies from annotations on classpath initialization in tes…
Browse files Browse the repository at this point in the history
…t-kit tests
  • Loading branch information
ileasile committed Oct 9, 2024
1 parent d0e8929 commit 0819a28
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gradleCompatibleKotlinLanguageLevel=1.8

kotlin.jupyter.add.api=false
kotlin.jupyter.add.scanner=false
kotlin.jupyter.add.testkit=false

artifactsPath=build/artifacts

Expand Down
28 changes: 28 additions & 0 deletions jupyter-lib/test-kit-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
kotlin("libs.publisher")
kotlin("jvm")
kotlin("plugin.serialization")
kotlin("jupyter.api")
}

repositories {
mavenCentral()
}

dependencies {
testImplementation(projects.testKit)
testImplementation(libs.test.kotlintest.assertions)
}

val rootShadowJar = ':' + build.SHADOW_JAR_TASK

buildSettings {
withLanguageLevel(rootSettings.kotlinLanguageLevel)
withTests {
mustRunAfter(rootShadowJar)
}
}

tasks.processJupyterApiResources {
libraryProducers = listOf("org.jetbrains.kotlinx.jupyter.testkit.test.integrations.DatetimeTestIntegration")
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ class JupyterReplWithResolverTest : JupyterReplTestCase(
exception.shouldBeTypeOf<ReplCompilerException>()
exception.message shouldContain "Unresolved reference: multik"
}

@Test
fun `datetime is loaded and present`() {
execRendered("Clock.System.now()")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.jetbrains.kotlinx.jupyter.testkit.test.integrations

import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
import org.jetbrains.kotlinx.jupyter.api.libraries.dependencies

@Suppress("unused")
class DatetimeTestIntegration : JupyterIntegration() {
override fun Builder.onLoaded() {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-datetime-jvm:0.6.1")
}
import("kotlinx.datetime.Clock")
}
}
3 changes: 0 additions & 3 deletions jupyter-lib/test-kit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ val rootShadowJar = ':' + build.SHADOW_JAR_TASK

buildSettings {
withLanguageLevel(rootSettings.kotlinLanguageLevel)
withTests {
mustRunAfter(rootShadowJar)
}
}

tasks.dokkaHtmlPartial {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ libSubproject("shared-compiler")
libSubproject("spring-starter")
libSubproject("lib-ext")
libSubproject("test-kit")
libSubproject("test-kit-test")

exampleSubproject("getting-started")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ class ReplForJupyterImpl(

private fun <T> withEvalContext(action: () -> T): T {
return synchronized(this) {
require(!evalContextEnabled) { "Recursive execution is not supported" }
evalContextEnabled = true
try {
action()
Expand Down Expand Up @@ -589,7 +590,7 @@ class ReplForJupyterImpl(
}

override fun <T> eval(execution: ExecutionCallback<T>): T {
return synchronized(this) {
return withEvalContext {
executor.execute(execution)
}
}
Expand Down

0 comments on commit 0819a28

Please sign in to comment.