BC native tests port to Konan's TestRunner
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package codegen.function.arithmetic
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun square(a:Int):Int = a * a
|
||||
fun sumOfSquares(a:Int, b:Int):Int = square(a) + square(b)
|
||||
fun diffOfSquares(a:Int, b:Int):Int = square(a) - square(b)
|
||||
fun mod(a:Int,b:Int):Int = a / b
|
||||
fun remainder(a:Int, b:Int):Int = a % b
|
||||
|
||||
fun main(args:Array<String>) {
|
||||
@Test fun runTest() {
|
||||
if (square(2) != 4) throw Error()
|
||||
if (sumOfSquares(2, 4) != 20) throw Error()
|
||||
if (diffOfSquares(2, 4) != -12) throw Error()
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package codegen.function.boolean
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun bool_yes(): Boolean = true
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@Test fun runTest() {
|
||||
if (!bool_yes()) throw Error()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
package codegen.function.defaults
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
/**
|
||||
* Created by minamoto on 12/26/16.
|
||||
*/
|
||||
@@ -14,9 +18,8 @@ open class A(val a:Int) {
|
||||
val one = A(1)
|
||||
val magic = A(42)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// FUN public fun foo(a: defaults.A = ...): kotlin.Int
|
||||
// a: EXPRESSION_BODY
|
||||
// CALL '<get-magic>(): A' type=defaults.A origin=GET_PROPERTY
|
||||
@@ -40,7 +43,7 @@ fun foo(a: A = A.magic, b:Int = 0xdeadbeef.toInt()) = a.a
|
||||
fun bar(a:A, inc:Int = 0) = A(a.a + inc)
|
||||
|
||||
|
||||
fun main(args:Array<String>) {
|
||||
@Test fun runTest() {
|
||||
|
||||
// if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
@@ -92,6 +95,3 @@ fun main(args:Array<String>) {
|
||||
}
|
||||
println("all tests passed")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package codegen.function.defaults1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(x:Int = 0, y:Int = x + 1, z:Int = x + y + 1) = x + y + z
|
||||
|
||||
fun main(arg:Array<String>) {
|
||||
@Test fun runTest() {
|
||||
val v = foo()
|
||||
if (v != 3) {
|
||||
println("test failed $v expected 3")
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package codegen.function.defaults10
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class A(one: Int, val two: Int = one) {
|
||||
FOO(42)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@Test fun runTest() {
|
||||
println(A.FOO.two)
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package codegen.function.defaults2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
fun Int.foo(inc0:Int, inc:Int = 0) = this + inc0 + inc
|
||||
|
||||
fun main(arg:Array<String>) {
|
||||
@Test fun runTest() {
|
||||
val v = 42.foo(0)
|
||||
if (v != 42) {
|
||||
println("test failed v:$v expected:42")
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package codegen.function.defaults3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(a:Int = 2, b:String = "Hello", c:Int = 4):String = "$b-$c$a"
|
||||
fun foo(a:Int = 3, b:Int = a + 1, c:Int = a + b) = a + b + c
|
||||
|
||||
fun main(arg:Array<String>){
|
||||
@Test fun runTest() {
|
||||
val a = foo(b="Universe")
|
||||
if (a != "Universe-42")
|
||||
throw Error()
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
package codegen.function.defaults4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class A {
|
||||
open fun foo(x: Int = 42) = println(x)
|
||||
}
|
||||
@@ -8,6 +12,6 @@ class C : B() {
|
||||
override fun foo(x: Int) = println(x + 1)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@Test fun runTest() {
|
||||
C().foo()
|
||||
}
|
||||
@@ -1,14 +1,18 @@
|
||||
class Test(val x: Int) {
|
||||
package codegen.function.defaults5
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class TestClass(val x: Int) {
|
||||
fun foo(y: Int = x) {
|
||||
println(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun Test.bar(y: Int = x) {
|
||||
fun TestClass.bar(y: Int = x) {
|
||||
println(y)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
Test(5).foo()
|
||||
Test(6).bar()
|
||||
@Test fun runTest() {
|
||||
TestClass(5).foo()
|
||||
TestClass(6).bar()
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
package codegen.function.defaults6
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class Foo(val x: Int = 42)
|
||||
class Bar : Foo()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@Test fun runTest() {
|
||||
println(Bar().x)
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
package codegen.function.defaults7
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
/**
|
||||
* Test fails with code generation:
|
||||
* Call parameter type does not match function signature!
|
||||
@@ -11,6 +15,6 @@ fun <T> foo(a : T, b : Int = 42){
|
||||
println(b)
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
@Test fun runTest() {
|
||||
foo(1)
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
package codegen.function.defaults8
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class Foo {
|
||||
fun test(x: Int = 1) = x
|
||||
}
|
||||
@@ -6,6 +10,6 @@ class Bar {
|
||||
fun test(x: Int = 2) = x
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
@Test fun runTest() {
|
||||
println(Bar().test())
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package codegen.function.defaults9
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class Foo {
|
||||
inner class Bar(x: Int, val y: Int = 1) {
|
||||
constructor() : this(42)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(arg:Array<String>) = println(Foo().Bar().y)
|
||||
@Test fun runTest() = println(Foo().Bar().y)
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
package codegen.function.eqeq
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun eqeqB (a:Byte, b:Byte ) = a == b
|
||||
fun eqeqS (a:Short, b:Short ) = a == b
|
||||
fun eqeqI (a:Int, b:Int ) = a == b
|
||||
@@ -26,7 +30,7 @@ fun neF (a:Float, b:Float ) = a != b
|
||||
fun helloString() = "Hello"
|
||||
fun goodbyeString() = "Goodbye"
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@Test fun runTest() {
|
||||
if (!eqeqB(3 , 3 )) throw Error()
|
||||
if (!eqeqS(3 , 3 )) throw Error()
|
||||
if (!eqeqI(3 , 3 )) throw Error()
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
package codegen.function.intrinsic
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// This code fails to link when bultins are taken from the
|
||||
// frontend generated module, instead of our library.
|
||||
@@ -10,6 +13,6 @@ fun intrinsic(b: Int): Int {
|
||||
return sum
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@Test fun runTest() {
|
||||
if (intrinsic(3) != 4) throw Error()
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
fun main(args : Array<String>) {
|
||||
package codegen.function.localFunction
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val x = 1
|
||||
fun local0() = println(x)
|
||||
fun local1() {
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
fun main(args: Array<String>) {
|
||||
package codegen.function.localFunction2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
var a = 0
|
||||
fun local() {
|
||||
class A {
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
fun main(args : Array<String>) {
|
||||
package codegen.function.localFunction3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun bar() {
|
||||
fun local1() {
|
||||
bar()
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package codegen.function.minus_eq
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun minus_eq(a: Int): Int {
|
||||
var b = 11
|
||||
b -= a
|
||||
return b
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@Test fun runTest() {
|
||||
if (minus_eq(23) != -12) throw Error()
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
package codegen.function.named
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(a:Int, b:Int) = a - b
|
||||
fun main(args:Array<String>) {
|
||||
|
||||
@Test fun runTest() {
|
||||
if (foo(b = 24, a = 42) != 18)
|
||||
throw Error()
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package codegen.function.plus_eq
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun plus_eq(a: Int): Int {
|
||||
var b = 11
|
||||
b += a
|
||||
return b
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@Test fun runTest() {
|
||||
if (plus_eq(3) != 14) throw Error()
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
package codegen.function.sum
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun sumIB(a:Int, b:Byte ) = a + b
|
||||
fun sumIS(a:Int, b:Short ) = a + b
|
||||
fun sumII(a:Int, b:Int ) = a + b
|
||||
@@ -7,7 +11,7 @@ fun sumID(a:Int, b:Double) = a + b
|
||||
|
||||
fun modID(a:Int, b:Double) = a % b
|
||||
|
||||
fun main(args:Array<String>) {
|
||||
@Test fun runTest() {
|
||||
if (sumIB(2, 3) != 5) throw Error()
|
||||
if (sumIS(2, 3) != 5) throw Error()
|
||||
if (sumII(2, 3) != 5) throw Error()
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package codegen.function.sum_3const
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun sum3():Int = sum(1, 2, 33)
|
||||
fun sum(a:Int, b:Int, c:Int): Int = a + b + c
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@Test fun runTest() {
|
||||
if (sum3() != 36) throw Error()
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package codegen.function.sum_foo_bar
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(a:Int):Int = a
|
||||
fun bar(a:Int):Int = a
|
||||
|
||||
fun sumFooBar(a:Int, b:Int):Int = foo(a) + bar(b)
|
||||
|
||||
fun main(args:Array<String>) {
|
||||
@Test fun runTest() {
|
||||
if (sumFooBar(2, 3) != 5) throw Error()
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
package codegen.function.sum_func
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo():Int = 1
|
||||
//fun bar():Int = 2
|
||||
//fun sum():Int = foo() + bar()
|
||||
//fun sum():Int = foo() + bar()
|
||||
|
||||
// FIXME: has no checks
|
||||
@@ -1,5 +1,9 @@
|
||||
package codegen.function.sum_imm
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun sum(a:Int): Int = a + 33
|
||||
|
||||
fun main(args:Array<String>) {
|
||||
@Test fun runTest() {
|
||||
if (sum(2) != 35) throw Error()
|
||||
}
|
||||
@@ -1 +1,6 @@
|
||||
package codegen.function.sum_mixed
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// FIXME: has no checks
|
||||
fun sum(a:Float, b:Int) = a + b
|
||||
@@ -1,3 +1,9 @@
|
||||
package codegen.function.sum_silly
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// FIXME: has no checks
|
||||
|
||||
fun sum(a:Int, b:Int):Int {
|
||||
var c:Int
|
||||
c = a + b
|
||||
|
||||
Reference in New Issue
Block a user