Skip to content

Commit 451fb2c

Browse files
committed
added tui + disabled constexpr
1 parent 4f681eb commit 451fb2c

5 files changed

Lines changed: 78 additions & 39 deletions

File tree

include/predicates/predicate_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define TUNIT_MODE 1
1212
#endif
1313

14-
#if TUNIT_MODE
14+
#if 0 // TUNIT_MODE
1515
#define TUNIT_CONSTEXPR constexpr
1616
#define TUNIT_TRACE_PREDICATE(name) ((void)0)
1717
#else

include/tUnit.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
/**
2-
* @file tUnit.h
3-
* @brief Single-header include for the complete tUnit testing framework.
4-
*
5-
* This header aggregates all core components of the tUnit testing framework:
6-
* - Predicates: predicates/all_predicates.h
7-
* - Assertions: tUnit/assertion.h
8-
* - Test cases: tUnit/test_case.h
9-
* - Test orchestrator: tUnit/test_orchestrator.h
10-
* - Test suites: tUnit/test_suite.h
11-
* - release asserts: utils/release_asserts.h
12-
* - Trace utilities: utils/trace_support.h
13-
* - Core evaluator: evaluator.h
2+
* Single-header include for the complete tUnit testing framework.
3+
* Predicates: predicates/all_predicates.h
4+
* Assertions: tUnit/assertion.h
5+
* Test cases: tUnit/test_case.h
6+
* Test orchestrator: tUnit/test_orchestrator.h
7+
* Test suites: tUnit/test_suite.h
8+
* Release asserts: utils/release_asserts.h
9+
* Trace utilities: utils/trace_support.h
10+
* Evaluator: evaluator.h
1411
*/
1512
#pragma once
1613

include/utils/trace_support.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ namespace tUnit
1616
namespace trace
1717
{
1818

19-
#define TUNIT_SCOPED_TRACE(message) \
20-
tUnit::trace::ScopedTrace _scoped_trace_##__LINE__(__FILE__, __LINE__, (message))
19+
#define TUNIT_SCOPED_TRACE(msg) \
20+
tUnit::trace::ScopedTrace _scoped_trace_##__LINE__(__FILE__, __LINE__, (msg))
2121

2222
#define TUNIT_TRACE_FUNCTION() TUNIT_SCOPED_TRACE(__func__)
2323

2424
struct TraceInfo
2525
{
26-
std::string file;
27-
std::int32_t line;
28-
std::string message;
26+
std::string file_;
27+
std::int32_t line_;
28+
std::string msg_;
2929

30-
TraceInfo(const std::string &file_path, std::int32_t line_num, const std::string &msg) : file(file_path), line(line_num), message(msg) {}
30+
TraceInfo(const std::string &file, std::int32_t line, const std::string &msg) : file_(file), line_(line), msg_(msg) {}
3131

3232
std::string to_string() const
3333
{
3434
std::ostringstream oss;
35-
if (!file.empty())
35+
if (!file_.empty())
3636
{
37-
oss << file << ":" << line << ": " << message;
37+
oss << file_ << ":" << line_ << ": " << msg_;
3838
}
3939
else
4040
{
41-
oss << message;
41+
oss << msg_;
4242
}
4343
return oss.str();
4444
}

src/tUnit/test_orchestrator.cpp

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,71 @@ void Orchestrator::print_summary() const
130130
size_t failed = failed_assertions();
131131
size_t passed = total - failed;
132132

133-
std::cout << "\n=== Test Summary ===" << "\n";
134-
std::cout << "Total assertions: " << total << "\n";
135-
std::cout << "Passed: " << passed << "\n";
136-
std::cout << "Failed: " << failed << "\n";
133+
std::cout << "\n";
137134

138-
if (failed > 0)
135+
// Group tests by suite
136+
std::unordered_map<std::string, std::vector<std::pair<std::string, const Test *>>> suites_map;
137+
for (const auto &[test_key, test] : tests_)
138+
{
139+
suites_map[test->suite_name()].emplace_back(test->name(), test.get());
140+
}
141+
142+
for (const auto &[suite_name, suite_tests] : suites_map)
139143
{
140-
std::cout << "===================" << "\n";
141-
std::cout << "Failed assertions:" << "\n";
142-
for (const auto &[test_key, assertions] : assertions_)
144+
std::cout << "--- " << suite_name << " ---\n";
145+
146+
for (const auto &[test_name, test] : suite_tests)
143147
{
144-
for (const auto &assertion : assertions)
148+
std::string test_key = test->suite_name() + "::" + test->name();
149+
auto assertions_it = assertions_.find(test_key);
150+
151+
bool test_has_failures = false;
152+
std::vector<std::string> failed_descriptions;
153+
154+
if (assertions_it != assertions_.end())
145155
{
146-
if (!assertion.result_)
156+
const auto &assertions = assertions_it->second;
157+
for (const auto &assertion : assertions)
147158
{
148-
std::cout << " [" << test_key << "] " << assertion.description_ << "\n";
159+
if (!assertion.result_)
160+
{
161+
test_has_failures = true;
162+
failed_descriptions.push_back(assertion.description_);
163+
}
149164
}
150165
}
166+
167+
if (test_has_failures)
168+
{
169+
std::cout << "[FAIL] " << test_name << "\n";
170+
for (const auto &desc : failed_descriptions)
171+
{
172+
std::cout << " " << desc << "\n";
173+
}
174+
}
175+
else
176+
{
177+
std::cout << "[PASS] " << test_name << "\n";
178+
}
151179
}
180+
std::cout << "\n";
181+
}
182+
183+
std::cout << "--- Total Summary ---\n";
184+
std::cout << "Total assertions: " << total << "\n";
185+
std::cout << "Passed: " << passed << "\n";
186+
std::cout << "Failed: " << failed << "\n";
187+
188+
if (failed == 0)
189+
{
190+
std::cout << "All tests passed!\n";
191+
}
192+
else
193+
{
194+
std::cout << failed << " assertion(s) failed\n";
152195
}
153196

154-
std::cout << "===================" << std::endl;
197+
std::cout << "====================\n" << std::endl;
155198
}
156199

157200
void Orchestrator::parse_args(int argc, char *argv[])
@@ -172,9 +215,10 @@ void Orchestrator::parse_args(int argc, char *argv[])
172215

173216
void Orchestrator::write_xml_output() const
174217
{
218+
// No XML output requested
175219
if (xml_output_path_.empty())
176220
{
177-
return; // No XML output requested
221+
return;
178222
}
179223

180224
std::ofstream xml_file(xml_output_path_);

tests/main.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
int main(int argc, char *argv[])
44
{
5-
// Run all test suites
6-
5+
// All test suites self register
76
tUnit::Orchestrator::instance().parse_args(argc, argv);
8-
tUnit::Orchestrator::instance().print_summary();
97
tUnit::Orchestrator::instance().write_xml_output();
10-
8+
tUnit::Orchestrator::instance().print_summary();
119
return tUnit::Orchestrator::instance().all_tests_passed() ? 0 : 1;
1210
}

0 commit comments

Comments
 (0)