CTest Integration & CI Pipelines
Relevant source files
The following files were used as context for generating this wiki page:
CTest integration within the mcpi-recompiled project serves as the primary mechanism for ensuring compatibility with the original Minecraft: Pi Edition 0.1.1 alpha protocol. By leveraging CMake's native testing capabilities, the project establishes a test-driven development (TDD) environment focused on reconstructing game behavior and preserving the TCP port 4711 programming API.
The testing infrastructure is designed to be cross-platform, supporting both Linux and Windows (x86-64) environments. It validates core components such as the protocol parser and the asynchronous API server through a combination of unit tests and integration tests that simulate network communication over loopback interfaces.
Sources: README.md:10-15, README.md:39-41, CMakeLists.txt:51-65
Build System Configuration
The project utilizes CMake to manage the build and test lifecycle. Testing is controlled via a specific CMake option, MCPI_BUILD_TESTS, which is enabled by default. When active, this option triggers the inclusion of test executables and registers them with the CTest runner.
Test Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
MCPI_BUILD_TESTS | BOOL | ON | Enables the compilation of test suites and activation of enable_testing(). |
Sources: CMakeLists.txt:9, CMakeLists.txt:51
CTest Execution Flow
The standard workflow for developers involves configuring the project with tests enabled, building the targets, and then executing the CTest utility to verify parity.
Sources: README.md:37-41, CMakeLists.txt:51-64
Defined Test Suites
The project implements two primary test targets that are registered as CTest entries. These targets are linked against the mcpi_core library, ensuring they have access to the internal API server and command parsing logic.
1. Protocol Parser Tests (mcpi_protocol_tests)
This suite focuses on the mcpi::api::parse_command function. It validates that strings received over the network are correctly decomposed into command names and argument lists, supporting various formats used by the MCPI protocol.
- Logic: Uses an
expecthelper to validate return values and exits with status1on failure. - Validation Cases:
world.setBlock(1,2,3,57)\n(Standard block placement)player.getPos()\r\n(Zero-argument retrieval)chat.post(Hello from Pi)(String payload handling)- Rejection of malformed or empty inputs.
Sources: tests/protocol_tests.cpp:21-47, CMakeLists.txt:54-57
2. API Server Integration Tests (mcpi_api_server_tests)
This suite performs an end-to-end integration test of the ApiServer class. It initializes a live TCP server on an available port and uses a native socket client to verify network interaction.
- Mechanism:
- Initializes
mcpi::api::ApiServer(0)to bind to an ephemeral port. - Establishes a loopback connection via
connect_loopback. - Sends a command (
player.getPos()) and validates the server's response handling.
- Initializes
- Platform Support: The test includes conditional compilation for
winsock2.hon Windows andsys/socket.hon POSIX systems to ensure CI parity across platforms.
Sources: tests/api_server_tests.cpp:11-30, tests/api_server_tests.cpp:103-125, CMakeLists.txt:59-62
API Server Data Flow in Testing
The integration tests verify the internal threading and socket handling of the ApiServer. The server operates by spawning a worker thread that listens for incoming connections and processes commands asynchronously.
CI Pipeline Requirements
The project roadmap prioritizes bootstrapping a portable C++ build with CI. The CMakeLists.txt is structured to facilitate this by enforcing strict compilation standards and providing granular test outputs.
- Compiler Standards: Requires C++20 (
cxx_std_20) for all targets, including tests. - Warning Levels: CI pipelines are expected to catch issues via
-Wall -Wextra -Wpedanticon non-MSVC compilers and/W4on MSVC. - Execution: CI environments should execute tests using
ctest --output-on-failureto provide visibility into the specific failures within the protocol or API server logic.
Sources: README.md:41, CMakeLists.txt:13-15, CMakeLists.txt:34-38
The integration of CTest and specialized test suites ensures that as the project progresses through its reconstruction phases, the foundational MCPI protocol compatibility remains intact across all supported operating systems.