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
+39-16Lines changed: 39 additions & 16 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 seperate using or joint using.
@@ -96,7 +96,7 @@ This functin `PrintExt` will match all the class who's base class is `Value` and
96
96
97
97
### 2. Joint using 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 a smart assertion libary, you can not easily combine them together. In `zeroerr`, if an assertion is failed, the logger will recevie 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,12 +121,12 @@ 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
+
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
125
126
126
```c++
127
127
TEST_CASE("match ostream") {
128
128
// match output can be done in the following workflow
129
-
// 1. user mark the test case which are comparing output use 'have_same_output'
129
+
// 1. user mark the test case which are comparing output use 'ZEROERR_HAVE_SAME_OUTPUT'
130
130
// 2. If the output is not exist, the result has been used as a correct verifier.
131
131
// 3. If the output is exist, compare with it and report error if output is not match.
132
132
std::cerr << "a = 100" << std::endl;
@@ -137,7 +137,6 @@ TEST_CASE("match ostream") {
137
137
138
138
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
139
140
-
141
140
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.
142
141
143
142
```c++
@@ -159,16 +158,40 @@ TEST_CASE("access log in Test case") {
159
158
160
159
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)
161
160
161
+
## 3. Fuzzing Support
162
+
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.
164
+
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:
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.
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.
162
186
163
187
164
-
## Features
188
+
## Other Good Features
165
189
166
190
167
-
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:
191
+
Here are a list of features we provided:
169
192
170
-
1.Minimal Requirement
171
-
You can only include what you need. If you need assert but no unit testing, no problem.
193
+
1. Partially include
194
+
You can only include what you need. If you need only assertion but no unit testing, no problem.
172
195
173
196
2. Optional thread safety
174
197
You can choose to build with/without thread safety. For some simple single thread program, log is no need to be multithread safed.
@@ -177,15 +200,15 @@ You can choose to build with/without thread safety. For some simple single threa
177
200
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.
178
201
179
202
4. Customized print / log / assert printing format
180
-
You can customize your printing format for everything. There is a callback function for the printing.
203
+
You can customize your printing format for everything. There is a templated callback function for the printing.
181
204
182
205
5. Quickly debug something
183
-
You can use dbg macro to quickly see the output, it can print the expression also.
206
+
You can use dbg macro to quickly see the output, it can be applied to any expression.
184
207
185
208
6. Colorful output
186
-
You can have default colorful output to terminal and no color for file
209
+
You can have default colorful output to terminal and no color for file output
187
210
188
-
7. Print struct/stl/special library data structure
211
+
7. Print struct/stl/pointers without any extra code
189
212
190
213
8. Doctest like assertion and unit test feature
191
214
You can use your unit test as a documentation of function behavior. The output of unittest can be a documented report.
@@ -197,10 +220,10 @@ After assertion failed, the logging result will print automatically even if you
197
220
Logging information can have customized category and only display one categroy based on your assertion or configuration
198
221
199
222
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
223
+
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
224
202
225
12. Structured Logging
203
-
We can support output structured information directly into plain text, json, logfmt, or other custom format
226
+
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
227
205
228
13. Automatic Tracing with logging
206
229
While logging at the end, we can record the time consuming for this function.
0 commit comments