Skip to content

Commit abdcf2e

Browse files
authored
Merge pull request #34 from sunxfancy/dev
v0.4 release
2 parents 4f3db41 + ae90898 commit abdcf2e

35 files changed

+1225
-227
lines changed

.githooks/pre-commit

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ cd $SCRIPTPATH/../
66
set -e
77

88
CMD_TO_RUN="make && make test && make doc && cp build/linux/zeroerr.hpp ./zeroerr.hpp"
9-
if [ -f "/etc/wsl.conf" ]; then
9+
if [ "$(uname -o)" == "GNU/Linux" ]; then
10+
bash -c "$CMD_TO_RUN"
11+
elif [ -f "/etc/wsl.conf" ]; then
1012
bash -c "$CMD_TO_RUN"
1113
else
1214
wsl -- bash -c "$CMD_TO_RUN"

.vscode/launch.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
"args": [],
1313
"cwd": "${workspaceFolder}"
1414
},
15+
{
16+
"type": "lldb",
17+
"request": "launch",
18+
"name": "Windows 2_log",
19+
"program": "${workspaceFolder}/build/windows/examples/Debug/2_log.exe",
20+
"args": ["--testcase=parsing test"],
21+
"cwd": "${workspaceFolder}"
22+
},
1523
{
1624
"type": "lldb",
1725
"request": "launch",

CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ option(BUILD_EXAMPLES "Build examples(ON, OFF)" OFF)
6464
option(BUILD_DOC "Build documentation" OFF)
6565
option(BUILD_TEST "Build unittest" OFF)
6666

67-
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
68-
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
69-
add_compile_options("$<$<CXX_COMPILER_ID:Clang>:-fstandalone-debug>")
70-
# add_compile_options("$<$<CXX_COMPILER_ID:GNU>:-ftime-report>")
71-
7267
set(header_dirs
7368
${CMAKE_CURRENT_SOURCE_DIR}/include
7469
${CMAKE_CURRENT_SOURCE_DIR}/extension

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ all: linux windows
55
build/linux/Makefile: Makefile
66
mkdir -p build/linux
77
cmake -B build/linux -S . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=11 \
8-
-DBUILD_EXAMPLES=ON -DBUILD_TEST=ON -DUSE_MOLD=ON -DENABLE_FUZZING=ON \
8+
-DBUILD_EXAMPLES=ON -DBUILD_TEST=ON -DUSE_MOLD=ON -DDISABLE_CUDA_BUILD=OFF -DENABLE_FUZZING=ON \
99
-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
1010

1111
linux: build/linux/Makefile
@@ -14,18 +14,21 @@ linux: build/linux/Makefile
1414
build/windows/ZeroErr.sln:
1515
mkdir -p build/windows
1616
cmake.exe -B build/windows -S . \
17-
-DBUILD_EXAMPLES=ON -DBUILD_TEST=ON -T host=x64 -A x64
17+
-DBUILD_EXAMPLES=ON -DBUILD_TEST=ON -DDISABLE_CUDA_BUILD=OFF -T host=x64 -A x64
1818

1919
windows: build/windows/ZeroErr.sln
2020
cmake.exe --build build/windows --config Debug -j `nproc`
2121

2222
test: linux-test windows-test fuzz-test
2323

24+
cuda-test: windows
25+
cd build/windows/test && ./Debug/cudatest.exe
26+
2427
fuzz-test: linux
2528
cd build/linux/test && ./unittest --testcase=fuzz_serialize.*
2629

2730
fuzz: linux
28-
cd build/linux/test && ./unittest -f --testcase=fuzz_test.*
31+
cd build/linux/test && ./unittest -f --testcase=presentation
2932

3033
linux-test: linux
3134
cd build/linux/test && ./unittest
@@ -34,7 +37,7 @@ reporter: linux
3437
cd build/linux/test && ./unittest --no-color --log-to-report --reporters=xml
3538

3639
windows-test: windows
37-
cd build/windows/test && ./Debug/unittest.exe
40+
cd build/windows/test && ../examples/Debug/2_log.exe --testcase="parsing test"
3841

3942

4043
build/linux-release/Makefile: Makefile

Readme.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,26 @@ clang++ -std=c++11 -fsanitize=fuzzer-no-link -L=`clang++ -print-runtime-dir` -lc
192192
```
193193

194194

195-
## Other Good Features
195+
## CppCon 24 Talk
196+
197+
If you are interested in the design and internal techiques used in `zeroerr`, please checkout [the talk in CppCon 24](https://youtu.be/otSPZyXqY_M?si=LLSHh8gkfCiQk983).
198+
199+
[![](docs/fig/video-screenshot.png)](https://youtu.be/otSPZyXqY_M?si=LLSHh8gkfCiQk983)
200+
201+
## Header-only libraries
202+
203+
* dbg
204+
* print (without use extern functions)
205+
* assert
206+
* color (if always enabled)
207+
196208

209+
## Other Good Features
197210

198211
Here are a list of features we provided:
199212

200213
1. Partially include
201-
You can only include what you need. If you need only assertion but no unit testing, no problem.
214+
You can only include what you need. If you need only assertion but no unit testing, you can only include the header `zeroerr/assert.h`.
202215

203216
2. Optional thread safety
204217
You can choose to build with/without thread safety.
@@ -235,12 +248,6 @@ We can support output structured information directly into plain text or lisp fo
235248
13. Automatic Tracing with logging
236249
While logging at the end, we can record the time consuming for this function.
237250

238-
## Header-only libraries
239-
240-
* dbg
241-
* print (without use extern functions)
242-
* assert
243-
* color (if always enabled)
244251

245252

246253
## The logo generation

docs/fig/video-screenshot.png

1.21 MB
Loading

examples/1_basic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ TEST_CASE("fib function test") {
4747
CHECK(fib(3) == 2);
4848
CHECK(fib(4) == 3);
4949
CHECK(fib(5) == 5);
50-
CHECK(fib(20) == 6765);
50+
CHECK_THROWS(fib(20));
5151
}

examples/2_log.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#define ZEROERR_IMPLEMENTATION
2+
#include "zeroerr.hpp"
3+
4+
using namespace zeroerr;
5+
6+
TEST_CASE("1. basic log test") {
7+
LOG("Basic log");
8+
WARN("Warning log");
9+
ERR("Error log");
10+
FATAL("Fatal log");
11+
12+
LOG("log with basic thype {} {} {} {}", 1, true, 1.0, "string");
13+
14+
std::vector<std::tuple<int, float, std::string>> data = {
15+
{1, 1.0, "string"}, {2, 2.0, "string"}
16+
};
17+
LOG("log with complex type: {data}", data);
18+
19+
LOG_IF(1==1, "log if condition is true");
20+
LOG_FIRST(1==1, "log only at the first time condition is true");
21+
WARN_EVERY_(2, "log every 2 times");
22+
WARN_IF_EVERY_(2, 1==1, "log if condition is true every 2 times");
23+
24+
DLOG(WARN_IF, 1==1, "debug log for WARN_IF");
25+
}
26+
27+
28+
struct Expr {
29+
virtual Expr* Clone() { return new Expr(); };
30+
virtual ~Expr() {}
31+
};
32+
33+
Expr* parse_the_input(std::string input) {
34+
return new Expr();
35+
}
36+
37+
38+
Expr* parseExpr(std::string input)
39+
{
40+
static std::map<std::string, Expr*> cache;
41+
if (cache.count(input) == 0) {
42+
Expr* expr = parse_the_input(input);
43+
cache[input] = expr;
44+
return expr;
45+
} else {
46+
LOG("CacheHit: input = {input}", input);
47+
return cache[input]->Clone();
48+
}
49+
}
50+
51+
TEST_CASE("parsing test") {
52+
zeroerr::suspendLog();
53+
std::string log;
54+
Expr* e1 = parseExpr("1 + 2");
55+
log = LOG_GET(parseExpr, "CacheHit", input, std::string);
56+
CHECK(log == std::string{});
57+
Expr* e2 = parseExpr("1 + 2");
58+
log = zeroerr::LogStream::getDefault()
59+
.getLog<std::string>("parseExpr", "CacheHit", "input");
60+
CHECK(log == "1 + 2");
61+
zeroerr::resumeLog();
62+
}
63+
64+
65+
TEST_CASE("iterate log stream") {
66+
zeroerr::suspendLog();
67+
68+
auto& stream = zeroerr::LogStream::getDefault();
69+
70+
for (auto p = stream.begin("function log {sum}, {i}"); p != stream.end(); ++p) {
71+
std::cerr << "p.get<int>(\"sum\") = " << p.get<int>("sum") << std::endl;
72+
std::cerr << "p.get<int>(\"i\") = " << p.get<int>("i") << std::endl;
73+
CHECK(p.get<int>("sum") == 10);
74+
CHECK(p.get<int>("i") == 1);
75+
}
76+
77+
zeroerr::resumeLog();
78+
}
79+

examples/3_fuzzing.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#define ZEROERR_IMPLEMENTATION
2+
#define ZEROERR_FUZZING
3+
#include "zeroerr.hpp"
4+
5+
using namespace zeroerr;
6+
7+
8+
9+
int find_the_biggest(std::vector<int> vec) {
10+
if (vec.empty()) {
11+
WARN("Empty vector, vec.size() = {size}", vec.size());
12+
return 0;
13+
}
14+
int max = 0;
15+
for (int i = 0; i < vec.size(); ++i) {
16+
if (vec[i] > max) {max = vec[i];}
17+
}
18+
return max;
19+
}
20+
21+
FUZZ_TEST_CASE("presentation") {
22+
LOG("Run fuzz_test");
23+
FUZZ_FUNC([=](std::vector<int> vec) {
24+
int ans = find_the_biggest(vec);
25+
// verify the result
26+
for (int i = 0; i < vec.size(); ++i) {
27+
CHECK(ans >= vec[i]);
28+
}
29+
if (vec.size() == 0) {
30+
CHECK(ans == 0);
31+
// verify WARN message to make sure the path is correct
32+
CHECK(LOG_GET(find_the_biggest,
33+
"Empty vector, vec.size() = {size}", size, size_t) == 0);
34+
}
35+
})
36+
.WithDomains(ContainerOf<std::vector<int>>(
37+
InRange<int>(0, 100)))
38+
.WithSeeds({{{0, 1, 2, 3, 4, 5}}, {{1, 8, 4, 2, 3}}})
39+
.Run(100);
40+
41+
}

examples/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
add_executable(1_basic ${CMAKE_CURRENT_SOURCE_DIR}/1_basic.cpp)
2-
add_dependencies(1_basic assemble_single_header)
1+
macro(define_example name)
2+
add_executable(${name} ${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp)
3+
add_dependencies(${name} assemble_single_header)
4+
endmacro(define_example)
5+
6+
define_example(1_basic)
7+
define_example(2_log)
8+
define_example(3_fuzzing)

0 commit comments

Comments
 (0)