Skip to content

Commit 9a869f8

Browse files
author
Patrick Jackson
committed
add thunk code and test
1 parent 3744394 commit 9a869f8

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

common/build.gradle

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ kotlin {
1414
targets {
1515
js()
1616
jvm()
17+
// iOS commented out b/c appling test to JS & iOS does not work. Comment JS tests for iOS to work
18+
19+
def buildForDevice = project.findProperty("device")?.toBoolean() ?: false
20+
def iosPreset = (buildForDevice) ? presets.iosArm64 : presets.iosX64
21+
fromPreset(iosPreset, 'ios') {
22+
binaries {
23+
framework {
24+
// Disable bitcode embedding for the simulator build.
25+
if (!buildForDevice) {
26+
embedBitcode("disable")
27+
}
28+
}
29+
}
30+
}
31+
1732
}
1833
sourceSets {
1934
commonMain {
@@ -47,16 +62,52 @@ kotlin {
4762
implementation kotlin("stdlib-js")
4863
}
4964
}
65+
iosTest {
66+
dependsOn commonTest
67+
}
68+
69+
}
70+
71+
}
72+
5073

74+
task iosTest {
75+
def device = project.findProperty("iosDevice")?.toString() ?: "iPhone 8"
76+
dependsOn 'linkDebugTestIos'
77+
group = JavaBasePlugin.VERIFICATION_GROUP
78+
description = "Runs tests for target 'ios' on an iOS simulator"
79+
80+
doLast {
81+
def binary = kotlin.targets.ios.binaries.getTest('DEBUG').outputFile
82+
exec {
83+
commandLine 'xcrun', 'simctl', 'spawn', device, binary.absolutePath
84+
}
5185
}
86+
}
5287

88+
task copyFramework {
89+
def buildType = project.findProperty("kotlin.build.type") ?: "DEBUG"
90+
dependsOn "link${buildType.toLowerCase().capitalize()}FrameworkIos"
91+
92+
doLast {
93+
def srcFile = kotlin.targets.ios.binaries.getFramework(buildType).outputFile
94+
def targetDir = getProperty("configuration.build.dir")
95+
copy {
96+
from srcFile.parent
97+
into targetDir
98+
include 'greeting.framework/**'
99+
include 'greeting.framework.dSYM'
100+
}
101+
}
53102
}
54103

104+
105+
55106
// workaround for https://youtrack.jetbrains.com/issue/KT-27170
56107
configurations {
57108
compileClasspath
58109
}
59-
110+
/*
60111
//Workaround to copy kotlin libraries so they are visible during testing
61112
def jsLibDir = "$compileKotlinJs.destinationDir/lib"
62113
def jsTestLibDir = "$compileTestKotlinJs.destinationDir/lib"
@@ -99,4 +150,6 @@ task runMocha(type: NodeTask, dependsOn: [installMocha, jsMainClasses, jsTestCla
99150
script = file("$nodeWorkingDir/node_modules/mocha/bin/mocha")
100151
args = [compileTestKotlinJs.outputFile]
101152
}
102-
jsTest.dependsOn runMocha
153+
jsTest.dependsOn runMocha
154+
155+
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
11
import kotlin.test.Test
22
import kotlin.test.fail
33

4+
typealias Dispatch = (Any) -> Any
5+
typealias GetState = () -> Any
6+
typealias Thunk = (Dispatch, GetState, Any?) -> Any
7+
48
class FunctionCheckTest {
59

10+
611
@Test
712
fun passIsCheck() {
813
if ({ str: String -> } is Function<*>) {
914
} else {
1015
fail("Function not recognized in `is Function<*>`")
1116
}
1217
}
18+
19+
data class AppState(val string: String)
20+
21+
val dispatch: Dispatch = { }
22+
val getState: GetState = { AppState("myState") }
23+
24+
fun myThunk(dispatch: Dispatch, getState: GetState, arg: Any?) {
25+
println("Inside thunk")
26+
}
27+
28+
fun test(foo: Any) {
29+
if (foo is Function<*>) {
30+
(foo as Thunk)(dispatch, getState, null)
31+
} else {
32+
fail()
33+
}
34+
}
35+
36+
@Test
37+
fun typeAliasCheck() {
38+
test(::myThunk)
39+
}
1340
}

0 commit comments

Comments
 (0)