Skip to content

Commit d1bf0a9

Browse files
authored
Merge pull request #22 from sunxfancy/dev
v0.1.0
2 parents 8c9ced2 + c6b9252 commit d1bf0a9

38 files changed

Lines changed: 5819 additions & 4601 deletions

.githooks/pre-commit

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
4+
cd $SCRIPTPATH/../
5+
6+
wsl -- bash -c "make && make test && make doc-build && cp build-linux/zeroerr.hpp ./zeroerr.hpp"
7+
8+
git add zeroerr.hpp

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/.vscode
21
/build*
3-
/.xmake
42
/.cache
53
/node_modules
64
/docs/.vuepress/.cache

.vscode/c_cpp_properties.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Win32",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [
9+
"_DEBUG",
10+
"UNICODE",
11+
"_UNICODE"
12+
],
13+
"windowsSdkVersion": "10.0.22621.0",
14+
"compilerPath": "cl.exe",
15+
"cStandard": "c17",
16+
"cppStandard": "c++17",
17+
"intelliSenseMode": "windows-msvc-x64",
18+
"configurationProvider": "ms-vscode.cmake-tools"
19+
}
20+
],
21+
"version": 4
22+
}

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug",
11+
"program": "${workspaceFolder}/build-windows/Debug/unittest.exe",
12+
"args": [],
13+
"cwd": "${workspaceFolder}"
14+
}
15+
]
16+
}

.vscode/settings.json

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"files.associations": {
3+
"*.cuh": "cpp",
4+
"*.cu": "cpp",
5+
"sstream": "cpp",
6+
"functional": "cpp",
7+
"map": "cpp",
8+
"memory": "cpp",
9+
"random": "cpp",
10+
"system_error": "cpp",
11+
"thread": "cpp",
12+
"type_traits": "cpp",
13+
"variant": "cpp",
14+
"vector": "cpp",
15+
"xmemory": "cpp",
16+
"xstddef": "cpp",
17+
"xstring": "cpp",
18+
"algorithm": "cpp",
19+
"array": "cpp",
20+
"atomic": "cpp",
21+
"bit": "cpp",
22+
"cctype": "cpp",
23+
"charconv": "cpp",
24+
"chrono": "cpp",
25+
"clocale": "cpp",
26+
"cmath": "cpp",
27+
"compare": "cpp",
28+
"concepts": "cpp",
29+
"condition_variable": "cpp",
30+
"cstdarg": "cpp",
31+
"cstddef": "cpp",
32+
"cstdint": "cpp",
33+
"cstdio": "cpp",
34+
"cstdlib": "cpp",
35+
"cstring": "cpp",
36+
"ctime": "cpp",
37+
"cwchar": "cpp",
38+
"deque": "cpp",
39+
"exception": "cpp",
40+
"format": "cpp",
41+
"forward_list": "cpp",
42+
"fstream": "cpp",
43+
"initializer_list": "cpp",
44+
"iomanip": "cpp",
45+
"ios": "cpp",
46+
"iosfwd": "cpp",
47+
"iostream": "cpp",
48+
"istream": "cpp",
49+
"iterator": "cpp",
50+
"limits": "cpp",
51+
"list": "cpp",
52+
"locale": "cpp",
53+
"mutex": "cpp",
54+
"new": "cpp",
55+
"optional": "cpp",
56+
"ostream": "cpp",
57+
"ratio": "cpp",
58+
"stdexcept": "cpp",
59+
"stop_token": "cpp",
60+
"streambuf": "cpp",
61+
"string": "cpp",
62+
"tuple": "cpp",
63+
"typeinfo": "cpp",
64+
"unordered_map": "cpp",
65+
"utility": "cpp",
66+
"xfacet": "cpp",
67+
"xhash": "cpp",
68+
"xiosbase": "cpp",
69+
"xlocale": "cpp",
70+
"xlocbuf": "cpp",
71+
"xlocinfo": "cpp",
72+
"xlocmes": "cpp",
73+
"xlocmon": "cpp",
74+
"xlocnum": "cpp",
75+
"xloctime": "cpp",
76+
"xtr1common": "cpp",
77+
"xtree": "cpp",
78+
"xutility": "cpp",
79+
"set": "cpp",
80+
"csignal": "cpp",
81+
"cwctype": "cpp",
82+
"hash_map": "cpp",
83+
"*.tcc": "cpp",
84+
"bitset": "cpp",
85+
"cfenv": "cpp",
86+
"cinttypes": "cpp",
87+
"codecvt": "cpp",
88+
"complex": "cpp",
89+
"unordered_set": "cpp",
90+
"memory_resource": "cpp",
91+
"numeric": "cpp",
92+
"source_location": "cpp",
93+
"string_view": "cpp",
94+
"future": "cpp",
95+
"numbers": "cpp",
96+
"semaphore": "cpp",
97+
"span": "cpp",
98+
"typeindex": "cpp",
99+
"valarray": "cpp",
100+
"regex": "cpp"
101+
},
102+
"cmake.buildDirectory": "${workspaceFolder}/build-windows"
103+
}

CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,25 @@ endif()
5353
option(BUILD_EXAMPLES "Build examples(ON, OFF)" OFF)
5454
option(BUILD_DOC "Build documentation" OFF)
5555

56-
# add_compile_options("$<$<C_COMPILER_ID:MSVC>:/P>" "$<$<CXX_COMPILER_ID:MSVC>:/P>")
57-
58-
# add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>" "$<$<C_COMPILER_ID:MSVC>:/Zc:preprocessor>")
59-
# add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>" "$<$<CXX_COMPILER_ID:MSVC>:/Zc:preprocessor>")
6056

6157

6258
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>" )
6359
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>" )
6460

61+
# add_compile_options("$<$<CXX_COMPILER_ID:GNU>:-ftime-report>")
6562

66-
67-
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
68-
set(header_dirs ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/extension ${CMAKE_CURRENT_SOURCE_DIR}/third_party ${CMAKE_CURRENT_BINARY_DIR})
63+
set(header_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/extension ${CMAKE_CURRENT_SOURCE_DIR}/third_party ${CMAKE_CURRENT_BINARY_DIR})
6964
include_directories(${header_dirs})
7065

7166
file(GLOB_RECURSE include_files ${CMAKE_CURRENT_SOURCE_DIR}/include/**/*.h)
7267
file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
7368

7469
add_library(zeroerr STATIC ${source_files})
7570

71+
target_compile_options(zeroerr PRIVATE
72+
$<$<CXX_COMPILER_ID:MSVC>:/W4>
73+
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
74+
)
7675
# if(ENABLE_SAN)
7776
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-recover=all -fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment")
7877
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-recover=address -fsanitize=address")
@@ -139,6 +138,10 @@ if(MAIN_PROJECT)
139138

140139
add_executable(unittest ${test_files} ${cuda_files})
141140
target_link_libraries(unittest zeroerr ${llvm_libs})
141+
target_compile_options(unittest PRIVATE
142+
$<$<CXX_COMPILER_ID:MSVC>:/W4>
143+
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
144+
)
142145

143146
add_executable(single_file_test ${CMAKE_CURRENT_SOURCE_DIR}/test/single_file_test.cpp)
144147
add_dependencies(single_file_test assemble_single_header)

Contributing.en.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ We encourage developers to contribute to this project, but please follow the rul
88
5. Please make sure to use English for comments in the code to avoid compiler encoding problems
99
6. Make sure that the modified project has been completely built once, so that the merged version `zeroerr.hpp` file in the root directory is consistent with the source code
1010
7. We welcome the extension of special environment use and the integration of third-party libraries. Please put these extensions in the extension directory
11+
12+
13+
## Tips
14+
15+
### Enable the pre-commit hook
16+
This hook script can help auto build and test the project before you submit a commit:
17+
```bash
18+
git config --local core.hooksPath .githooks/
19+
```
20+
21+

Contributing.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@
88
4. 所有文档、教程的修改请务必注意保持中英版本一致
99
5. 代码中注释的添加与修改请确保使用英文,避免出现编译器编码问题
1010
6. 确保修改后完整构建过一次本项目,这样可以使得根目录下的合并版`zeroerr.hpp`文件与源码保持一致
11-
7. 我们欢迎给特殊环境的使用、第三方库的集成提供扩展功能,请将这些扩展放到extension目录下
11+
7. 我们欢迎给特殊环境的使用、第三方库的集成提供扩展功能,请将这些扩展放到extension目录下
12+
13+
14+
## 小技巧
15+
16+
### 启用 git pre-commit hook
17+
这个hook会在每次commit前运行,可以用来检查代码风格、运行测试等,最后把构建的zeroerr.hpp文件放到根目录下并一起提交
18+
```bash
19+
git config --local core.hooksPath .githooks/
20+
```

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

0 commit comments

Comments
 (0)