https://kotlinlang.org logo
#scripting
Title
# scripting
j

jmfayard

08/01/2022, 6:43 AM
Bonjour again, do you have a way to combine scripting and unit testing? Like if I have pure functions or a Regex inside my script, I would like to be able to unit test it so that the script itself is only a small imperative shell around the functional core
b

Big Chungus

08/01/2022, 8:34 AM
Only functional testing I guess where you invoke your script from shell and assert console and fs outputs
i.e. no dedicated script test framework unless you set one up yourself
j

jmfayard

08/01/2022, 8:35 AM
So probably a separate repo where I can unit test stuff and then I copy/paste in the script when it's ready
b

Big Chungus

08/01/2022, 8:37 AM
Not necessarily. Just have a test-only gradle jvm project in the repo and inject script file path via gradle task env vars
Or do you mean copying from .kt onto .kts file?
That can also be quite easily automated with custom gradle task (just merge all kt files into kts and extract @Import statements from gradle dependencies
j

jmfayard

08/01/2022, 8:39 AM
That could be cool
Ever wondered how to unit test your Kotlin Scripts? Following a suggestion from @Big Chungus I have put together a repository where scripts in a
bin
repository coexist with a normal Gradle project There's a way to mark a block of text as something you want to use in your Kotlin scripts, and a Gradle task that extract them from your KT files and update your KTS files with it https://github.com/jmfayard/my-kotlin-scipts
4 Views