Skip to content

Commit 6796528

Browse files
committed
Nicer test output
1 parent 8f9e7c3 commit 6796528

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

include/test/Testing.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,18 @@ namespace Game3 {
2323
bool report(std::string_view, bool passed);
2424

2525
template <typename T, typename U>
26-
bool expectEqual(T &&actual, U &&expected) {
27-
std::string name = std::format("actual \"{}\" == expected \"{}\"", actual, expected);
26+
bool expectEqual(const T &actual, const U &expected) {
27+
if (actual == expected) {
28+
pass(std::format("expect \"{}\"", expected));
29+
return true;
30+
} else {
31+
fail(std::format("expect actual \"{}\" == expected \"{}\"", actual, expected));
32+
return false;
33+
}
34+
}
35+
36+
template <typename T, typename U>
37+
bool expectEqual(std::string_view name, T &&actual, U &&expected) {
2838
return report(name, std::forward<T>(actual) == std::forward<U>(expected));
2939
}
3040

src/test/Testing.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ namespace Game3 {
5555
if (good == 0 && bad == 0) {
5656
WARN("No tests were run.");
5757
} else if (good > 0 && bad == 0) {
58-
SUCCESS("Summary: passed {} {}.", good, plural(good));
58+
if (good == 1) {
59+
SUCCESS("Summary: passed 1 test.");
60+
} else {
61+
SUCCESS("Summary: passed all {} tests.", good);
62+
}
5963
} else if (bad > 0 && good == 0) {
60-
ERR("Summary: failed \e[31m{}\e[39m {}.", bad, plural(bad));
64+
if (bad == 1) {
65+
ERR("Summary: failed \e[31m1\e[39m test.");
66+
} else {
67+
ERR("Summary: failed all \e[31m{}\e[39m tests.", bad);
68+
}
6169
} else {
6270
WARN("Summary: passed \e[32m{}\e[39m {} and failed \e[31m{}\e[39m {}.", good, plural(good), bad, plural(bad));
6371
}

src/test/UString.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ namespace Game3 {
5353
{
5454
UString string = "Gangblanc, Gangblanc, give me your answer, do\nI'm half forswonk all for the code of you\nIt won't be a stylish shader\nI can't code up a trader\nBut you'll look cool without the tools\nOf a game engine built for three";
5555
UString wrapped = string.wrap(renderer, 538, 0.5);
56-
context.expectEqual(wrapped, "Gangblanc, Gangblanc, \ngive me your answer, \ndo\nI'm half forswonk all \nfor the code of you\nIt won't be a stylish \nshader\nI can't code up a tra-\nder\nBut you'll look cool \nwithout the tools\nOf a game engine bu-\nilt for three");
56+
context.expectEqual("word wrapping", wrapped, "Gangblanc, Gangblanc, \ngive me your answer, \ndo\nI'm half forswonk all \nfor the code of you\nIt won't be a stylish \nshader\nI can't code up a tra-\nder\nBut you'll look cool \nwithout the tools\nOf a game engine bu-\nilt for three");
5757
}
5858

5959
{
6060
UString string = "\n\nGangblanc, Gangblanc, give me your answer, do\nI'm half forswonk all for the code of you\nIt won't be a stylish shader\nI can't code up a trader\nBut you'll look cool without the tools\nOf a game engine built for three\n \n";
6161
UString wrapped = string.wrap(renderer, 538, 0.5);
62-
context.expectEqual(wrapped, "\n\nGangblanc, Gangblanc, \ngive me your answer, \ndo\nI'm half forswonk all \nfor the code of you\nIt won't be a stylish \nshader\nI can't code up a tra-\nder\nBut you'll look cool \nwithout the tools\nOf a game engine bu-\nilt for three\n \n");
62+
context.expectEqual("word wrapping with extra newlines", wrapped, "\n\nGangblanc, Gangblanc, \ngive me your answer, \ndo\nI'm half forswonk all \nfor the code of you\nIt won't be a stylish \nshader\nI can't code up a tra-\nder\nBut you'll look cool \nwithout the tools\nOf a game engine bu-\nilt for three\n \n");
6363
}
6464
}
6565
};

0 commit comments

Comments
 (0)