untoldwind / KontrolSystem2

Autopilot scripting system for KSP2
Other
54 stars 14 forks source link

Custom unit tests #161

Closed versvisa closed 2 months ago

versvisa commented 2 months ago

Hello, I see there are a bunch of unit test functions of the form test sync fn test_...() -> Unit = {. How can I use that system for my own code? When and where are the tests executed?

If it does not happen already, I suppose it would be good to run all tests (optionally) when "rebooting", i.e. loading/compiling the TO2 code.

lefouvert commented 2 months ago

issue #120

untoldwind commented 2 months ago

As mentioned in the referenced issue, the "test fn" functions are currently only executed during the build process of the addon (as a mix between unit and regression tests).

It would be nice to have this generally available for stuff in "to2Local" as well. There are just some things to consider:

What I eventually want to explore is bundling a test-runner as a WASM, so that it could be easily integrated into anything javascript/typescript related and would be executed in a sandbox environment ... but again: Time and priority ;)

untoldwind commented 2 months ago

... and sometimes I just overthink it. pre-release 0.5.8.2 (https://github.com/untoldwind/KontrolSystem2/releases/tag/v0.5.8.2) now has console commands. One of the commands is "test" to run unit-tests.

Results are reported in the Console window (so no extra UI necessary ;) )

I also overhauled the REPL execution: Expressions typed into the console should now behave the same as in scripts (it is running through the same compilation steps)

untoldwind commented 2 months ago

Now part of the regular release 0.5.8.3

lefouvert commented 2 months ago

Gorgeous.