-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_tests.py
50 lines (42 loc) · 1.53 KB
/
_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def setup_tests(lib_name, needs_imgui: bool):
from _utils import make_file
from os.path import join
make_file(
join("tests", "tests.cpp"),
f"""#define {"DOCTEST_CONFIG_IMPLEMENT" if needs_imgui else "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"}
#include "doctest/doctest.h"
#include "{lib_name}/{lib_name}.hpp"
{f'''#include "quick_imgui/quick_imgui.hpp"
// Learn how to use Dear ImGui: https://coollibs.github.io/contribute/Programming/dear-imgui
auto main(int argc, char* argv[]) -> int
{{
int const exit_code = doctest::Context{{}}.run(); // Run all unit tests
bool const should_run_imgui_tests = argc < 2 || strcmp(argv[1], "-nogpu") != 0; // NOLINT(*pointer-arithmetic)
if (!should_run_imgui_tests
|| exit_code != 0 // Only open the window if the tests passed; this makes it easier to notice when some tests fail
)
{{
return exit_code;
}}
quick_imgui::loop("{lib_name} tests", [&]() {{ // Open a window and run all the ImGui-related code
ImGui::Begin("{lib_name} tests");
ImGui::End();
ImGui::ShowDemoWindow();
}});
return 0;
}}
''' if needs_imgui else ""}
// Check out doctest's documentation: https://github.com/doctest/doctest/blob/master/doc/markdown/tutorial.md
int factorial(int number)
{{
return number <= 1 ? number : factorial(number - 1) * number;
}}
TEST_CASE("testing the factorial function")
{{
CHECK(factorial(1) == 1);
CHECK(factorial(2) == 2);
CHECK(factorial(3) == 6);
CHECK(factorial(10) == 3628800);
}}
""",
)