Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
cd $SCRIPTPATH/../

wsl -- bash -c "make && make test && make doc-build && cp build-linux/zeroerr.hpp ./zeroerr.hpp"

git add zeroerr.hpp
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/.vscode
/build*
/.xmake
/.cache
/node_modules
/docs/.vuepress/.cache
Expand Down
22 changes: 22 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22621.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/build-windows/Debug/unittest.exe",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
103 changes: 103 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"files.associations": {
"*.cuh": "cpp",
"*.cu": "cpp",
"sstream": "cpp",
"functional": "cpp",
"map": "cpp",
"memory": "cpp",
"random": "cpp",
"system_error": "cpp",
"thread": "cpp",
"type_traits": "cpp",
"variant": "cpp",
"vector": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"deque": "cpp",
"exception": "cpp",
"format": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"string": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"utility": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"set": "cpp",
"csignal": "cpp",
"cwctype": "cpp",
"hash_map": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"unordered_set": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"source_location": "cpp",
"string_view": "cpp",
"future": "cpp",
"numbers": "cpp",
"semaphore": "cpp",
"span": "cpp",
"typeindex": "cpp",
"valarray": "cpp",
"regex": "cpp"
},
"cmake.buildDirectory": "${workspaceFolder}/build-windows"
}
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,25 @@ endif()
option(BUILD_EXAMPLES "Build examples(ON, OFF)" OFF)
option(BUILD_DOC "Build documentation" OFF)

# add_compile_options("$<$<C_COMPILER_ID:MSVC>:/P>" "$<$<CXX_COMPILER_ID:MSVC>:/P>")

# add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>" "$<$<C_COMPILER_ID:MSVC>:/Zc:preprocessor>")
# add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>" "$<$<CXX_COMPILER_ID:MSVC>:/Zc:preprocessor>")


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

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


# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
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})
set(header_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/extension ${CMAKE_CURRENT_SOURCE_DIR}/third_party ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${header_dirs})

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

add_library(zeroerr STATIC ${source_files})

target_compile_options(zeroerr PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
)
# if(ENABLE_SAN)
# 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")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-recover=address -fsanitize=address")
Expand Down Expand Up @@ -139,6 +138,10 @@ if(MAIN_PROJECT)

add_executable(unittest ${test_files} ${cuda_files})
target_link_libraries(unittest zeroerr ${llvm_libs})
target_compile_options(unittest PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
)

add_executable(single_file_test ${CMAKE_CURRENT_SOURCE_DIR}/test/single_file_test.cpp)
add_dependencies(single_file_test assemble_single_header)
Expand Down
11 changes: 11 additions & 0 deletions Contributing.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ We encourage developers to contribute to this project, but please follow the rul
5. Please make sure to use English for comments in the code to avoid compiler encoding problems
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
7. We welcome the extension of special environment use and the integration of third-party libraries. Please put these extensions in the extension directory


## Tips

### Enable the pre-commit hook
This hook script can help auto build and test the project before you submit a commit:
```bash
git config --local core.hooksPath .githooks/
```


11 changes: 10 additions & 1 deletion Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
4. 所有文档、教程的修改请务必注意保持中英版本一致
5. 代码中注释的添加与修改请确保使用英文,避免出现编译器编码问题
6. 确保修改后完整构建过一次本项目,这样可以使得根目录下的合并版`zeroerr.hpp`文件与源码保持一致
7. 我们欢迎给特殊环境的使用、第三方库的集成提供扩展功能,请将这些扩展放到extension目录下
7. 我们欢迎给特殊环境的使用、第三方库的集成提供扩展功能,请将这些扩展放到extension目录下


## 小技巧

### 启用 git pre-commit hook
这个hook会在每次commit前运行,可以用来检查代码风格、运行测试等,最后把构建的zeroerr.hpp文件放到根目录下并一起提交
```bash
git config --local core.hooksPath .githooks/
```
28 changes: 25 additions & 3 deletions Readme.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Hope you get 0 errors and 0 warnings everyday!
![](./docs/fig/zeroerr.jpg)



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.

[Tutorial](./docs/tutorial.en.md)
[English Documentation](https://sunxfancy.github.io/zeroerr/en/) | [项目文档](https://sunxfancy.github.io/zeroerr/zh/)

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.

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

## Why we need another unit testing framework

Expand Down Expand Up @@ -138,6 +138,28 @@ TEST_CASE("match ostream") {
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)


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.

```c++
118 static void function() {
119 LOG("function log {i}", 1);
120 LOG("function log {sum}, {i}", 10, 1);
121 }
...

TEST_CASE("access log in Test case") {
zeroerr::suspendLog();
function();
CHECK(LOG_GET(function, 119, i, int) == 1);
CHECK(LOG_GET(function, 120, sum, int) == 10);
CHECK(LOG_GET(function, 120, i, int) == 1);
zeroerr::resumeLog();
}
```

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)



## Features

Expand Down
23 changes: 23 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ZeroErr 零误框架是一款轻量级C++单元测试框架,同时也集成了

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

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

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

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


最后,对于日志系统,单元测试不但能够访问日志数据,以确保函数按照预期逻辑执行出来了结果。
还可以在逻辑出错时,自动捕获函数中的断言和相关打印信息,以便于后续的调试。

```c++
118 static void function() {
119 LOG("function log {i}", 1);
120 LOG("function log {sum}, {i}", 10, 1);
121 }
...

TEST_CASE("access log in Test case") {
zeroerr::suspendLog();
function();
CHECK(LOG_GET(function, 119, i, int) == 1);
CHECK(LOG_GET(function, 120, sum, int) == 10);
CHECK(LOG_GET(function, 120, i, int) == 1);
zeroerr::resumeLog();
}
```

为了访问log,我们首先要暂停log系统,避免数据被输出到文件中,然后调用函数,通过`LOG_GET`宏访问log中的数据,最后再恢复log系统的运行。(目前,暂时仅能获取到每个Log点第一次调用的数据,仍是实验功能)。


## 项目构建

Expand Down
4 changes: 4 additions & 0 deletions docs/en/assertion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Assertion
===========


2 changes: 1 addition & 1 deletion docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ features:
- title: Header-only
details: Header-only library, easy to use and integrate with your project. Support C++11/14/17/20.
- title: Small and Fast
details: Only 3K+ lines of C++ code, fast to compile and run.
details: Only 5K+ lines of C++ code, fast to compile and run.
- title: Multi-Scene Usage
details: Configure the print rules once, and it can be applied to multiple scenes such as logging, unit testing, and debugging at the same time.
footer: MIT Licensed | Copyright © 2022-present 西风逍遥游
Expand Down
24 changes: 24 additions & 0 deletions docs/en/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,30 @@ Once you set `ZEROERR_HAVE_SAME_OUTPUT` marco, the system will check the output



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.

```c++
118 static void function() {
119 LOG("function log {i}", 1);
120 LOG("function log {sum}, {i}", 10, 1);
121 }
...

TEST_CASE("access log in Test case") {
zeroerr::suspendLog();
function();
CHECK(LOG_GET(function, 119, i, int) == 1);
CHECK(LOG_GET(function, 120, sum, int) == 10);
CHECK(LOG_GET(function, 120, i, int) == 1);
zeroerr::resumeLog();
}
```

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)




### Features


Expand Down
8 changes: 8 additions & 0 deletions docs/zh/assertion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
断言(Assertion)
================

断言是一个表达式,用来约束当前的程序变量符合一定的条件。如果断言失败,程序会抛出一个异常。断言通常用于调试和测试,可以在程序中加入一些检查点,确保程序的正确性。


我们提供了高级的断言库,可以用来检查变量的类型、值、长度等。

2 changes: 1 addition & 1 deletion docs/zh/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ features:
- title: 单文件,易引入
details: Header-only的库,只需引入一个头文件即可使用。
- title: 小巧快速
details: 仅3K余行C++代码,编译速度快,运行速度快。
details: 仅5K行C++代码,编译速度快,运行速度快。
- title: 多场景使用
details: 一次配置打印规则,可同时应用于日志,单元测试,调试等场景。
footer: MIT Licensed | Copyright © 2022-present 西风逍遥游
Expand Down
Loading