Skip to content

Commit 30a966e

Browse files
committed
feat: more tests
1 parent d1fcca6 commit 30a966e

23 files changed

Lines changed: 288 additions & 60 deletions

.github/workflows/clean_build_test.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,19 @@ on:
1111
# workflow_dispatch: # Allows manual triggering
1212

1313
jobs:
14-
format:
15-
runs-on: ubuntu-latest
16-
container:
17-
image: ghcr.io/milsanore/tradercppbuild:v1.6
18-
steps:
19-
- name: Checkout repository
20-
uses: actions/checkout@v4
21-
with:
22-
# if commit ref not set, revert to github-set commit
23-
ref: ${{ inputs.ref || github.ref }}
24-
- name: clang-format
25-
run: hooks/check_clang_format.sh
26-
2714
build_and_test:
28-
needs: format
2915
runs-on: ubuntu-latest
3016
container:
31-
image: ghcr.io/milsanore/tradercppbuild:v1.6
17+
image: ghcr.io/milsanore/tradercppbuild:v1.7
3218
steps:
3319
- name: Checkout repository
3420
uses: actions/checkout@v4
3521
with:
3622
fetch-depth: 0
3723

24+
- name: clang-format
25+
run: hooks/check_clang_format.sh
26+
3827
- name: Restore Conan cache
3928
uses: actions/cache@v4
4029
with:
@@ -53,11 +42,11 @@ jobs:
5342
set -e
5443
cmake --preset=debug
5544
cmake --build --preset=debug
56-
ctest --preset=debug
5745
5846
- name: Test
5947
run: |
6048
set -e
49+
ctest -j$(nproc) --preset=debug
6150
# `lcov` FOR CODECOV
6251
lcov --gcov-tool gcov \
6352
--capture \

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build_release:
1010
runs-on: ubuntu-latest
1111
container:
12-
image: ghcr.io/milsanore/tradercppbuild:v1.6
12+
image: ghcr.io/milsanore/tradercppbuild:v1.7
1313
steps:
1414
- name: Checkout repository
1515
uses: actions/checkout@v4

Dockerfile_build

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#############################################
2-
# milss/tradercppbuild:v1.6
2+
# milss/tradercppbuild:v1.7
33
# Build container for tradercpp
44
# Published to dockerhub in order to accelerate github actions
55
# Uses:
@@ -70,6 +70,9 @@ RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" > /etc/ap
7070
RUN apt update && apt install -y --no-install-recommends \
7171
clang-format-18 \
7272
clang-tidy-18 \
73+
libc++-18-dev \
74+
libclang-18-dev \
75+
libclang-rt-18-dev \
7376
&& rm -rf /var/lib/apt/lists/*
7477

7578
RUN update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-18 100 && \

Makefile

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ build-release:
5454
test:
5555
cmake --preset debug
5656
cmake --build --preset=debug
57-
ctest --preset=debug
57+
ctest -j$(shell nproc) --preset=debug
5858
lcov --gcov-tool gcov --capture --directory . --output-file lcov.info
5959
source .venv/bin/activate && \
6060
gcovr -r . --exclude 'tests/*' --sonarqube -o sonar-coverage.xml
@@ -63,8 +63,7 @@ test:
6363
.PHONY: tidy
6464
tidy:
6565
find src/ tests/ \( -name '*.cpp' -o -name '*.hpp' -o -name '*.c' -o -name '*.h' \) -exec clang-format -i {} +
66-
find tests/ -name '*.cpp' | xargs clang-tidy -p build/Debug --fix --format-style=.clang-format
67-
find src/ -name '*.cpp' | xargs clang-tidy -p build/Debug --fix --format-style=.clang-format
66+
hooks/check_clang_tidy.sh
6867

6968
## run-debug: 🏃‍♂️ run the app (debug) (don't forget `withenv`)
7069
.PHONY: run-debug
@@ -76,3 +75,21 @@ run-debug:
7675
.PHONY: run-release
7776
run-release:
7877
build/Release/tradercpp
78+
79+
# CONTAINERISATION RECIPES ----------------------------------------------------
80+
81+
## build-container: 🚢 create the docker container for building the app (hosted on dockerhub and ghcr)
82+
.PHONY: build-container
83+
build-container:
84+
IMAGE_VERSION=
85+
@if [ -z "$(IMAGE_VERSION)" ]; then \
86+
echo "Error: IMAGE_VERSION is not set"; \
87+
echo "(you can set it on the command line like so: \`make build-container IMAGE_VERSION=1.7\`)"; \
88+
exit 1; \
89+
fi
90+
docker build -f Dockerfile_build -t milss/tradercppbuild:latest -t milss/tradercppbuild:v$(IMAGE_VERSION) .
91+
92+
## docker: 🚢 create an app docker image
93+
.PHONY: docker
94+
docker:
95+
docker build .

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ NB: this app uses `make` as a recipe book, but it's not essential:
148148
- ✅ coverage gutters
149149
- ✅ dependency injection
150150
- integration test with mocked Binance server
151-
- UI snapshot testing
151+
- FTXUI snapshot testing
152152
- performance
153153
- ✅ store prices and sizes as integrals (ticks as `uint64_t`) for performance
154154
- release compile flags

docs/make-menu.png

-29.2 KB
Loading

hooks/check_clang_tidy.sh

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
# check_clang_tidy.sh
55
# checks for any lint warnings and errors out.
66
# does not modify files in-place.
7+
# uses run-clang-tidy for parallel execution.
78
################################################################
89

910
set -euo pipefail
1011

11-
echo ">> Checking for clang-tidy warnings in src/..."
12+
echo ">> Checking for clang-tidy warnings..."
1213

13-
CLANG_TIDY_BIN="clang-tidy"
14+
CLANG_TIDY_BIN="run-clang-tidy-18"
1415
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1516
BUILD_DIR="$SCRIPT_DIR/../build/Debug"
1617

@@ -20,21 +21,17 @@ if [ ! -f "$BUILD_DIR/compile_commands.json" ]; then
2021
exit 1
2122
fi
2223

23-
files=$(find "$SCRIPT_DIR"/../src/ \( -name '*.cpp' -o -name '*.c' \) | sort)
24-
tidy_errors=0
25-
for file in $files; do
26-
echo "Running clang-tidy on $file"
27-
$CLANG_TIDY_BIN "$file" -p "$BUILD_DIR" > tidy_output.txt 2>&1 || true
28-
if grep -q "warning:" tidy_output.txt; then
29-
echo "clang-tidy warnings found in file, exiting. file: [$file] warnings:"
30-
cat tidy_output.txt
31-
tidy_errors=1
32-
break
33-
fi
34-
done
35-
rm tidy_output.txt
36-
37-
if [ $tidy_errors -ne 0 ]; then
38-
echo "ERROR: clang-tidy found warnings. Try \`make tidy\`"
24+
# Run run-clang-tidy in parallel on src/ and tests/ directories
25+
# no -fix flag to just report warnings/errors
26+
output=$($CLANG_TIDY_BIN -p "$BUILD_DIR" -j "$(nproc)" -header-filter='src/.*|tests/.*' src tests 2>&1) || true
27+
28+
echo "$output"
29+
30+
# Check if output contains any warnings or errors
31+
if echo "$output" | grep -qE "warning:|error:"; then
32+
echo "ERROR: clang-tidy found warnings or errors. Try \`make tidy\`"
3933
exit 1
4034
fi
35+
36+
echo "..."
37+
echo "No clang-tidy warnings found."

src/binance/auth.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class Auth final : public IAuth {
3232

3333
const std::string& get_api_key() const override;
3434

35+
/// Fetch a 32-byte Ed25519 seed from a private key PEM file (using OpenSSL)
36+
/// @return 32-byte Ed25519 seed
37+
std::vector<unsigned char> get_seed_from_pem() const;
38+
3539
void clear_keys() override;
3640

3741
private:
@@ -41,9 +45,6 @@ class Auth final : public IAuth {
4145

4246
std::string& api_key_;
4347
std::string& private_pem_path_;
44-
/// Fetch a 32-byte Ed25519 seed from a private key PEM file (using OpenSSL)
45-
/// @return 32-byte Ed25519 seed
46-
std::vector<unsigned char> get_seed_from_pem() const;
4748
};
4849

4950
} // namespace binance

src/core/bid_ask.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace core {
77
/// @brief basic bid/ask level
88
struct BidAsk {
99
public:
10-
BidAsk() {};
10+
BidAsk() = default;
1111
explicit BidAsk(u_int64_t bidsz, u_int64_t bidpx, u_int64_t askpx, u_int64_t asksz)
1212
: bid_sz(bidsz), bid_px(bidpx), ask_px(askpx), ask_sz(asksz) {}
1313

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ int main() {
2828
b_worker.start();
2929

3030
// ui app (reads from Binance's queues)
31-
auto ui = ui::App::from_env(b_worker.get_order_queue(), b_worker.get_trade_queue(),
32-
b_conf.MAX_DEPTH);
31+
auto ui =
32+
ui::App::from_env(b_worker.get_order_queue(), b_worker.get_trade_queue(), b_conf);
3333
ui.start();
3434

3535
if (ui.thread_exception) {

0 commit comments

Comments
 (0)