Skip to content

Commit

Permalink
Add test runner
Browse files Browse the repository at this point in the history
- Move test utilities to util/testing
- Allow to pass options from VoxelEngine.run_tests()
- Add runner to the Godot project for use with GDExtension builds
  • Loading branch information
Zylann committed Mar 4, 2025
1 parent e6ccda3 commit d424fdb
Show file tree
Hide file tree
Showing 38 changed files with 201 additions and 74 deletions.
4 changes: 3 additions & 1 deletion common.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ def get_sources(env, is_editor_build, include_tests):
sources += [
"tests/*.cpp",
"tests/util/*.cpp",
"tests/voxel/*.cpp"
"tests/voxel/*.cpp",

"util/testing/*.cpp"
]

def process_glob_paths(p_sources):
Expand Down
8 changes: 5 additions & 3 deletions engine/voxel_engine_gd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#ifdef VOXEL_TESTS
#include "../tests/tests.h"
#include "../util/testing/test_options.h"
#endif

using namespace zylann::godot;
Expand Down Expand Up @@ -188,8 +189,9 @@ Vector3 VoxelEngine::get_editor_camera_direction() const {

#ifdef VOXEL_TESTS

void VoxelEngine::run_tests() {
zylann::voxel::tests::run_voxel_tests();
void VoxelEngine::run_tests(Dictionary options_dict) {
zylann::testing::TestOptions options(options_dict);
zylann::voxel::tests::run_voxel_tests(options);
}

#endif
Expand Down Expand Up @@ -217,7 +219,7 @@ void VoxelEngine::_bind_methods() {
);

#ifdef VOXEL_TESTS
ClassDB::bind_method(D_METHOD("run_tests"), &VoxelEngine::run_tests);
ClassDB::bind_method(D_METHOD("run_tests", "options"), &VoxelEngine::run_tests);
#endif

// ClassDB::bind_method(
Expand Down
2 changes: 1 addition & 1 deletion engine/voxel_engine_gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class VoxelEngine : public Object {
#endif

#ifdef VOXEL_TESTS
void run_tests();
void run_tests(Dictionary options_dict);
#endif

private:
Expand Down
7 changes: 7 additions & 0 deletions project/tests/runner.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends Node

func _ready() -> void:
if VoxelEngine.has_method("run_tests"):
VoxelEngine.call_deferred("run_tests")
else:
push_error("Tests not available")
1 change: 1 addition & 0 deletions project/tests/runner.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://c757lvb02hpah
6 changes: 6 additions & 0 deletions project/tests/runner.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://by5xtqdgr0r13"]

[ext_resource type="Script" uid="uid://c757lvb02hpah" path="res://tests/runner.gd" id="1_p0saw"]

[node name="Node" type="Node"]
script = ExtResource("1_p0saw")
3 changes: 2 additions & 1 deletion register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@

#ifdef VOXEL_TESTS
#include "tests/tests.h"
#include "util/testing/test_options.h"
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -367,7 +368,7 @@ void initialize_voxel_module(ModuleInitializationLevel p_level) {
for (int i = 0; i < command_line_arguments.size(); ++i) {
const String arg = command_line_arguments[i];
if (arg == tests_cmd) {
zylann::voxel::tests::run_voxel_tests();
zylann::voxel::tests::run_voxel_tests(zylann::testing::TestOptions());
break;
}
}
Expand Down
7 changes: 3 additions & 4 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "tests.h"
#include "../util/profiling.h"
#include "testing.h"
#include "../util/testing/test_options.h"

#include "util/test_box3i.h"
#include "util/test_container_funcs.h"
Expand Down Expand Up @@ -37,13 +37,12 @@
namespace zylann::voxel::tests {

#define VOXEL_TEST(fname) \
{ \
print_line("Running " #fname); \
if (options.can_run_print(#fname)) { \
ZN_PROFILE_SCOPE_NAMED(#fname); \
fname(); \
}

void run_voxel_tests() {
void run_voxel_tests(const testing::TestOptions &options) {
print_line("------------ Voxel tests begin -------------");

using namespace zylann::tests;
Expand Down
23 changes: 18 additions & 5 deletions tests/tests.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
#ifndef VOXEL_TESTS_H
#define VOXEL_TESTS_H

namespace zylann::voxel::tests {
void run_voxel_tests();
} // namespace zylann::voxel::tests
#include "../util/godot/macros.h"

namespace zylann::voxel::noise_tests {
namespace zylann {

namespace testing {
class TestOptions;
}

namespace voxel {

namespace tests {
void run_voxel_tests(const testing::TestOptions &options);
}

namespace noise_tests {
void run_noise_tests();
} // namespace zylann::voxel::noise_tests
}

} // namespace voxel
} // namespace zylann

#endif // VOXEL_TESTS_H
2 changes: 1 addition & 1 deletion tests/util/test_box3i.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "test_box3i.h"
#include "../../util/containers/std_unordered_map.h"
#include "../../util/math/box3i.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::tests {

Expand Down
14 changes: 9 additions & 5 deletions tests/util/test_container_funcs.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "test_container_funcs.h"
#include "../../util/containers/container_funcs.h"
#include "../../util/containers/std_vector.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::tests {

Expand Down Expand Up @@ -29,7 +29,8 @@ void test_unordered_remove_if() {

ZN_TEST_ASSERT(vec.size() == 3);
ZN_TEST_ASSERT(
L::count(vec, 0) == 0 && L::count(vec, 1) == 1 && L::count(vec, 2) == 1 && L::count(vec, 3) == 1);
L::count(vec, 0) == 0 && L::count(vec, 1) == 1 && L::count(vec, 2) == 1 && L::count(vec, 3) == 1
);
}
// Remove one in middle
{
Expand All @@ -43,7 +44,8 @@ void test_unordered_remove_if() {

ZN_TEST_ASSERT(vec.size() == 3);
ZN_TEST_ASSERT(
L::count(vec, 0) == 1 && L::count(vec, 1) == 1 && L::count(vec, 2) == 0 && L::count(vec, 3) == 1);
L::count(vec, 0) == 1 && L::count(vec, 1) == 1 && L::count(vec, 2) == 0 && L::count(vec, 3) == 1
);
}
// Remove one at end
{
Expand All @@ -57,7 +59,8 @@ void test_unordered_remove_if() {

ZN_TEST_ASSERT(vec.size() == 3);
ZN_TEST_ASSERT(
L::count(vec, 0) == 1 && L::count(vec, 1) == 1 && L::count(vec, 2) == 1 && L::count(vec, 3) == 0);
L::count(vec, 0) == 1 && L::count(vec, 1) == 1 && L::count(vec, 2) == 1 && L::count(vec, 3) == 0
);
}
// Remove multiple
{
Expand All @@ -71,7 +74,8 @@ void test_unordered_remove_if() {

ZN_TEST_ASSERT(vec.size() == 2);
ZN_TEST_ASSERT(
L::count(vec, 0) == 1 && L::count(vec, 1) == 0 && L::count(vec, 2) == 0 && L::count(vec, 3) == 1);
L::count(vec, 0) == 1 && L::count(vec, 1) == 0 && L::count(vec, 2) == 0 && L::count(vec, 3) == 1
);
}
// Remove last
{
Expand Down
2 changes: 1 addition & 1 deletion tests/util/test_expression_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "test_expression_parser.h"
#include "../../util/math/funcs.h"
#include "../../util/string/expression_parser.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::tests {

Expand Down
2 changes: 1 addition & 1 deletion tests/util/test_flat_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../../util/containers/flat_map.h"
#include "../../util/containers/std_vector.h"
#include "../../util/godot/core/random_pcg.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::tests {

Expand Down
2 changes: 1 addition & 1 deletion tests/util/test_island_finder.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "test_island_finder.h"
#include "../../util/containers/std_vector.h"
#include "../../util/island_finder.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::tests {

Expand Down
2 changes: 1 addition & 1 deletion tests/util/test_math_funcs.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "test_math_funcs.h"
#include "../../util/math/funcs.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::tests {

Expand Down
2 changes: 1 addition & 1 deletion tests/util/test_noise.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "test_noise.h"
#include "../../util/noise/fast_noise_lite/fast_noise_lite.h"
#include "../../util/noise/fast_noise_lite/fast_noise_lite_range.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::tests {

Expand Down
2 changes: 1 addition & 1 deletion tests/util/test_slot_map.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "test_slot_map.h"
#include "../../util/containers/slot_map.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::tests {

Expand Down
2 changes: 1 addition & 1 deletion tests/util/test_spatial_lock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "../../util/profiling.h"
#include "../../util/string/format.h"
#include "../../util/tasks/threaded_task_runner.h"
#include "../../util/testing/test_macros.h"
#include "../../util/thread/spatial_lock_3d.h"
#include "../testing.h"

// #define VOXEL_TEST_TASK_POSTPONING_DUMP_EVENTS
#ifdef VOXEL_TEST_TASK_POSTPONING_DUMP_EVENTS
Expand Down
2 changes: 1 addition & 1 deletion tests/util/test_threaded_task_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "../../util/string/format.h"
#include "../../util/string/std_stringstream.h"
#include "../../util/tasks/threaded_task_runner.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

// #define VOXEL_TEST_TASK_POSTPONING_DUMP_EVENTS
#ifdef VOXEL_TEST_TASK_POSTPONING_DUMP_EVENTS
Expand Down
2 changes: 1 addition & 1 deletion tests/voxel/test_block_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "../../streams/voxel_block_serializer.h"
#include "../../streams/voxel_block_serializer_gd.h"
#include "../../util/godot/classes/stream_peer_buffer.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::voxel::tests {

Expand Down
2 changes: 1 addition & 1 deletion tests/voxel/test_curve_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../../generators/graph/range_utility.h"
#include "../../util/containers/std_vector.h"
#include "../../util/godot/classes/curve.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::voxel::tests {

Expand Down
2 changes: 1 addition & 1 deletion tests/voxel/test_detail_rendering_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "../../meshers/transvoxel/transvoxel_cell_iterator.h"
#include "../../meshers/transvoxel/voxel_mesher_transvoxel.h"
#include "../../util/godot/classes/time.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::voxel::tests {

Expand Down
2 changes: 1 addition & 1 deletion tests/voxel/test_edition_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "../../meshers/blocky/voxel_blocky_model_mesh.h"
#include "../../storage/voxel_data.h"
#include "../../util/godot/classes/image.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"
#include "test_util.h"

namespace zylann::voxel::tests {
Expand Down
2 changes: 1 addition & 1 deletion tests/voxel/test_octree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "../../util/containers/std_unordered_set.h"
#include "../../util/math/conv.h"
#include "../../util/profiling_clock.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

#include <core/string/print_string.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/voxel/test_raycast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "../../meshers/blocky/voxel_blocky_model_empty.h"
#include "../../meshers/blocky/voxel_mesher_blocky.h"
#include "../../storage/voxel_data.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::voxel::tests {

Expand Down
3 changes: 2 additions & 1 deletion tests/voxel/test_region_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include "../../streams/region/voxel_stream_region_files.h"
#include "../../util/containers/std_unordered_map.h"
#include "../../util/godot/core/random_pcg.h"
#include "../testing.h"
#include "../../util/testing/test_directory.h"
#include "../../util/testing/test_macros.h"

namespace zylann::voxel::tests {

Expand Down
2 changes: 1 addition & 1 deletion tests/voxel/test_storage_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../../storage/funcs.h"
#include "../../storage/materials_4i4w.h"
#include "../../util/containers/std_vector.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::voxel::tests {

Expand Down
3 changes: 2 additions & 1 deletion tests/voxel/test_stream_sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include "../../util/profiling.h"
#include "../../util/profiling_clock.h"
#include "../../util/string/format.h"
#include "../testing.h"
#include "../../util/testing/test_directory.h"
#include "../../util/testing/test_macros.h"

namespace zylann::voxel::tests {

Expand Down
4 changes: 3 additions & 1 deletion tests/voxel/test_voxel_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#include "../../storage/metadata/voxel_metadata_variant.h"
#include "../../storage/voxel_buffer_gd.h"
#include "../../streams/voxel_block_serializer.h"
#include "../../util/io/log.h"
#include "../../util/string/std_string.h"
#include "../../util/string/std_stringstream.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"
#include <sstream>

namespace zylann::voxel::tests {
Expand Down
8 changes: 5 additions & 3 deletions tests/voxel/test_voxel_data_map.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "test_voxel_data_map.h"
#include "../../storage/voxel_buffer.h"
#include "../../storage/voxel_data_map.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"

namespace zylann::voxel::tests {

Expand Down Expand Up @@ -64,7 +64,8 @@ void test_voxel_data_map_paste_mask() {
const Box3i box(Vector3i(10, 10, 10), buffer.get_size());

map.paste_masked(
box.position, buffer, (1 << channel), true, channel, masked_value, false, 0, Span<const int32_t>(), true);
box.position, buffer, (1 << channel), true, channel, masked_value, false, 0, Span<const int32_t>(), true
);

// All voxels in the area must be as pasted. Ignoring the outline.
const bool is_match = box.padded(-1).all_cells_match([&map](const Vector3i &pos) { //
Expand Down Expand Up @@ -137,7 +138,8 @@ void test_voxel_data_map_copy() {
}

map.paste_masked(
box.position, buffer, (1 << channel), true, channel, default_value, false, 0, Span<const int32_t>(), true);
box.position, buffer, (1 << channel), true, channel, default_value, false, 0, Span<const int32_t>(), true
);

VoxelBuffer buffer2(VoxelBuffer::ALLOCATOR_DEFAULT);
buffer2.create(box.size);
Expand Down
2 changes: 1 addition & 1 deletion tests/voxel/test_voxel_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "../../util/noise/fast_noise_lite/fast_noise_lite.h"
#include "../../util/string/format.h"
#include "../../util/string/std_string.h"
#include "../testing.h"
#include "../../util/testing/test_macros.h"
#include "test_util.h"
#include <sstream>

Expand Down
Loading

0 comments on commit d424fdb

Please sign in to comment.