Skip to content

Commit f9bbe50

Browse files
authored
Merge branch 'main' into numbers
2 parents 9501670 + dc535c4 commit f9bbe50

9 files changed

Lines changed: 485 additions & 157 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ compile_commands.json
1010
notes.txt
1111
*.exe
1212
.cache
13+
.clang-format

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Quick description, and links to the documentation of all the libraries of the pr
1414
- [Text](./zero/ifc/text/README.md) - Offers utilities for text manipulation, string splitting, formatting, styling, and print to console functionalities.
1515
- [Types](./zero/ifc/types/README.md) - Information about types and traits for types
1616
- [Math](./zero/ifc/math/README.md) - Mathematical operations and functions
17+
- [Test Suite](./zero/ifc/test-suite/README.md) - A flexible and simple test-suite.
1718

1819
## Sponsorship
1920

@@ -48,16 +49,6 @@ system in a real world environment, so people can profit by taking examples of h
4849
in a big scale project. Also, we introduce the changes of the latest releases available here, so it serves as well as
4950
a kind of latest up-to-date guide.
5051

51-
## Testing tools
52-
53-
We are using [`catch2`](https://github.com/catchorg/Catch2) as the testing suite for `Zero`, in its *header-only* version.
54-
55-
We made a try to replace it with `boost::ut`, that spots that is compatible with modules, but we are getting all kind of errors in the process of convert the provided header to a precompiled module, so we will stay
56-
with `catch2` for now.
57-
58-
Also, we are looking for generate a precompiled header of the Catch's suite in order to decrement
59-
the tests compilation time.
60-
6152
## General guidelines and API design
6253

6354
This entry is a collection of both the things that we're looking for, or focusing on

zero/assets/tsuite_results.png

-31.4 KB
Binary file not shown.
11.2 KB
Loading
39.8 KB
Loading
41.7 KB
Loading

zero/ifc/test-suite/README.md

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ Test cases within a suite can be registered using the `TEST_CASE(...)` function,
6565
just like standalone tests, but choosing the overload that receives as its first parameter
6666
a reference to the test suite.
6767

68+
### **Test Modes**
69+
In the pursuit of flexibility and control over the test execution process, our testing framework offers different modes of operation. These modes determine the test runner's behavior in response to test failures, allowing users to tailor the testing process according to their specific needs or the nature of the tests being run.
70+
71+
1. **CONTINUE_ON_ERROR**
72+
- **Description**: This mode ensures that all tests are executed regardless of any failures encountered. It's ideal for comprehensive error analysis or understanding the full extent of issues in the codebase.
73+
- **Use Case**: Opt for this mode when a complete analysis of the system's state is required, particularly to identify all potential problems in a single test run.
74+
75+
2. **HALT_SUITE_ON_FAIL**
76+
- **Description**: In this mode, the test suite halts the execution of the current suite or free tests upon encountering a failure, then proceeds to the next suite or free test. It allows for a quick bypass of problematic tests while still performing remaining tests.
77+
- **Use Case**: Useful for scenarios where quickly identifying and addressing failures is important, without getting bogged down by tests in a problematic suite.
78+
79+
3. **ABORT_ALL_ON_FAIL (Default mode)**
80+
- **Description**: This mode adopts a zero-tolerance approach towards test failures. As soon as any test fails, it immediately halts all further testing activities.
81+
- **Use Case**: Use this mode to avoid wasting time on further tests when there's already a known issue that needs fixing.
82+
6883
## **Example of usage**
6984

7085
Here's an example of how to use the custom test-suite to write and run test cases:
@@ -76,52 +91,104 @@ import std; // Should be ready on all the major compilers for C++23. But until
7691
// with the `Zork++` out of the box solution based on Clang modulemaps.
7792
import tsuite;
7893

79-
// Define test functions. Should be void functions that later w'd be registered in a suite.
94+
// Let's define some example test functions using the assertion function
8095
void testAddition() {
8196
int result = 2 + 2;
8297
assertEquals(4, result);
98+
assertEquals(4, result);
99+
assertEquals(4, result);
100+
}
101+
102+
// Let's define some more example test functions using the assertion function
103+
void testSubtraction() {
104+
int result = 3 - 2;
105+
assertEquals(1, result);
106+
assertEquals(23, result);
107+
assertEquals(1, result);
108+
}
109+
110+
111+
// Let's define even more example test functions using the assertion function
112+
void testMultiplication() {
113+
int result = 2 * 2;
114+
assertEquals(4, result);
115+
assertEquals(4, result);
116+
assertEquals(4, result);
83117
}
84118

119+
85120
// Passing two pointers to compare if the values that they point to are equals
86121
void testPtrsAddition() {
87122
int result = 2 + 2;
88123
int expected = 4;
124+
int wrongExpected = 16;
89125
assertEquals(&expected, &result);
126+
assertEquals(&wrongExpected, &result);
90127
}
91128

92129
// Driver code
93130
int main() {
94-
// Free tests cases registration examples
95-
131+
132+
TEST_CASE("Multiplication Test", []() {
133+
int result = 5 * 3;
134+
assertEquals(15, result);
135+
assertEquals(15, result);
136+
});
137+
138+
96139
// Register a new test case using a function pointer.
97140
TEST_CASE("Addition Test With Pointers", testPtrsAddition);
98-
99-
// Users can register a new test case using lambdas, avoiding to write standalone functions
141+
142+
// Users can register a new test case using lambdas, avoiding writing standalone functions
100143
TEST_CASE("Subtraction Test", []() {
101144
int result = 5 - 3;
102-
assertEquals(122435, result);
145+
assertEquals(2, result);
146+
assertEquals(2, result);
103147
});
104-
148+
105149
// Registering test cases into test suites, to group and relate tests that makes sense to exists
106150
// as a part of a whole
107-
151+
108152
// Instantiate a new test suite, giving it a unique identifier.
109153
TestSuite suite {"My Suite"};
110154
// Register test cases using function pointers into a test suite
111155
TEST_CASE(suite, "Addition Test", testAddition);
112-
// Force a warning that alerts the user that the test will be discarded, since already
156+
// Forces a warning that alerts the user that the test will be discarded, since already
113157
// exists one with the same identifier in the given suite
114158
TEST_CASE(suite, "Addition Test", testAddition);
115-
159+
// Register a test case designed to fail, useful for testing the behavior
160+
// of RUN_TESTS with different failure modes.
161+
TEST_CASE(suite, "Subtraction Test", testSubtraction);
162+
163+
// Register additional test cases to verify the functionality of RUN_TESTS
164+
// under different conditions.
165+
TEST_CASE(suite, "Multiplication Test", testMultiplication);
166+
167+
// Create another test suite to further validate the behavior of RUN_TESTS
168+
// with multiple suites, especially under different failure modes.
169+
TestSuite anotherSuite {"Another Suite"};
170+
TEST_CASE(anotherSuite, "Addition Test", testAddition);
171+
TEST_CASE(anotherSuite, "Subtraction Test", testSubtraction);
172+
TEST_CASE(anotherSuite, "Multiplication Test", testMultiplication);
173+
116174
// Don't forget to call this free function, to run all the tests written!
175+
// Options are: CONTINUE_ON_ERROR, HALT_SUITE_ON_FAIL, ABORT_ALL_ON_FAIL (default)
117176
RUN_TESTS();
118177

119178
return 0;
120179
}
121180
```
122181

123-
With these example, you will see this result:
124-
![img.png](../../assets/tsuite_results.png)
182+
With these examples, you will see different results depending on the mode used:
183+
184+
1. **ABORT_ALL_ON_FAIL** mode (Default):
185+
![Abort All on Fail Mode](../../assets/tsuite_results_ABORT_ALL_ON_FAIL_mode.png)
186+
187+
2. **HALT_SUITE_ON_FAIL** mode:
188+
![Halt Suite on Fail Mode](../../assets/tsuite_results_HALT_SUITE_ON_FAIL_mode.png)
189+
190+
3. **CONTINUE_ON_ERROR** mode:
191+
![Continue on Error Mode](../../assets/tsuite_results_CONTINUE_ON_ERROR_mode.png)
125192

126193
## Funny facts
127194

0 commit comments

Comments
 (0)