Skip to content

Commit c6b9252

Browse files
committed
update docs
1 parent 3b045fb commit c6b9252

4 files changed

Lines changed: 94 additions & 3 deletions

File tree

Readme.en.md

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

1010

11-
1211
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.
1312

14-
[Tutorial](./docs/tutorial.en.md)
13+
[English Documentation](https://sunxfancy.github.io/zeroerr/en/) | [项目文档](https://sunxfancy.github.io/zeroerr/zh/)
14+
15+
Note: The project is currently in the experimental stage, and the API may change significantly. It is not recommended to use it in a production environment.
1516

16-
[Introducation of Print Feature](./docs/print.en.md)
1717

1818
## Why we need another unit testing framework
1919

@@ -138,6 +138,28 @@ TEST_CASE("match ostream") {
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
140140
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.
142+
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+
...
149+
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();
157+
}
158+
```
159+
160+
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+
162+
141163

142164
## Features
143165

Readme.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ZeroErr 零误框架是一款轻量级C++单元测试框架,同时也集成了
1212

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

15+
注:目前项目处于实验阶段,API可能会有较大变动,不建议在生产环境中使用。
1516

1617
## 为何要开发一款新的测试框架
1718

@@ -138,6 +139,28 @@ TEST_CASE("match ostream") {
138139
通过设置 `ZEROERR_HAVE_SAME_OUTPUT` 宏,系统会自动检查该测试点的output stream输出,第一次执行时的结果会自动保存起来,而之后每次执行,都会将输出与第一次输出进行对比,相同则正确,否则该点错误。用户可以第一次手动观察输出是否符合预期,若是修改了实现后,想清除保存的结果,只需要将测试目录下的 `output.txt` 缓存文件删除即可。(目前仍是实验功能)
139140
140141
142+
最后,对于日志系统,单元测试不但能够访问日志数据,以确保函数按照预期逻辑执行出来了结果。
143+
还可以在逻辑出错时,自动捕获函数中的断言和相关打印信息,以便于后续的调试。
144+
145+
```c++
146+
118 static void function() {
147+
119 LOG("function log {i}", 1);
148+
120 LOG("function log {sum}, {i}", 10, 1);
149+
121 }
150+
...
151+
152+
TEST_CASE("access log in Test case") {
153+
zeroerr::suspendLog();
154+
function();
155+
CHECK(LOG_GET(function, 119, i, int) == 1);
156+
CHECK(LOG_GET(function, 120, sum, int) == 10);
157+
CHECK(LOG_GET(function, 120, i, int) == 1);
158+
zeroerr::resumeLog();
159+
}
160+
```
161+
162+
为了访问log,我们首先要暂停log系统,避免数据被输出到文件中,然后调用函数,通过`LOG_GET`宏访问log中的数据,最后再恢复log系统的运行。(目前,暂时仅能获取到每个Log点第一次调用的数据,仍是实验功能)。
163+
141164

142165
## 项目构建
143166

docs/en/introduction.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ Once you set `ZEROERR_HAVE_SAME_OUTPUT` marco, the system will check the output
125125

126126

127127

128+
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.
129+
130+
```c++
131+
118 static void function() {
132+
119 LOG("function log {i}", 1);
133+
120 LOG("function log {sum}, {i}", 10, 1);
134+
121 }
135+
...
136+
137+
TEST_CASE("access log in Test case") {
138+
zeroerr::suspendLog();
139+
function();
140+
CHECK(LOG_GET(function, 119, i, int) == 1);
141+
CHECK(LOG_GET(function, 120, sum, int) == 10);
142+
CHECK(LOG_GET(function, 120, i, int) == 1);
143+
zeroerr::resumeLog();
144+
}
145+
```
146+
147+
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)
148+
149+
150+
151+
128152
### Features
129153

130154

docs/zh/introduction.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,25 @@ TEST_CASE("match ostream") {
125125
```
126126
通过设置 `ZEROERR_HAVE_SAME_OUTPUT` 宏,系统会自动检查该测试点的output stream输出,第一次执行时的结果会自动保存起来,而之后每次执行,都会将输出与第一次输出进行对比,相同则正确,否则该点错误。用户可以第一次手动观察输出是否符合预期,若是修改了实现后,想清除保存的结果,只需要将测试目录下的 `output.txt` 缓存文件删除即可。(目前仍是实验功能)
127127

128+
129+
最后,对于日志系统,单元测试不但能够访问日志数据,以确保函数按照预期逻辑执行出来了结果。
130+
还可以在逻辑出错时,自动捕获函数中的断言和相关打印信息,以便于后续的调试。
131+
132+
```c++
133+
118 static void function() {
134+
119 LOG("function log {i}", 1);
135+
120 LOG("function log {sum}, {i}", 10, 1);
136+
121 }
137+
...
138+
139+
TEST_CASE("access log in Test case") {
140+
zeroerr::suspendLog();
141+
function();
142+
CHECK(LOG_GET(function, 119, i, int) == 1);
143+
CHECK(LOG_GET(function, 120, sum, int) == 10);
144+
CHECK(LOG_GET(function, 120, i, int) == 1);
145+
zeroerr::resumeLog();
146+
}
147+
```
148+
149+
为了访问log,我们首先要暂停log系统,避免数据被输出到文件中,然后调用函数,通过`LOG_GET`宏访问log中的数据,最后再恢复log系统的运行。(目前,暂时仅能获取到每个Log点第一次调用的数据,仍是实验功能)。

0 commit comments

Comments
 (0)