forked from Chrisland58/SorobanPay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (82 loc) · 3.57 KB
/
Copy pathMakefile
File metadata and controls
94 lines (82 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
FRONTEND_DIR := frontend
CONTRACT_DIR := contracts/subscription
TARGET_DIR := contracts/target
WASM_PATH := $(TARGET_DIR)/wasm32-unknown-unknown/release/soroban_subscription_contract.wasm
# Supported triple → environment variables used by build/test recipes
TARGET_TRIPLE ?= wasm32-unknown-unknown
PROFILE ?= release
ARTIFACT_NAME ?= soroban_subscription_contract
ARTIFACT_PATH = $(TARGET_DIR)/$(TARGET_TRIPLE)/$(PROFILE)/$(ARTIFACT_NAME).wasm
CARGO_FLAGS = --manifest-path $(CONTRACT_DIR)/Cargo.toml --target $(TARGET_TRIPLE) --$(PROFILE)
# Issue #432: Coverage threshold (95% line coverage required)
COVERAGE_THRESHOLD ?= 95
.PHONY: build test test-coverage coverage clean test-frontend
# build: Compile the contract to WASM using the current $(TARGET_TRIPLE) and $(PROFILE)
# Override at the command line, e.g.:
# make build TARGET_TRIPLE=wasm32-unknown-unknown PROFILE=release
# Add new triple:
# 1) rustup target add <triple>
# 2) make build TARGET_TRIPLE=<triple>
build:
cargo build $(CARGO_FLAGS)
@test -f "$(ARTIFACT_PATH)" || \
(echo "ERROR: WASM artifact not found at $(ARTIFACT_PATH)" >&2; exit 1)
# test: Run cargo tests for the contract (native host test, not WASM)
# Note: cargo test cannot cross-compile to WASM; keep this target native.
test:
cargo test --manifest-path $(CONTRACT_DIR)/Cargo.toml
# test-coverage / coverage: Run contract tests with llvm-cov.
#
# Generates:
# contracts/target/lcov.info — LCOV data for Codecov / CI badge
# contracts/target/coverage-html/ — Human-readable HTML report
#
# Then enforces the $(COVERAGE_THRESHOLD)% line-coverage threshold.
# Fails with a non-zero exit code if coverage is below the threshold.
#
# Requires: cargo install cargo-llvm-cov
test-coverage: coverage
coverage:
@echo "Running contract tests with coverage instrumentation…"
cargo llvm-cov \
--manifest-path $(CONTRACT_DIR)/Cargo.toml \
--lcov --output-path $(TARGET_DIR)/lcov.info
cargo llvm-cov \
--manifest-path $(CONTRACT_DIR)/Cargo.toml \
--html --output-dir $(TARGET_DIR)/coverage-html
@echo ""
@echo "Coverage report: $(TARGET_DIR)/coverage-html/index.html"
@echo "LCOV data: $(TARGET_DIR)/lcov.info"
@echo ""
@$(MAKE) _check-coverage-threshold
# Internal target: parse lcov.info and enforce the threshold.
# Separated so CI can also call it after uploading reports.
_check-coverage-threshold:
@LCOV_FILE="$(TARGET_DIR)/lcov.info"; \
if [ ! -f "$$LCOV_FILE" ]; then \
echo "ERROR: $$LCOV_FILE not found. Run 'make coverage' first." >&2; \
exit 1; \
fi; \
FOUND=$$(grep -E "^LF:" "$$LCOV_FILE" | awk -F: '{sum += $$2} END {print sum}'); \
HIT=$$(grep -E "^LH:" "$$LCOV_FILE" | awk -F: '{sum += $$2} END {print sum}'); \
if [ -z "$$FOUND" ] || [ "$$FOUND" -eq 0 ]; then \
echo "ERROR: No coverage data in $$LCOV_FILE" >&2; \
exit 1; \
fi; \
PCT=$$(echo "scale=2; $$HIT * 100 / $$FOUND" | bc); \
echo "Line coverage: $${PCT}% ($${HIT}/$${FOUND} lines)"; \
PASS=$$(echo "$$PCT" | awk '{print ($$1 >= $(COVERAGE_THRESHOLD)) ? "yes" : "no"}'); \
if [ "$$PASS" != "yes" ]; then \
echo "FAIL: $${PCT}% is below the required $(COVERAGE_THRESHOLD)% threshold." >&2; \
exit 1; \
fi; \
echo "PASS: $${PCT}% meets the $(COVERAGE_THRESHOLD)% threshold."
# clean: Remove all build artifacts for the contract
clean:
cargo clean --manifest-path $(CONTRACT_DIR)/Cargo.toml
# test-frontend: Run the frontend Jest test suite (unit + coverage)
test-frontend:
cd $(FRONTEND_DIR) && npm run test
# test-frontend-coverage: Run the frontend Jest suite with coverage report
test-frontend-coverage:
cd $(FRONTEND_DIR) && npm run test:coverage