Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 1 | import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType |
| 2 | |
dkhalanskyjb | 02b403d | 2020-04-06 16:33:22 +0300 | [diff] [blame] | 3 | /* |
| 4 | * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 5 | */ |
| 6 | |
| 7 | apply from: rootProject.file("gradle/compile-jvm.gradle") |
| 8 | |
| 9 | repositories { |
| 10 | mavenLocal() |
| 11 | mavenCentral() |
| 12 | } |
| 13 | |
| 14 | sourceSets { |
| 15 | npmTest { |
| 16 | kotlin |
| 17 | compileClasspath += sourceSets.test.runtimeClasspath |
| 18 | runtimeClasspath += sourceSets.test.runtimeClasspath |
| 19 | } |
| 20 | mavenTest { |
| 21 | kotlin |
| 22 | compileClasspath += sourceSets.test.runtimeClasspath |
| 23 | runtimeClasspath += sourceSets.test.runtimeClasspath |
| 24 | } |
| 25 | debugAgentTest { |
| 26 | kotlin |
| 27 | compileClasspath += sourceSets.test.runtimeClasspath |
| 28 | runtimeClasspath += sourceSets.test.runtimeClasspath |
| 29 | } |
Vsevolod Tolstopyatov | 70a7487 | 2020-04-24 14:59:28 +0300 | [diff] [blame] | 30 | |
| 31 | coreAgentTest { |
| 32 | kotlin |
| 33 | compileClasspath += sourceSets.test.runtimeClasspath |
| 34 | runtimeClasspath += sourceSets.test.runtimeClasspath |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | compileDebugAgentTestKotlin { |
| 39 | kotlinOptions { |
| 40 | freeCompilerArgs += ["-Xallow-kotlin-package"] |
| 41 | } |
dkhalanskyjb | 02b403d | 2020-04-06 16:33:22 +0300 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | task npmTest(type: Test) { |
| 45 | def sourceSet = sourceSets.npmTest |
| 46 | environment "projectRoot", project.rootDir |
| 47 | environment "deployVersion", version |
| 48 | def dryRunNpm = project.properties['dryRun'] |
| 49 | def doRun = dryRunNpm == "true" // so that we don't accidentally publish anything, especially before the test |
| 50 | onlyIf { doRun } |
| 51 | if (doRun) { // `onlyIf` only affects execution of the task, not the dependency subtree |
| 52 | dependsOn(project(':').getTasksByName("publishNpm", true)) |
| 53 | } |
| 54 | testClassesDirs = sourceSet.output.classesDirs |
| 55 | classpath = sourceSet.runtimeClasspath |
| 56 | } |
| 57 | |
| 58 | task mavenTest(type: Test) { |
| 59 | def sourceSet = sourceSets.mavenTest |
| 60 | dependsOn(project(':').getTasksByName("publishToMavenLocal", true)) |
dkhalanskyjb | 02b403d | 2020-04-06 16:33:22 +0300 | [diff] [blame] | 61 | testClassesDirs = sourceSet.output.classesDirs |
| 62 | classpath = sourceSet.runtimeClasspath |
| 63 | // we can't depend on the subprojects because we need to test the classfiles that are published in the end. |
| 64 | // also, we can't put this in the `dependencies` block because the resolution would happen before publication. |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 65 | def mavenTestClasspathConfiguration = project.configurations.detachedConfiguration( |
dkhalanskyjb | 02b403d | 2020-04-06 16:33:22 +0300 | [diff] [blame] | 66 | project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"), |
| 67 | project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-android:$version")) |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 68 | |
| 69 | mavenTestClasspathConfiguration.attributes { |
| 70 | attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm) |
| 71 | } |
| 72 | |
| 73 | classpath += mavenTestClasspathConfiguration |
dkhalanskyjb | 02b403d | 2020-04-06 16:33:22 +0300 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | task debugAgentTest(type: Test) { |
| 77 | def sourceSet = sourceSets.debugAgentTest |
| 78 | dependsOn(project(':kotlinx-coroutines-debug').shadowJar) |
| 79 | jvmArgs ('-javaagent:' + project(':kotlinx-coroutines-debug').shadowJar.outputs.files.getFiles()[0]) |
| 80 | testClassesDirs = sourceSet.output.classesDirs |
| 81 | classpath = sourceSet.runtimeClasspath |
| 82 | } |
| 83 | |
Vsevolod Tolstopyatov | 70a7487 | 2020-04-24 14:59:28 +0300 | [diff] [blame] | 84 | task coreAgentTest(type: Test) { |
| 85 | def sourceSet = sourceSets.coreAgentTest |
| 86 | dependsOn(project(':kotlinx-coroutines-core').jvmJar) |
| 87 | jvmArgs ('-javaagent:' + project(':kotlinx-coroutines-core').jvmJar.outputs.files.getFiles()[0]) |
| 88 | testClassesDirs = sourceSet.output.classesDirs |
| 89 | classpath = sourceSet.runtimeClasspath |
| 90 | } |
| 91 | |
dkhalanskyjb | 02b403d | 2020-04-06 16:33:22 +0300 | [diff] [blame] | 92 | dependencies { |
| 93 | testCompile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" |
| 94 | testCompile 'junit:junit:4.12' |
| 95 | npmTestCompile 'org.apache.commons:commons-compress:1.18' |
| 96 | npmTestCompile 'com.google.code.gson:gson:2.8.5' |
| 97 | debugAgentTestCompile project(':kotlinx-coroutines-core') |
| 98 | debugAgentTestCompile project(':kotlinx-coroutines-debug') |
Vsevolod Tolstopyatov | 70a7487 | 2020-04-24 14:59:28 +0300 | [diff] [blame] | 99 | coreAgentTestCompile project(':kotlinx-coroutines-core') |
dkhalanskyjb | 02b403d | 2020-04-06 16:33:22 +0300 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | compileTestKotlin { |
| 103 | kotlinOptions.jvmTarget = "1.8" |
| 104 | } |
| 105 | |
Vsevolod Tolstopyatov | 70a7487 | 2020-04-24 14:59:28 +0300 | [diff] [blame] | 106 | check { |
| 107 | dependsOn([npmTest, mavenTest, debugAgentTest, coreAgentTest]) |
dkhalanskyjb | 02b403d | 2020-04-06 16:33:22 +0300 | [diff] [blame] | 108 | } |