aboutsummaryrefslogtreecommitdiffstats
path: root/integration-testing/build.gradle
blob: 6efa3a14e6fd5dedf78461680f429c19b3938f81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

plugins {
    id("kotlin-jvm-conventions")
}

repositories {
    mavenLocal()
    mavenCentral()
}

sourceSets {
    npmTest {
        kotlin
        compileClasspath += sourceSets.test.runtimeClasspath
        runtimeClasspath += sourceSets.test.runtimeClasspath
    }
    mavenTest {
        kotlin
        compileClasspath += sourceSets.test.runtimeClasspath
        runtimeClasspath += sourceSets.test.runtimeClasspath
    }
    debugAgentTest {
        kotlin
        compileClasspath += sourceSets.test.runtimeClasspath
        runtimeClasspath += sourceSets.test.runtimeClasspath
    }

    coreAgentTest {
        kotlin
        compileClasspath += sourceSets.test.runtimeClasspath
        runtimeClasspath += sourceSets.test.runtimeClasspath
    }
}

compileDebugAgentTestKotlin {
    kotlinOptions {
        freeCompilerArgs += ["-Xallow-kotlin-package"]
    }
}

task npmTest(type: Test) {
    def sourceSet = sourceSets.npmTest
    environment "projectRoot", project.rootDir
    environment "deployVersion", version
    def dryRunNpm = project.properties['dryRun']
    def doRun = dryRunNpm == "true" // so that we don't accidentally publish anything, especially before the test
    onlyIf { doRun }
    if (doRun) { // `onlyIf` only affects execution of the task, not the dependency subtree
        dependsOn(project(':').getTasksByName("publishNpm", true))
    }
    testClassesDirs = sourceSet.output.classesDirs
    classpath = sourceSet.runtimeClasspath
}

task mavenTest(type: Test) {
    def sourceSet = sourceSets.mavenTest
    dependsOn(project(':').getTasksByName("publishToMavenLocal", true))
    testClassesDirs = sourceSet.output.classesDirs
    classpath = sourceSet.runtimeClasspath
    // we can't depend on the subprojects because we need to test the classfiles that are published in the end.
    // also, we can't put this in the `dependencies` block because the resolution would happen before publication.
    def mavenTestClasspathConfiguration = project.configurations.detachedConfiguration(
            project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"),
            project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"))

    mavenTestClasspathConfiguration.attributes {
        attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
    }

    classpath += mavenTestClasspathConfiguration
}

task debugAgentTest(type: Test) {
    def sourceSet = sourceSets.debugAgentTest
    dependsOn(project(':kotlinx-coroutines-debug').shadowJar)
    jvmArgs ('-javaagent:' + project(':kotlinx-coroutines-debug').shadowJar.outputs.files.getFiles()[0])
    testClassesDirs = sourceSet.output.classesDirs
    classpath = sourceSet.runtimeClasspath
}

task coreAgentTest(type: Test) {
    def sourceSet = sourceSets.coreAgentTest
    dependsOn(project(':kotlinx-coroutines-core').jvmJar)
    jvmArgs ('-javaagent:' + project(':kotlinx-coroutines-core').jvmJar.outputs.files.getFiles()[0])
    testClassesDirs = sourceSet.output.classesDirs
    classpath = sourceSet.runtimeClasspath
}

dependencies {
    testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    testImplementation 'junit:junit:4.12'
    npmTestImplementation 'org.apache.commons:commons-compress:1.18'
    npmTestImplementation 'com.google.code.gson:gson:2.8.5'
    debugAgentTestCompile project(':kotlinx-coroutines-core')
    debugAgentTestCompile project(':kotlinx-coroutines-debug')
    coreAgentTestCompile project(':kotlinx-coroutines-core')
}

compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

check {
    dependsOn([npmTest, mavenTest, debugAgentTest, coreAgentTest])
}