Skip to content

Commit bf01fbe

Browse files
committed
Verbose mode
1 parent 0c4bc0a commit bf01fbe

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ make: *** [Makefile:84: test] Error 8
175175
- `UTEST_ALLOW_EMPTY_TESTS()` - Allow test runner to succeed even when no tests are run
176176
- `UTEST_USE_ASCII_CHECKMARKS()` - Use ASCII [OK]/[FAIL] instead of Unicode ✓/✗
177177
- `UTEST_SHOW_PERFORMANCE()` - Enable performance timing for each test
178+
- `UTEST_ENABLE_VERBOSE_MODE()` - Show test names before execution (useful for debugging)
178179

179180
### Function Definition Macros
180181
- `UTEST_FUNC_DEF(name)` - Define a test function: `void test_name()`
@@ -273,6 +274,28 @@ Output will show timing information:
273274
✓ Test [my_test] succeeded (1.234ms)
274275
```
275276

277+
### Verbose Mode
278+
Enable verbose mode to see test names before execution:
279+
280+
```cpp
281+
UTEST_PROLOG();
282+
UTEST_ENABLE_VERBOSE_MODE(); // Show test names before execution
283+
UTEST_FUNC(my_test);
284+
UTEST_EPILOG();
285+
```
286+
287+
Output will show test names before execution:
288+
```
289+
Running test: my_test
290+
✓ Test [my_test] succeeded (1.234ms)
291+
```
292+
293+
For grouped tests:
294+
```
295+
Running test: GroupName::TestName
296+
✓ Test [GroupName::TestName] succeeded (1.234ms)
297+
```
298+
276299
### ASCII Checkmarks
277300
For environments that don't support Unicode characters:
278301

demo/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,19 @@ target_include_directories(demo_unicode_checkmarks PRIVATE ${CMAKE_CURRENT_SOURC
5757

5858
set_target_properties(demo_unicode_checkmarks PROPERTIES
5959
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
60+
)
61+
62+
# Demo for verbose mode
63+
add_executable(demo_verbose_mode
64+
demo_verbose_mode.cpp
65+
)
66+
67+
target_link_libraries(demo_verbose_mode
68+
PRIVATE utest
69+
)
70+
71+
target_include_directories(demo_verbose_mode PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
72+
73+
set_target_properties(demo_verbose_mode PROPERTIES
74+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
6075
)

demo/demo_verbose_mode.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Demo showcasing verbose mode in utest library
2+
#include "utest.h"
3+
#include <string>
4+
5+
UTEST_FUNC_DEF(VerboseBasicTest) {
6+
UTEST_ASSERT_TRUE(true);
7+
UTEST_ASSERT_EQUALS(2 + 2, 4);
8+
UTEST_ASSERT_STR_EQUALS("hello", "hello");
9+
}
10+
11+
UTEST_FUNC_DEF2(VerboseDemo, PassingTest) {
12+
std::string greeting = "Hello, World!";
13+
UTEST_ASSERT_EQUALS(greeting.length(), 13);
14+
UTEST_ASSERT_GT(greeting.find("World"), 0);
15+
}
16+
17+
UTEST_FUNC_DEF2(VerboseDemo, AnotherPassingTest) {
18+
int numbers[] = {1, 2, 3, 4, 5};
19+
UTEST_ASSERT_EQUALS(numbers[0], 1);
20+
UTEST_ASSERT_EQUALS(numbers[4], 5);
21+
}
22+
23+
UTEST_FUNC_DEF2(VerboseDemo, MathTest) {
24+
UTEST_ASSERT_LT(3.14, 4.0);
25+
UTEST_ASSERT_GTE(10, 10);
26+
UTEST_ASSERT_NEQ(1, 2);
27+
}
28+
29+
int main() {
30+
UTEST_PROLOG();
31+
32+
// Enable verbose mode for prettier output
33+
UTEST_ENABLE_VERBOSE_MODE();
34+
35+
// Enable Unicode checkmarks for prettier output
36+
UTEST_USE_UNICODE_CHECKMARKS();
37+
38+
// Keep performance timing enabled (default)
39+
UTEST_SHOW_PERFORMANCE();
40+
41+
std::cout << "=== Verbose Mode Demo ===\n";
42+
std::cout << "This demo shows test names before execution\n\n";
43+
44+
UTEST_FUNC(VerboseBasicTest);
45+
UTEST_FUNC2(VerboseDemo, PassingTest);
46+
UTEST_FUNC2(VerboseDemo, AnotherPassingTest);
47+
UTEST_FUNC2(VerboseDemo, MathTest);
48+
49+
UTEST_EPILOG();
50+
}

include/utest.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
* The library can be configured using these macros in your test main():
6363
* - UTEST_USE_ASCII_CHECKMARKS() - Use [OK]/[FAIL] instead of checkmarks
6464
* - UTEST_SHOW_PERFORMANCE() - Show timing information for each test
65+
* - UTEST_ENABLE_VERBOSE_MODE() - Show test names before execution
6566
* - UTEST_ALLOW_EMPTY_TESTS() - Don't fail if no tests are run
6667
*
6768
* By default, ASCII checkmarks and performance timing are enabled for
@@ -685,6 +686,12 @@ namespace details {
685686
static bool showPerf = true; // Default to showing performance info
686687
return showPerf;
687688
}
689+
690+
// Configuration for verbose mode (showing test names before execution)
691+
inline bool& getVerboseMode() {
692+
static bool verbose = false; // Default to non-verbose
693+
return verbose;
694+
}
688695

689696
template<typename Func>
690697
void testFunc(const char *name, Func f, bool &failed) {
@@ -698,6 +705,11 @@ namespace details {
698705
const char* successMark = getUseAsciiCheckmarks() ? "[OK]" : "";
699706
const char* failMark = getUseAsciiCheckmarks() ? "[FAIL]" : "";
700707

708+
// Show test name before execution if verbose mode is enabled
709+
if (getVerboseMode()) {
710+
std::cout << "Running test: " << std::string(name) << "\n";
711+
}
712+
701713
auto start = std::chrono::high_resolution_clock::now();
702714

703715
try {
@@ -757,6 +769,11 @@ namespace details {
757769
const char* successMark = getUseAsciiCheckmarks() ? "[OK]" : "";
758770
const char* failMark = getUseAsciiCheckmarks() ? "[FAIL]" : "";
759771

772+
// Show test name before execution if verbose mode is enabled
773+
if (getVerboseMode()) {
774+
std::cout << "Running test: " << std::string(group) << "::" << std::string(name) << "\n";
775+
}
776+
760777
auto start = std::chrono::high_resolution_clock::now();
761778

762779
try {
@@ -996,6 +1013,23 @@ namespace details {
9961013
*/
9971014
#define UTEST_HIDE_PERFORMANCE() utest::details::getShowPerformanceInfo() = false
9981015

1016+
/**
1017+
* @brief Enable verbose mode to show test names before execution
1018+
*
1019+
* Shows the name of each test before it runs, useful for debugging
1020+
* and understanding test execution flow.
1021+
*
1022+
* @code{.cpp}
1023+
* int main() {
1024+
* UTEST_PROLOG();
1025+
* UTEST_ENABLE_VERBOSE_MODE(); // Show test names before execution
1026+
* // ... run tests ...
1027+
* UTEST_EPILOG();
1028+
* }
1029+
* @endcode
1030+
*/
1031+
#define UTEST_ENABLE_VERBOSE_MODE() utest::details::getVerboseMode() = true
1032+
9991033
/** @} */ // end of test_execution group
10001034

10011035
/**

0 commit comments

Comments
 (0)