TestRunner support in test's build.gradle
* Fixes to tests * RunKonanTest runs tests build with TestRunner * Standalone tests
This commit is contained in:
@@ -2213,7 +2213,7 @@ task interop_echo_server(type: RunInteropKonanTest) {
|
||||
}
|
||||
|
||||
if (isMac()) {
|
||||
task interop_opengl_teapot(type: RunKonanTest) {
|
||||
task interop_opengl_teapot(type: RunStandaloneKonanTest) {
|
||||
disabled = (project.testTarget == 'wasm32') // No interop for wasm yet.
|
||||
run = false
|
||||
source = "interop/basics/opengl_teapot.kt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package codegen.basics
|
||||
package codegen.basics.check_type
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package codegen.bridges.linkTest.a
|
||||
package a
|
||||
|
||||
interface A<T> {
|
||||
fun foo(): T
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package codegen.bridges.linkTest_main
|
||||
|
||||
import kotlin.test.*
|
||||
import codegen.bridges.linkTest.a.*
|
||||
import a.*
|
||||
|
||||
class B: C()
|
||||
|
||||
@Test fun runTest() {
|
||||
fun main(args: Array<String>) {
|
||||
val b = B()
|
||||
println(b.foo())
|
||||
val c: C = b
|
||||
|
||||
@@ -18,7 +18,7 @@ open class B: A<Int>() {
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
@Test fun runTest() {
|
||||
val b = B()
|
||||
val a = A<Int>()
|
||||
b.bar(42)
|
||||
|
||||
@@ -10,6 +10,6 @@ fun cycle_for(arr: Array<Int>) : Int {
|
||||
return sum
|
||||
}
|
||||
|
||||
@Test fun main() {
|
||||
@Test fun runTest() {
|
||||
if (cycle_for(Array(4, init = { it })) != 6) throw Error()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package codegen.delegatedProperty.delegatedOverride.a
|
||||
package a
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
package codegen.delegatedProperty.delegatedOverride_main
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import codegen.delegatedProperty.delegatedOverride.a.*
|
||||
import a.*
|
||||
|
||||
open class C: B() {
|
||||
override val x: Int = 156
|
||||
@@ -15,7 +11,7 @@ open class C: B() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun main(args: Array<String>) {
|
||||
val c = C()
|
||||
c.foo()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package codegen.enum.linkTest.a
|
||||
package a
|
||||
|
||||
enum class A(val x: Int) {
|
||||
Z1(42),
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package codegen.enum.linkTest_main
|
||||
import a.*
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import codegen.enum.linkTest.a.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun main(args: Array<String>) {
|
||||
println(A.Z1.x)
|
||||
println(A.valueOf("Z2").x)
|
||||
println(A.values()[2].x)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package codegen.inline.defaultArgs_linkTest.a
|
||||
package a
|
||||
|
||||
inline fun foo(x: Int, y: Int = 117) = x + y
|
||||
@@ -1,10 +1,6 @@
|
||||
package codegen.inline.defaultArgs_linkTest_main
|
||||
import a.*
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import codegen.inline.defaultArgs_linkTest.a.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun main(args: Array<String>) {
|
||||
println(foo(5))
|
||||
println(foo(5, 42))
|
||||
}
|
||||
@@ -45,6 +45,6 @@ class A: ABase() { // implicit label @A
|
||||
|
||||
fun box() = A().B().bar(D())
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
|
||||
@@ -19,6 +19,6 @@ class Outer(val x: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
@Test fun runTest() {
|
||||
Outer(42).Inner().InnerInner("zzz")
|
||||
}
|
||||
|
||||
@@ -12,6 +12,6 @@ open class Outer(val outer: String) {
|
||||
|
||||
fun box() = Outer("Fail").value()
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package codegen.kclass.kclass0
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Test fun runTest() {
|
||||
main(emptyArray())
|
||||
main(emptyArray<String>())
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package codegen.propertyCallableReference.linkTest.a
|
||||
package a
|
||||
|
||||
class A(val x: Int)
|
||||
@@ -1,10 +1,6 @@
|
||||
package codegen.propertyCallableReference.linkTest_main
|
||||
import a.A
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import codegen.propertyCallableReference.linkTest.a.A
|
||||
|
||||
@Test fun runTest() {
|
||||
fun main(args: Array<String>) {
|
||||
val p1 = A::x
|
||||
println(p1.get(A(42)))
|
||||
val a = A(117)
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
package mangling.mangling
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun test_direct() {
|
||||
val mutListInt = mutableListOf<Int>(1, 2, 3, 4)
|
||||
val mutListNum = mutableListOf<Number>(9, 10, 11, 12)
|
||||
@@ -32,7 +28,7 @@ fun test_multiple_constructors() {
|
||||
mangle3(number)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun main(args: Array<String>) {
|
||||
test_direct()
|
||||
test_param()
|
||||
test_multiple_constructors()
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
package mangling.mangling
|
||||
|
||||
public fun mangle1(l: List<Int>) {
|
||||
println("Int direct $l")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// TODO: remove kotlin_native.io once overrides are in place.
|
||||
fun main(args : Array<String>) {
|
||||
println("Hello, world!")
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
package runtime.basic.entry1
|
||||
|
||||
fun fail() {
|
||||
println("Test failed, this is a wrong main() function.")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
package runtime.basic.entry2
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
fail()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
package runtime.basic.initializers2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A(val msg: String) {
|
||||
init {
|
||||
println("init $msg")
|
||||
@@ -13,7 +9,7 @@ val globalValue1 = 1
|
||||
val globalValue2 = A("globalValue2")
|
||||
val globalValue3 = A("globalValue3")
|
||||
|
||||
@Test fun runTest() {
|
||||
fun main(args: Array<String>) {
|
||||
println(globalValue1.toString())
|
||||
println(globalValue2.toString())
|
||||
println(globalValue3.toString())
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
package runtime.basic.entry2
|
||||
|
||||
fun fail() {
|
||||
println("Test failed, this is a wrong main() function.")
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package serialization.deserialize_members
|
||||
import foo.bar.*
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import serialization.serialize_members.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun main(args: Array<String>) {
|
||||
val c = C()
|
||||
val d = C.D()
|
||||
val e = C.D.E()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package serialization.serialize_members
|
||||
package foo.bar
|
||||
|
||||
class R<T> {
|
||||
inline fun bar(t: T) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.JavaExec
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.process.ExecResult
|
||||
@@ -296,7 +295,117 @@ class TestFailedException extends RuntimeException {
|
||||
}
|
||||
}
|
||||
|
||||
class RunKonanTest extends KonanTest {
|
||||
abstract class ExtKonanTest extends KonanTest {
|
||||
|
||||
ExtKonanTest() {
|
||||
super()
|
||||
}
|
||||
|
||||
@Override
|
||||
String buildExePath() {
|
||||
// a single executable for all tests
|
||||
return "$outputDirectory/program.tr"
|
||||
}
|
||||
|
||||
// The same as its super() version but doesn't create a new dir for each test
|
||||
@Override
|
||||
void createOutputDirectory() {
|
||||
if (outputDirectory != null) {
|
||||
return
|
||||
}
|
||||
|
||||
def outputSourceSet = project.sourceSets.findByName(getOutputSourceSetName())
|
||||
if (outputSourceSet != null) {
|
||||
outputDirectory = outputSourceSet.output.getDirs().getSingleFile().absolutePath
|
||||
project.file(outputDirectory).mkdirs()
|
||||
} else {
|
||||
outputDirectory = getTemporaryDir().absolutePath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds tests with TestRunner enabled
|
||||
*/
|
||||
class BuildKonanTest extends ExtKonanTest {
|
||||
|
||||
public List<String> compileList
|
||||
public List<String> excludeList
|
||||
|
||||
@Override
|
||||
List<String> buildCompileList() {
|
||||
assert compileList != null
|
||||
|
||||
// convert exclude list to paths
|
||||
def excludeFiles = new ArrayList<String>()
|
||||
excludeList.each { excludeFiles.add(project.file(it).absolutePath) }
|
||||
|
||||
// create list of tests to compile
|
||||
def compileFiles = new ArrayList<String>()
|
||||
compileList.each {
|
||||
project.file(it).eachFileRecurse {
|
||||
if (it.isFile() && it.name.endsWith(".kt") && !excludeFiles.contains(it.absolutePath)) {
|
||||
compileFiles.add(it.absolutePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
compileFiles
|
||||
}
|
||||
|
||||
@Override
|
||||
void compileTest(List<String> filesToCompile, String exe) {
|
||||
flags = flags ?: []
|
||||
// compile with test runner enabled
|
||||
flags.add("-tr")
|
||||
runCompiler(filesToCompile, exe, flags)
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
@Override
|
||||
void executeTest() {
|
||||
// only build tests
|
||||
createOutputDirectory()
|
||||
def program = buildExePath()
|
||||
compileTest(buildCompileList(), program)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs test built with Konan's TestRunner
|
||||
*/
|
||||
class RunKonanTest extends ExtKonanTest {
|
||||
|
||||
RunKonanTest() {
|
||||
super()
|
||||
dependsOn(project.tasks['buildKonanTests'])
|
||||
}
|
||||
|
||||
@Override
|
||||
void compileTest(List<String> filesToCompile, String exe) {
|
||||
// tests should be already compiled
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
@Override
|
||||
void executeTest() {
|
||||
arguments = arguments ?: []
|
||||
// Print only test's output
|
||||
arguments.add("--ktest_logger=SILENT")
|
||||
arguments.add("--ktest_filter=" + convertToPattern(source))
|
||||
super.executeTest()
|
||||
}
|
||||
|
||||
private String convertToPattern(String source) {
|
||||
return source.replace('/', '.')
|
||||
.replace(".kt", "")
|
||||
.concat(".*")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles and executes test as a standalone binary
|
||||
*/
|
||||
class RunStandaloneKonanTest extends KonanTest {
|
||||
void compileTest(List<String> filesToCompile, String exe) {
|
||||
runCompiler(filesToCompile, exe, flags?:[])
|
||||
}
|
||||
@@ -379,7 +488,7 @@ class LinkKonanTest extends KonanTest {
|
||||
}
|
||||
}
|
||||
|
||||
class RunExternalTestGroup extends RunKonanTest {
|
||||
class RunExternalTestGroup extends RunStandaloneKonanTest {
|
||||
|
||||
def groupDirectory = "."
|
||||
def outputSourceSetName = "testOutputExternal"
|
||||
|
||||
@@ -48,8 +48,8 @@ object TestRunner {
|
||||
* --gtest_list_tests
|
||||
* --ktest_list_tests - Show all available tests.
|
||||
*
|
||||
* --gtest_filter=POSTIVE_PATTERNS[-NEGATIVE_PATTERNS]
|
||||
* --ktest_filter=POSTIVE_PATTERNS[-NEGATIVE_PATTERNS] - Run only the tests whose name matches one of the
|
||||
* --gtest_filter=POSITIVE_PATTERNS[-NEGATIVE_PATTERNS]
|
||||
* --ktest_filter=POSITIVE_PATTERNS[-NEGATIVE_PATTERNS] - Run only the tests whose name matches one of the
|
||||
* positive patterns but none of the negative patterns.
|
||||
* '?' matches any single character; '*' matches any
|
||||
* substring; ':' separates two patterns.
|
||||
|
||||
Reference in New Issue
Block a user