-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit tests #145
Comments
Expanding on the idea: The functionality will be built upon modules (#149). Unit tests will be code blocks annotated with a Compiling without unit tests:
Compiling with unit tests:
Mocking the environment:
A unit test might look like this:
|
Unit tests were implemented in version 2.6.0 for the system library. The unit tests depend on the text output created by the test code, which allows testing not just values of the variables, but also actual output generated by the program. |
Some rudimentary support for unit testing will be included in the next release. The Mindcode compiler will support two new functions:
Example of a code utilizing these functions:
The special instructions generated by the To create a basic unit test, a separate source file containing just the assertions should be created. This file would use the Unit tests would be executed by compiling and running the unit test file. It's a far cry from a finished unit tests suite, but it still could be useful when developing and maintaining a set of library functions. |
So, today's session of debugging some Mindcode has given me another idea: unit testing of Mindcode.
We already have a processor emulator, so we can run compiled Mindcode. Unit tests might be, for simplicity, contained in the same source file as the code being tested, perhaps in some separate section, perhaps just functions marked with some annotation.
All test functions would be run. If they return anything else than
0
, the test would fail and the output of the text buffer would be printed.The processor emulator can already emulate memory cells and memory banks. In the future, more parts of the Mindustry World could be emulated (mocked). The mocked world would be static - certainly at the beginning.
As a first step, the mocked objects would just return values when sensed (this could be easily provided as a collection of property-value pairs) and would accept any calls. Later the calls might be somehow tracked too.
The text was updated successfully, but these errors were encountered: