You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.en.md
+67-38Lines changed: 67 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Hope you get 0 errors and 0 warnings everyday!
8
8

9
9
10
10
11
-
ZeroErr is a smart assert library, a lightweight unit test framework and a quick logging framework. It integrates those features and provided an unite and clear interface for seperate using or joint using.
11
+
ZeroErr is a smart assertion library, a lightweight unit testing framework and a structure logging framework. It integrates those features and provided an unite and clear interface for separated usage or combined usage.
@@ -21,7 +21,7 @@ The current popular unit testing frameworks, e.g. Catch2, doctest, Boost.Test an
21
21
22
22
### 1. Generic Printing
23
23
24
-
Most unit testing frameworks and logger libraries can not provide a generic printing for user customized type. Especially, when using containers, struct and pointers (including smart pointers), user have to manualy write code to generate the log message or print those information during unit testing failed cases.
24
+
Most unit testing frameworks and logger libraries can not provide a generic printing for user customized types. Especially, when using containers, structures and pointers (including smart pointers), user have to manually write code to generate the log message or print those information during unit testing failed cases.
25
25
26
26
This library `zeroerr` gives you an ability to print generically for all types:
27
27
@@ -36,7 +36,7 @@ Similar to other C++ unit testing frameworks, `zeroerr` will convert this piece
36
36
37
37

38
38
39
-
For the custom struct type with override `std::ostream& operator<<(std::ostream&, Type)` stream output, you can use it not only for this type but also all contains using this type, including multiple recurisve contains:
39
+
For the custom struct type with override `std::ostream& operator<<(std::ostream&, Type)` stream output, you can use it not only for this type but also all contains using this type, including multiple recursive contains:
40
40
41
41
```c++
42
42
struct Node {
@@ -94,9 +94,9 @@ This functin `PrintExt` will match all the class who's base class is `Value` and
94
94
95
95

96
96
97
-
### 2. Joint using of assert, log and unit testing
97
+
### 2. Combined usage of assert, log and unit testing
98
98
99
-
If you use a logger, an unit testing framework and a smart assert libary, you can joint use them and some macros may conflict. In `zeroerr`, if an assertion is failed, the logger will recevie an event and stored in your log file. If you are using an assertion in unit testing, the assertion can be recorded and reported in the end.
99
+
If you use one logging framework, an unit testing framework and an assertion library, it's not a easy work to combine them together. There is a lot of benefits to use assertion, logging and unit testing together. In `zeroerr`, if an assertion is failed, the logger will receive an event and stored the event in your log file. If you are using an assertion in unit testing, the assertion failure, logged fatal events can be recorded and reported.
100
100
101
101
```c++
102
102
int fib(int n) {
@@ -121,13 +121,33 @@ TEST_CASE("fib function test") {
121
121
122
122

123
123
124
-
Further more, the unit testing can check the log result matches the previous running result to avoid writing code to check it.
124
+
For the logging system, the unit testing can access the log data to ensure that the function has executed the expected logic and results.
In order to access the log, we need to pause the log system first, to avoid the data being output to the file, then call the function, access the data in the log through the `LOG_GET` macro, and finally resume the log system. (Currently experimental, only the first call of each log point can be accessed)
142
+
143
+
144
+
Further more, the unit testing can check the logged result if it matches the previous running result (a golden file) to avoid writing any code in the test case.
125
145
126
146
```c++
127
147
TEST_CASE("match ostream") {
128
148
// match output can be done in the following workflow
129
-
// 1. user mark the test case which are comparing output use 'have_same_output'
130
-
// 2. If the output is not exist, the result has been used as a correct verifier.
149
+
// 1. user mark the test case which are comparing output use 'ZEROERR_HAVE_SAME_OUTPUT'
150
+
// 2. If the output is not exist, the result will be store to the disk.
131
151
// 3. If the output is exist, compare with it and report error if output is not match.
Once you set `ZEROERR_HAVE_SAME_OUTPUT` marco, the system will check the output stream and save the first run result into a file. Then, the next run will compare the result to see if it the same. (Currently experimental)
139
159
140
160
141
-
Finally, for the log system, the unit testing can access the log data to ensure that the function has executed the expected logic and results.
161
+
## 3. Fuzzing Support
142
162
143
-
```c++
144
-
118 static void function() {
145
-
119 LOG("function log {i}", 1);
146
-
120 LOG("function log {sum}, {i}", 10, 1);
147
-
121 }
148
-
...
163
+
Most Unit Testing frameworks do not support fuzzing. However, it's a powerful feature to automatically detect faults in the software and can greatly reduce the work to write test cases.
149
164
150
-
TEST_CASE("access log in Test case") {
151
-
zeroerr::suspendLog();
152
-
function();
153
-
CHECK(LOG_GET(function, 119, i, int) == 1);
154
-
CHECK(LOG_GET(function, 120, sum, int) == 10);
155
-
CHECK(LOG_GET(function, 120, i, int) == 1);
156
-
zeroerr::resumeLog();
165
+
Different than other fuzzing framework, `zeroerr` can also support logging and assertion in the code, so the fuzzing result not only contains corpus but also with the logging and assertion information.
166
+
167
+
Here is an example of using `zeroerr` to do structured fuzzing:
In order to access the log, we need to pause the log system first, to avoid the data being output to the file, then call the function, access the data in the log through the `LOG_GET` macro, and finally resume the log system. (Currently experimental, only the first call of each log point can be accessed)
183
+
Inspired by [fuzztest](https://github.com/google/fuzztest), Domain is a concept to specify the input data range (or patterns) for the target function. Here, we use `InRange`to specify the range of `k` is 0 to 10, and `Arbitrary` to specify the data of `num` can be any random string. Then, we use `WithSeeds` to specify the initial seeds for the fuzzing.
161
184
185
+
The macro `FUZZ_TEST_CASE` will generate a test case which can connect with `libFuzzer` to run the fuzzing. Finally, we use `Run(10)` to call `libFuzzer` to run the target for 10 times.
186
+
187
+
To build the test case with fuzzing, you need to use `clang++` to compile the code and with `-fsanitize=fuzzer-no-link` and link the `-lclang_rt.fuzzer_no_main-x86_64` which is a version of libFuzzer without main function. You can find this runtime library by calling `clang++ -print-runtime-dir`. Here is the complete command to build the test case with fuzzing support:
Using ZeroErr, you can catch your assert error, log fatal event in the unit testing.
168
-
The fatal condition will be recorded and printed. Here are a list of features we provided:
197
+
Here are a list of features we provided:
169
198
170
-
1.Minimal Requirement
171
-
You can only include what you need. If you need assert but no unit testing, no problem.
199
+
1.Partially include
200
+
You can only include what you need. If you need only assertion but no unit testing, no problem.
172
201
173
202
2. Optional thread safety
174
-
You can choose to build with/without thread safety. For some simple single thread program, log is no need to be multithread safed.
203
+
You can choose to build with/without thread safety.
175
204
176
205
3. Fastest log
177
-
Using a lock-free queue for logging and multiple level of log writing policies. You can choose to only write to disk with the most important events.
206
+
Multiple level of log writing policies. You can choose to only write to disk with the most important events.
178
207
179
208
4. Customized print / log / assert printing format
180
-
You can customize your printing format for everything. There is a callback function for the printing.
209
+
You can customize your printing format for everything. There is a templated callback function for the printing.
181
210
182
211
5. Quickly debug something
183
-
You can use dbg macro to quickly see the output, it can print the expression also.
212
+
You can use dbg macro to quickly see the output, it can be applied to any expression.
184
213
185
214
6. Colorful output
186
-
You can have default colorful output to terminal and no color for file
215
+
You can have default colorful output to terminal and no color for file output
187
216
188
-
7. Print struct/stl/special library data structure
217
+
7. Print struct/stl/pointers without any extra code
189
218
190
219
8. Doctest like assertion and unit test feature
191
220
You can use your unit test as a documentation of function behavior. The output of unittest can be a documented report.
@@ -194,13 +223,13 @@ You can use your unit test as a documentation of function behavior. The output o
194
223
After assertion failed, the logging result will print automatically even if you didn't redirect to your error stream
195
224
196
225
10. Logging Category
197
-
Logging information can have customized category and only display one categroy based on your assertion or configuration
226
+
Logging information can have customized category and only display one category based on your assertion or configuration
198
227
199
228
11. Logging for Unit Testing
200
-
You can use a correct logging result as your unit testing comparsion. So you just need to manually verify your log once and setup it as baseline comparsion. The unit testing framework will use that as the result to verify unit testing
229
+
You can use a correct logging result as your unit testing golden file. So you just need to manually verify your log once and save it. The unit testing framework will use the golden file to verify your unit testing result.
201
230
202
231
12. Structured Logging
203
-
We can support output structured information directly into plain text, json, logfmt, or other custom format
232
+
We can support output structured information directly into plain text or lisp format (json, logfmt, or other custom format should be the next step to support)
204
233
205
234
13. Automatic Tracing with logging
206
235
While logging at the end, we can record the time consuming for this function.
@@ -210,7 +239,7 @@ While logging at the end, we can record the time consuming for this function.
0 commit comments