🕵️ Debug Tools#
Debugging is a fundamental aspect of software development. Bookshelf provides tools to help identify and resolve issues effectively.
🧪 Unit Tests#
Tests are essential for ensuring code correctness and preventing future bugs. This project uses Misode’s Minecraft Fabric mod, PackTest, for testing.
⚙️ Running Tests#
To run the tests, you have two options:
Headless Mode: We provide a simple command
pdm run modules test
that allows you to run the tests headlessly, without having to open the gameIn-Game: Download and install the Minecraft Fabric mod. Once that’s done, you can run the tests using the test command in Minecraft
Java Required
Ensure that Java is installed on your system, as it is required for the command to work.
✍️ Writing Tests#
Each test is a .mcfunction
file inside the test
folder.
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.
🛠️ Custom Commands#
PackTest offers a variety of commands to control test flow, validate conditions, and interact with Minecraft’s environment:
Test Flow Commands:
fail [<text>]
: Immediately fails the current test and logs an optional messagesucceed
: Immediately passes the current testassert <condition>
: Fails the test if the condition is falseassert not <condition>
: Fails the test if the condition is trueawait <condition>
: Continuously checks a condition until it succeeds or times outawait not <condition>
: Waits until the condition becomes falseawait delay <time>
: Pauses the test for a specified duration
Condition Types:
block <pos> <block>
: Checks if a block at the specified position matches the given blockdata <path>
: Verifies NBT data using standard Minecraft data syntaxentity <selector>
: Validates if entities match a selector (works beyond test boundaries)predicate <predicate>
: Executes a predicate in the data packscore <target>
: Compares scores using Minecraft’s score-based conditionschat <pattern> [<receivers>]
: Matches chat messages against a regex pattern
🧍 Player Dummies#
PackTest allows you to spawn and control “dummies,” simulated players for testing:
dummy <name> spawn
: Spawns a new dummydummy <name> respawn
: Respawns the dummy after it has been killeddummy <name> leave
: Makes the dummy leave the serverdummy <name> jump
: Makes the dummy jumpdummy <name> sneak [true|false]
: Makes the dummy hold shift or un-shift (not the same as currently crouching)dummy <name> sprint [true|false]
: Makes the dummy sprint or un-sprintdummy <name> drop [all]
: Makes the dummy drop the current mainhand, either one item or the entire stackdummy <name> swap
: Makes the dummy swap its mainhand and offhanddummy <name> selectslot
: Makes the dummy select a different hotbar slotdummy <name> use item
: Makes the dummy use its hand item, either mainhand or offhanddummy <name> use block <pos> [<direction>]
: Makes the dummy use its hand item on a block positiondummy <name> use entity <entity>
: Makes the dummy use its hand item on an entitydummy <name> attack <entity>
: Makes the dummy attack an entity with its mainhanddummy <name> mine <pos>
: Makes the dummy mine a block
📋 Test Directives#
You can customize tests using directives (special comments at the beginning of the test):
@template
: The resource location of a structure template to use for the test, defaults tominecraft:empty
, which is an empty 1×1×1 structure@timeout
: An integer specifying the timeout, defaults to100
@optional
: Whether this test is allowed to fail, defaults tofalse
, if there is no value after the directive it is considered astrue
@skyaccess
: Whether this test needs sky access, defaults tofalse
, which will place barrier blocks above the test@dummy
: Whether to spawn a dummy at the start of the test and set@s
to this dummy, taking a position which defaults to~0.5 ~ ~0.5
Learn more…
If you need more information than this page provides, visit Misode’s repository for detailed guidance on writing tests.
📦 Modules#
Bookshelf includes a variety of modules designed to enhance your development experience.
📄 Logging#
Centralizes and streamlines log management, making it easier to monitor and troubleshoot your project. For more details, refer to the log module documentation.
🔬 Var Dumping#
Provides an easy way to display scores or storage values at any given time, helping with debugging and tracking. For more details, refer to the dump module documentation.