๐ต๏ธ Debug#
Learn about Bookshelfโs debugging tools, including unit tests, logging and var dumping.
๐ Logging#
Bookshelf offers a logging module designed to centralize and streamline log management. For more details on this feature, refer to the log module documentation.
๐ฌ Var dumping#
Bookshelf offers a var dumper module designed to easily display a score or storage at any given time. For more details on this feature, refer to the dump module documentation.
๐งช Unit tests#
Tests are an integral part of any software development process. They help ensure the correctness of your code and can save you from potential bugs in the future. In this project, we use a Minecraft fabric mod made by Misode called PackTest.
โ๏ธ Writing tests#
Each test is a .mcfunction
file inside the test
folder, at the root of each module.
When writing tests, make sure to clearly define what you are testing and what the expected outcome is. Itโs also a good idea to include edge cases to ensure your code can handle all possible inputs.
Each test must set the @batch
directive to the name of the module. For example:
# This is a test
# @batch <bs.my_module>
This setup ensures that tests are correctly scoped to their respective modules, providing a structured and isolated testing environment.
Additionally, each test folder should contain a __boot__.mcfunction
file that initializes the testing environment. This file should set the @beforebatch
directive, as shown below:
# @batch <bs.my_module>
# @beforebatch function #<bs.my_module:load>
The purpose of these directives is to load only the relevant module, helping to identify any missing load instructions.
โ๏ธ Running tests#
To run the tests, you have two options:
Headless Mode: We provide a small script inside the notebook that allows you to run the tests headlessly, without having to open the game. This is a more convenient option for continuous integration environments.
In-Game: Download and install the Minecraft fabric mod. Once thatโs done, you can run the tests using the test command in Minecraft.
For more information on how to write and run tests, you can refer to Misodeโs PackTest repository.