Skip to content

Commit 067a7d9

Browse files
committed
update doc
1 parent 5b3b4f6 commit 067a7d9

1 file changed

Lines changed: 39 additions & 16 deletions

File tree

Readme.en.md

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Hope you get 0 errors and 0 warnings everyday!
88
![](./docs/fig/zeroerr.jpg)
99

1010

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.
1212

1313
[English Documentation](https://sunxfancy.github.io/zeroerr/en/) | [项目文档](https://sunxfancy.github.io/zeroerr/zh/)
1414

@@ -96,7 +96,7 @@ This functin `PrintExt` will match all the class who's base class is `Value` and
9696
9797
### 2. Joint using of assert, log and unit testing
9898
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.
100100
101101
```c++
102102
int fib(int n) {
@@ -121,12 +121,12 @@ TEST_CASE("fib function test") {
121121

122122
![joint1](docs/fig/joint1.png)
123123

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.
125125

126126
```c++
127127
TEST_CASE("match ostream") {
128128
// 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'
130130
// 2. If the output is not exist, the result has been used as a correct verifier.
131131
// 3. If the output is exist, compare with it and report error if output is not match.
132132
std::cerr << "a = 100" << std::endl;
@@ -137,7 +137,6 @@ TEST_CASE("match ostream") {
137137
138138
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)
139139
140-
141140
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.
142141
143142
```c++
@@ -159,16 +158,40 @@ TEST_CASE("access log in Test case") {
159158

160159
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)
161160

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:
168+
169+
```c++
170+
FUZZ_TEST_CASE("fuzz_test") {
171+
LOG("Run fuzz_test");
172+
FUZZ_FUNC([=](int k, std::string num) {
173+
int t = atoi(num.c_str());
174+
LOG("k: {k}, num:{num}, t: {t}", k, num, t);
175+
REQUIRE(k == t);
176+
})
177+
.WithDomains(InRange<int>(0, 10), Arbitrary<std::string>())
178+
.WithSeeds({{5, "Foo"}, {10, "Bar"}})
179+
.Run(10);
180+
}
181+
```
182+
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.
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.
162186
163187
164-
## Features
188+
## Other Good Features
165189
166190
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:
169192
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.
172195
173196
2. Optional thread safety
174197
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
177200
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.
178201
179202
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.
181204
182205
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.
184207
185208
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
187210
188-
7. Print struct/stl/special library data structure
211+
7. Print struct/stl/pointers without any extra code
189212
190213
8. Doctest like assertion and unit test feature
191214
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
197220
Logging information can have customized category and only display one categroy based on your assertion or configuration
198221
199222
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.
201224
202225
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)
204227
205228
13. Automatic Tracing with logging
206229
While logging at the end, we can record the time consuming for this function.

0 commit comments

Comments
 (0)