Proof of concept for testing C code using Kotlin/Native.
// C
int add(int x, int y)
// Kotlin
testsuite("Add") {
test("Simple addition") {
assertEquals(4, add(1, 3))
}
}
# Your favorite terminal
$ make check
=== TESTSUITE: Add ===
PASS: Simple addition
=== Add: 1 passing ===
This is not production-ready by any means, and is just a proof-of-concept.
Most of the magic happens in the Makefile. Read the comments there to find out more.
In order to run this mess (which you should consider not doing), you will need:
- Linux. Windows is not worthy enough of such crap programming
- A JDK (AdoptOpenJDK is a good start)
- Install
libncurses5
for some reason (compilation of Kotlin stuff fails otherwise)
You do not need to have Kotlin/Native on your machine, the Makefile will download it automatically.
Then, simply run make check
.
I wanted an excuse for writing Kotlin code.
src
: C source filestests
: Kotlin test filesCut.kt
: Very simple test framework implementationTestsuite.kt
: Your tests here.
Makefile
: The Makefiletest_target.def
: Information file for KLib generation
All Cut.kt-related stuff is built into a separate kt_build
folder. After a make check
, the folder will contain the following:
kotlin-native
: Kotlin/Native binaries used to compile the stufftest_target.klib-build
:cinterop
uses that for building theklib
with your codetest_target.a
: Static library with all of the code that needs to be testedtest_target.klib
: Kotlin/Native library (with the static library embedded) with your codetestsuite.kexe
: Testsuite executable