Running Tests
GoogleTest framework, test structure, and how to run specific test suites.
Test Framework
sharp-runtime uses GoogleTest. Tests are built per requested component when SHARP_RUNTIME_BUILD_TESTS=ON (the default). GoogleTest is provided by the vendor/googletest/ Git submodule.
Run the Complete Suite
cmake -S . -B build \
-DSHARP_RUNTIME_COMPONENTS=All \
-DSHARP_RUNTIME_BUILD_TESTS=ON
cmake --build build --target SharpRuntimeTests --parallel 4
scripts/run_component_tests.sh build
SharpRuntimeTests is an aggregate build target. The runner script finds every selected component test executable, runs it, and prints a total after all executables pass.
Test One Component
cmake -S . -B build-json-tests \
'-DSHARP_RUNTIME_COMPONENTS=Text.Json' \
-DSHARP_RUNTIME_BUILD_TESTS=ON
cmake --build build-json-tests --target SharpRuntimeTests --parallel 4
scripts/run_component_tests.sh build-json-tests
This builds and runs SharpRuntimeTests_Text_Json. It does not build test executables for unrelated components or for ordinary production dependencies.
Run a Specific Test Suite
# The executable name derives from the component name.
./build-json-tests/SharpRuntimeTests_Text_Json \
--gtest_filter="Json*"
# CTest can discover individual GoogleTest cases.
ctest --test-dir build-json-tests --output-on-failure
Test Locations and Targets
Each component owns its tests next to its public headers and implementation:
| Component | Test source location | Test executable |
|---|---|---|
Core.Base | modules/core/tests/ | SharpRuntimeTests_Core_Base |
Collections.Core | modules/collections/tests/ | SharpRuntimeTests_Collections_Core |
Text.Json | modules/text-json/tests/ | SharpRuntimeTests_Text_Json |
IO.Compression | modules/io-compression/tests/ | SharpRuntimeTests_IO_Compression |
Net.Sockets | modules/net-sockets/tests/ | SharpRuntimeTests_Net_Sockets |
| Cross-component scenarios | tests/integration/ | SharpRuntimeIntegrationTests |
Adding a Test
Add the source beneath the owning component's tests/ directory. The component registration discovers and builds the test source; test-only production dependencies must be declared by that component, rather than being pulled in by the entire runtime.
// modules/text-json/tests/System/Text/Json/MyNewTests.cpp
#include <gtest/gtest.h>
#include <System/Text/Json/JsonDocument.hpp>
TEST(MyNewTests, ParsesExpectedInput) {
// ...
}
All and run the complete component suite.