Skip to content

Commit 4f681eb

Browse files
committed
v5
1 parent 8fd28f2 commit 4f681eb

2 files changed

Lines changed: 95 additions & 66 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.10)
22

33
project(TUNIT
4-
VERSION 0.4.0
4+
VERSION 0.5.0
55
LANGUAGES CXX
66
DESCRIPTION "A C++ testing framework"
77
)

README.md

Lines changed: 94 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,110 @@
1-
# TUnit - Modern C++ Testing Framework
1+
# tUnit - Modern C++ Testing Framework
22

33
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
44
[![C++17](https://img.shields.io/badge/C%2B%2B-17-blue.svg)](https://en.cppreference.com/w/cpp/17)
5-
[![CMake](https://img.shields.io/badge/CMake-3.10%2B-blue.svg)](https://cmake.org/)
65

7-
TUnit is a lightweight, expressive C++ testing framework designed for clarity and powerful predicate-based testing. It combines modern C++ features with comprehensive testing capabilities including trace support and automatic test discovery.
6+
tUnit is a lightweight, expressive C++ testing framework designed for clarity and powerful predicate-based testing. It combines modern C++ features with comprehensive testing capabilities including trace support and automatic test discovery.
7+
8+
## Features
9+
### Core Testing Capabilities
10+
- **Single Header**: Use tUnit as a single header for easy integration—just include `tUnit.h` in your project
11+
- **Natural Language Testing**: Write tests that read like specifications with descriptive predicates
12+
- **Type-Safe Predicates**: Comprehensive library of composable, type-safe test predicates
13+
- **Flexible Test Organization**: Automatic test suite discovery and hierarchical organization
14+
- **Multiple Assertion Styles**: Both `assert` and `expect` methods for different testing needs
15+
- **Mixed Type Support**: Seamless testing across different data types (int, double, string, containers)
16+
17+
### Predicate Library
18+
- **Comparison Predicates**: `is_equal`, `is_greater`, `is_less`, `is_not_equal`, `is_greater_equal`, `is_less_equal`
19+
- **Numeric Predicates**: `is_even`, `is_odd`, `is_positive`, `is_negative`, `is_zero`
20+
- **String Predicates**: `contains_substring`, `starts_with`, `ends_with`
21+
- **Range Predicates**: `is_in_range`, `is_out_of_range`
22+
- **Container Predicates**: `is_empty`, `is_not_empty`, `has_size`, `contains_element`, `is_sorted`, `is_unique`
23+
- **Container Element Operations**: `contains_all_elements`, `contains_any_elements`, `all_elements_satisfy`, `any_element_satisfies`
24+
- **Custom Predicates**: `is_palindrome`, `is_prime`, `is_perfect_square`
25+
26+
### Logical Composition
27+
- **Basic Logic**: `and_`, `or_`, `not_`, `xor_`
28+
- **Advanced Logic**: `nand_`, `nor_`, `implies`
29+
- **Complex Combinations**: `all_of`, `any_of`, `none_of`
30+
- **Conditional Logic**: `conditional` predicates with if-then-else semantics
31+
- **Quantified Predicates**: `exactly_n_of`, `at_least_n_of`, `at_most_n_of`
32+
33+
### Testing Infrastructure
34+
- **Test Orchestration**: Centralized test management with automatic suite discovery
35+
- **Result Tracking**: Comprehensive assertion tracking and failure reporting
36+
- **XML Output**: JUnit-compatible XML test reports for CI/CD integration
37+
- **Command Line Interface**: Support for test filtering and output formatting
38+
- **Summary Reports**: Detailed pass/fail statistics with failure details
39+
40+
### Advanced Features
41+
- **Exception Tracing**: Detailed stack traces with scoped trace support using `TUNIT_TRACE_FUNCTION()` and `TUNIT_SCOPED_TRACE(msg)`
42+
- **Custom Evaluators**: Support for custom predicates and evaluation logic
43+
- **Container Algorithm Testing**: Integration with STL containers for argument-dependent lookup (ADL)
44+
- **Performance Testing**: Lightweight framework suitable for performance-critical testing
45+
- **Debug Support**: Enhanced debugging capabilities with trace information
46+
### (TODO)
47+
48+
- **Compile-Time Assertions**: `assert` statements are evaluated at compile time when possible, enabling static verification of predicates and values.
49+
- **Runtime Expectations**: `expect` statements are always evaluated at runtime, allowing for dynamic checks and flexible test flows.
850

9-
## Architecture Overview
10-
11-
TUnit consists of three core components working together:
51+
## Quick Start
1252

13-
### 1. Evaluator System
14-
The central evaluation engine that processes predicates against test values:
53+
Get started with TUnit in just a few lines:
1554
```cpp
16-
tUnit::Evaluator eval(10, 20, pred::is_less{});
17-
bool result = eval.evaluate();
18-
```
55+
#include "tUnit.h"
56+
// Define your tests inside an anonymous namespace
57+
namespace {
1958

20-
### 2. Predicate Library
21-
A comprehensive collection of type-safe, composable predicates organized into categories:
22-
- **Common**: Comparisons, strings, numeric operations, ranges
23-
- **Containers**: Element operations, size checks, sorting, uniqueness
24-
- **Logical**: AND, OR, NOT, XOR combinations
25-
- **Complex**: Multi-predicate compositions (all_of, any_of, conditional)
59+
namespace pred = tUnit::predicates;
60+
auto &suite = tUnit::Orchestrator::instance().get_suite("foo");
2661

27-
### 3. Test Runner
28-
Organizes tests into suites with automatic result tracking and reporting:
29-
```cpp
30-
auto& suite = tUnit::Runner::get_suite("Test Suite Name");
31-
suite.test("description", value1, predicate, value2);
32-
```
62+
void bar() {
63+
auto& suite = tUnit::Orchestrator::instance().get_suite("Basic Tests");
64+
auto& test = suite.get_test("Simple Assertions");
3365

34-
## Key Features
66+
// Basic assertions
67+
test.assert("equality check", 5, pred::is_equal{}, 5);
68+
test.expect("range validation", pred::is_in_range{}(7, 1, 10), true);
69+
}
70+
bar()
71+
}
3572

36-
### Natural Language Testing
37-
Tests read like specifications using descriptive predicates:
38-
```cpp
39-
suite.test("10 is greater than 5", 10, pred::is_greater{}, 5);
40-
suite.test("vector contains element", numbers, pred::contains_element{}, 3);
41-
suite.test("string is palindrome", pred::is_palindrome{}("racecar"));
73+
int main(int argc, char* argv[]) {
74+
// Test suites are automatically registered and executed
75+
tUnit::Orchestrator::instance().parse_args(argc, argv);
76+
tUnit::Orchestrator::instance().print_summary();
77+
tUnit::Orchestrator::instance().write_xml_output();
78+
return tUnit::Orchestrator::instance().all_tests_passed() ? 0 : 1;
79+
}
4280
```
4381
44-
### Predicate Composition
45-
Complex logic through predicate combinations:
82+
## Testing Patterns
83+
84+
TUnit supports multiple testing approaches:
85+
86+
**Assert Style** (predicate-based comparisons):
4687
```cpp
47-
auto complex_check = pred::all_of{pred::is_positive{}, pred::is_even{}};
48-
auto conditional_logic = pred::conditional{condition, then_pred, else_pred};
88+
test.assert("description", value1, predicate, value2);
4989
```
5090

51-
### Exception Tracing
52-
Debug mode provides detailed call stack traces:
91+
**Expect Style** (boolean expressions or single value checks):
5392
```cpp
54-
TUNIT_SCOPED_TRACE("Testing complex function");
55-
// Automatic file:line information in debug output
93+
test.expect("description", boolean_expression, expected_result);
94+
// Or, to check a single value is true:
95+
test.expect("description", value); // same function, expected default == true
5696
```
5797

58-
## Quick Start
59-
98+
**Container Testing**:
6099
```cpp
61-
#include "include/tsuite.h"
62-
namespace pred = tUnit::predicates;
63-
64-
int main() {
65-
auto& suite = tUnit::Runner::get_suite("Basic Tests");
66-
67-
suite.test("equality check", 5, pred::is_equal{}, 5);
68-
suite.test("range validation", pred::is_in_range{}(7, 1, 10));
69-
70-
return tUnit::Runner::all_tests_passed() ? 0 : 1;
71-
}
100+
std::vector<int> numbers = {1, 2, 3, 4, 5};
101+
test.assert("contains element", numbers, pred::contains_element{}, 3);
102+
test.expect("all positive", pred::all_elements_satisfy{}(numbers, pred::is_positive{}), true);
72103
```
73104
74-
## Predicate Categories
75-
76-
| Category | Examples | Purpose |
77-
|----------|----------|---------|
78-
| **Common** | `is_equal`, `is_greater`, `contains_substring` | Basic comparisons and operations |
79-
| **Containers** | `is_empty`, `has_size`, `is_sorted` | Container state and element operations |
80-
| **Logical** | `and_`, `or_`, `not_`, `xor_` | Combining multiple predicates |
81-
| **Complex** | `all_of`, `any_of`, `conditional` | Advanced multi-predicate logic |
82-
83105
## Build Integration
84106
85-
### CMake
107+
### CMake Integration
86108
```cmake
87109
add_subdirectory(tunit)
88110
target_link_libraries(your_target tunit)
@@ -95,11 +117,18 @@ make test # Run all tests
95117
make clean # Clean build artifacts
96118
```
97119

98-
## Technical Requirements
120+
### Example Test Output
121+
```
122+
=== Test Summary ===
123+
Total assertions: 152
124+
Passed: 151
125+
Failed: 1
126+
===================
127+
```
128+
129+
## Requirements
99130

100-
- C++17 or later
101-
- CMake 3.10+
102-
- GCC 7+, Clang 6+, or MSVC 2017+
131+
- **C++17 or later**: Modern C++ features for type safety and performance
103132

104133
## License
105134
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)