Skip to content

Commit d424fdb

Browse files
committed
Add test runner
- 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
1 parent e6ccda3 commit d424fdb

38 files changed

+201
-74
lines changed

common.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ def get_sources(env, is_editor_build, include_tests):
147147
sources += [
148148
"tests/*.cpp",
149149
"tests/util/*.cpp",
150-
"tests/voxel/*.cpp"
150+
"tests/voxel/*.cpp",
151+
152+
"util/testing/*.cpp"
151153
]
152154

153155
def process_glob_paths(p_sources):

engine/voxel_engine_gd.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#ifdef VOXEL_TESTS
1414
#include "../tests/tests.h"
15+
#include "../util/testing/test_options.h"
1516
#endif
1617

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

189190
#ifdef VOXEL_TESTS
190191

191-
void VoxelEngine::run_tests() {
192-
zylann::voxel::tests::run_voxel_tests();
192+
void VoxelEngine::run_tests(Dictionary options_dict) {
193+
zylann::testing::TestOptions options(options_dict);
194+
zylann::voxel::tests::run_voxel_tests(options);
193195
}
194196

195197
#endif
@@ -217,7 +219,7 @@ void VoxelEngine::_bind_methods() {
217219
);
218220

219221
#ifdef VOXEL_TESTS
220-
ClassDB::bind_method(D_METHOD("run_tests"), &VoxelEngine::run_tests);
222+
ClassDB::bind_method(D_METHOD("run_tests", "options"), &VoxelEngine::run_tests);
221223
#endif
222224

223225
// ClassDB::bind_method(

engine/voxel_engine_gd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class VoxelEngine : public Object {
4141
#endif
4242

4343
#ifdef VOXEL_TESTS
44-
void run_tests();
44+
void run_tests(Dictionary options_dict);
4545
#endif
4646

4747
private:

project/tests/runner.gd

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extends Node
2+
3+
func _ready() -> void:
4+
if VoxelEngine.has_method("run_tests"):
5+
VoxelEngine.call_deferred("run_tests")
6+
else:
7+
push_error("Tests not available")

project/tests/runner.gd.uid

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://c757lvb02hpah

project/tests/runner.tscn

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://by5xtqdgr0r13"]
2+
3+
[ext_resource type="Script" uid="uid://c757lvb02hpah" path="res://tests/runner.gd" id="1_p0saw"]
4+
5+
[node name="Node" type="Node"]
6+
script = ExtResource("1_p0saw")

register_types.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152

153153
#ifdef VOXEL_TESTS
154154
#include "tests/tests.h"
155+
#include "util/testing/test_options.h"
155156
#endif
156157

157158
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -367,7 +368,7 @@ void initialize_voxel_module(ModuleInitializationLevel p_level) {
367368
for (int i = 0; i < command_line_arguments.size(); ++i) {
368369
const String arg = command_line_arguments[i];
369370
if (arg == tests_cmd) {
370-
zylann::voxel::tests::run_voxel_tests();
371+
zylann::voxel::tests::run_voxel_tests(zylann::testing::TestOptions());
371372
break;
372373
}
373374
}

tests/tests.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "tests.h"
22
#include "../util/profiling.h"
3-
#include "testing.h"
3+
#include "../util/testing/test_options.h"
44

55
#include "util/test_box3i.h"
66
#include "util/test_container_funcs.h"
@@ -37,13 +37,12 @@
3737
namespace zylann::voxel::tests {
3838

3939
#define VOXEL_TEST(fname) \
40-
{ \
41-
print_line("Running " #fname); \
40+
if (options.can_run_print(#fname)) { \
4241
ZN_PROFILE_SCOPE_NAMED(#fname); \
4342
fname(); \
4443
}
4544

46-
void run_voxel_tests() {
45+
void run_voxel_tests(const testing::TestOptions &options) {
4746
print_line("------------ Voxel tests begin -------------");
4847

4948
using namespace zylann::tests;

tests/tests.h

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
#ifndef VOXEL_TESTS_H
22
#define VOXEL_TESTS_H
33

4-
namespace zylann::voxel::tests {
5-
void run_voxel_tests();
6-
} // namespace zylann::voxel::tests
4+
#include "../util/godot/macros.h"
75

8-
namespace zylann::voxel::noise_tests {
6+
namespace zylann {
7+
8+
namespace testing {
9+
class TestOptions;
10+
}
11+
12+
namespace voxel {
13+
14+
namespace tests {
15+
void run_voxel_tests(const testing::TestOptions &options);
16+
}
17+
18+
namespace noise_tests {
919
void run_noise_tests();
10-
} // namespace zylann::voxel::noise_tests
20+
}
21+
22+
} // namespace voxel
23+
} // namespace zylann
1124

1225
#endif // VOXEL_TESTS_H

tests/util/test_box3i.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "test_box3i.h"
22
#include "../../util/containers/std_unordered_map.h"
33
#include "../../util/math/box3i.h"
4-
#include "../testing.h"
4+
#include "../../util/testing/test_macros.h"
55

66
namespace zylann::tests {
77

tests/util/test_container_funcs.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "test_container_funcs.h"
22
#include "../../util/containers/container_funcs.h"
33
#include "../../util/containers/std_vector.h"
4-
#include "../testing.h"
4+
#include "../../util/testing/test_macros.h"
55

66
namespace zylann::tests {
77

@@ -29,7 +29,8 @@ void test_unordered_remove_if() {
2929

3030
ZN_TEST_ASSERT(vec.size() == 3);
3131
ZN_TEST_ASSERT(
32-
L::count(vec, 0) == 0 && L::count(vec, 1) == 1 && L::count(vec, 2) == 1 && L::count(vec, 3) == 1);
32+
L::count(vec, 0) == 0 && L::count(vec, 1) == 1 && L::count(vec, 2) == 1 && L::count(vec, 3) == 1
33+
);
3334
}
3435
// Remove one in middle
3536
{
@@ -43,7 +44,8 @@ void test_unordered_remove_if() {
4344

4445
ZN_TEST_ASSERT(vec.size() == 3);
4546
ZN_TEST_ASSERT(
46-
L::count(vec, 0) == 1 && L::count(vec, 1) == 1 && L::count(vec, 2) == 0 && L::count(vec, 3) == 1);
47+
L::count(vec, 0) == 1 && L::count(vec, 1) == 1 && L::count(vec, 2) == 0 && L::count(vec, 3) == 1
48+
);
4749
}
4850
// Remove one at end
4951
{
@@ -57,7 +59,8 @@ void test_unordered_remove_if() {
5759

5860
ZN_TEST_ASSERT(vec.size() == 3);
5961
ZN_TEST_ASSERT(
60-
L::count(vec, 0) == 1 && L::count(vec, 1) == 1 && L::count(vec, 2) == 1 && L::count(vec, 3) == 0);
62+
L::count(vec, 0) == 1 && L::count(vec, 1) == 1 && L::count(vec, 2) == 1 && L::count(vec, 3) == 0
63+
);
6164
}
6265
// Remove multiple
6366
{
@@ -71,7 +74,8 @@ void test_unordered_remove_if() {
7174

7275
ZN_TEST_ASSERT(vec.size() == 2);
7376
ZN_TEST_ASSERT(
74-
L::count(vec, 0) == 1 && L::count(vec, 1) == 0 && L::count(vec, 2) == 0 && L::count(vec, 3) == 1);
77+
L::count(vec, 0) == 1 && L::count(vec, 1) == 0 && L::count(vec, 2) == 0 && L::count(vec, 3) == 1
78+
);
7579
}
7680
// Remove last
7781
{

tests/util/test_expression_parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "test_expression_parser.h"
22
#include "../../util/math/funcs.h"
33
#include "../../util/string/expression_parser.h"
4-
#include "../testing.h"
4+
#include "../../util/testing/test_macros.h"
55

66
namespace zylann::tests {
77

tests/util/test_flat_map.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "../../util/containers/flat_map.h"
33
#include "../../util/containers/std_vector.h"
44
#include "../../util/godot/core/random_pcg.h"
5-
#include "../testing.h"
5+
#include "../../util/testing/test_macros.h"
66

77
namespace zylann::tests {
88

tests/util/test_island_finder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "test_island_finder.h"
22
#include "../../util/containers/std_vector.h"
33
#include "../../util/island_finder.h"
4-
#include "../testing.h"
4+
#include "../../util/testing/test_macros.h"
55

66
namespace zylann::tests {
77

tests/util/test_math_funcs.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "test_math_funcs.h"
22
#include "../../util/math/funcs.h"
3-
#include "../testing.h"
3+
#include "../../util/testing/test_macros.h"
44

55
namespace zylann::tests {
66

tests/util/test_noise.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "test_noise.h"
22
#include "../../util/noise/fast_noise_lite/fast_noise_lite.h"
33
#include "../../util/noise/fast_noise_lite/fast_noise_lite_range.h"
4-
#include "../testing.h"
4+
#include "../../util/testing/test_macros.h"
55

66
namespace zylann::tests {
77

tests/util/test_slot_map.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "test_slot_map.h"
22
#include "../../util/containers/slot_map.h"
3-
#include "../testing.h"
3+
#include "../../util/testing/test_macros.h"
44

55
namespace zylann::tests {
66

tests/util/test_spatial_lock.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include "../../util/profiling.h"
77
#include "../../util/string/format.h"
88
#include "../../util/tasks/threaded_task_runner.h"
9+
#include "../../util/testing/test_macros.h"
910
#include "../../util/thread/spatial_lock_3d.h"
10-
#include "../testing.h"
1111

1212
// #define VOXEL_TEST_TASK_POSTPONING_DUMP_EVENTS
1313
#ifdef VOXEL_TEST_TASK_POSTPONING_DUMP_EVENTS

tests/util/test_threaded_task_runner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "../../util/string/format.h"
1111
#include "../../util/string/std_stringstream.h"
1212
#include "../../util/tasks/threaded_task_runner.h"
13-
#include "../testing.h"
13+
#include "../../util/testing/test_macros.h"
1414

1515
// #define VOXEL_TEST_TASK_POSTPONING_DUMP_EVENTS
1616
#ifdef VOXEL_TEST_TASK_POSTPONING_DUMP_EVENTS

tests/voxel/test_block_serializer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "../../streams/voxel_block_serializer.h"
44
#include "../../streams/voxel_block_serializer_gd.h"
55
#include "../../util/godot/classes/stream_peer_buffer.h"
6-
#include "../testing.h"
6+
#include "../../util/testing/test_macros.h"
77

88
namespace zylann::voxel::tests {
99

tests/voxel/test_curve_range.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "../../generators/graph/range_utility.h"
33
#include "../../util/containers/std_vector.h"
44
#include "../../util/godot/classes/curve.h"
5-
#include "../testing.h"
5+
#include "../../util/testing/test_macros.h"
66

77
namespace zylann::voxel::tests {
88

tests/voxel/test_detail_rendering_gpu.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "../../meshers/transvoxel/transvoxel_cell_iterator.h"
88
#include "../../meshers/transvoxel/voxel_mesher_transvoxel.h"
99
#include "../../util/godot/classes/time.h"
10-
#include "../testing.h"
10+
#include "../../util/testing/test_macros.h"
1111

1212
namespace zylann::voxel::tests {
1313

tests/voxel/test_edition_funcs.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "../../meshers/blocky/voxel_blocky_model_mesh.h"
88
#include "../../storage/voxel_data.h"
99
#include "../../util/godot/classes/image.h"
10-
#include "../testing.h"
10+
#include "../../util/testing/test_macros.h"
1111
#include "test_util.h"
1212

1313
namespace zylann::voxel::tests {

tests/voxel/test_octree.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "../../util/containers/std_unordered_set.h"
77
#include "../../util/math/conv.h"
88
#include "../../util/profiling_clock.h"
9-
#include "../testing.h"
9+
#include "../../util/testing/test_macros.h"
1010

1111
#include <core/string/print_string.h>
1212

tests/voxel/test_raycast.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "../../meshers/blocky/voxel_blocky_model_empty.h"
66
#include "../../meshers/blocky/voxel_mesher_blocky.h"
77
#include "../../storage/voxel_data.h"
8-
#include "../testing.h"
8+
#include "../../util/testing/test_macros.h"
99

1010
namespace zylann::voxel::tests {
1111

tests/voxel/test_region_file.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include "../../streams/region/voxel_stream_region_files.h"
44
#include "../../util/containers/std_unordered_map.h"
55
#include "../../util/godot/core/random_pcg.h"
6-
#include "../testing.h"
6+
#include "../../util/testing/test_directory.h"
7+
#include "../../util/testing/test_macros.h"
78

89
namespace zylann::voxel::tests {
910

tests/voxel/test_storage_funcs.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "../../storage/funcs.h"
33
#include "../../storage/materials_4i4w.h"
44
#include "../../util/containers/std_vector.h"
5-
#include "../testing.h"
5+
#include "../../util/testing/test_macros.h"
66

77
namespace zylann::voxel::tests {
88

tests/voxel/test_stream_sqlite.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include "../../util/profiling.h"
99
#include "../../util/profiling_clock.h"
1010
#include "../../util/string/format.h"
11-
#include "../testing.h"
11+
#include "../../util/testing/test_directory.h"
12+
#include "../../util/testing/test_macros.h"
1213

1314
namespace zylann::voxel::tests {
1415

tests/voxel/test_voxel_buffer.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
#include "../../storage/metadata/voxel_metadata_variant.h"
44
#include "../../storage/voxel_buffer_gd.h"
55
#include "../../streams/voxel_block_serializer.h"
6+
#include "../../util/io/log.h"
7+
#include "../../util/string/std_string.h"
68
#include "../../util/string/std_stringstream.h"
7-
#include "../testing.h"
9+
#include "../../util/testing/test_macros.h"
810
#include <sstream>
911

1012
namespace zylann::voxel::tests {

tests/voxel/test_voxel_data_map.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "test_voxel_data_map.h"
22
#include "../../storage/voxel_buffer.h"
33
#include "../../storage/voxel_data_map.h"
4-
#include "../testing.h"
4+
#include "../../util/testing/test_macros.h"
55

66
namespace zylann::voxel::tests {
77

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

6666
map.paste_masked(
67-
box.position, buffer, (1 << channel), true, channel, masked_value, false, 0, Span<const int32_t>(), true);
67+
box.position, buffer, (1 << channel), true, channel, masked_value, false, 0, Span<const int32_t>(), true
68+
);
6869

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

139140
map.paste_masked(
140-
box.position, buffer, (1 << channel), true, channel, default_value, false, 0, Span<const int32_t>(), true);
141+
box.position, buffer, (1 << channel), true, channel, default_value, false, 0, Span<const int32_t>(), true
142+
);
141143

142144
VoxelBuffer buffer2(VoxelBuffer::ALLOCATOR_DEFAULT);
143145
buffer2.create(box.size);

tests/voxel/test_voxel_graph.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "../../util/noise/fast_noise_lite/fast_noise_lite.h"
1616
#include "../../util/string/format.h"
1717
#include "../../util/string/std_string.h"
18-
#include "../testing.h"
18+
#include "../../util/testing/test_macros.h"
1919
#include "test_util.h"
2020
#include <sstream>
2121

0 commit comments

Comments
 (0)