Skip to content
This repository was archived by the owner on Mar 2, 2020. It is now read-only.

Commit 350e77c

Browse files
authored
Merge pull request #204 from pi-hole/feature/code-coverage
Add code coverage to CI
2 parents d4cc463 + 1e98676 commit 350e77c

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

.circleci/config.yml

+21-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ version: 2
99
keys:
1010
# Find a cache corresponding to this specific target and Cargo.lock checksum.
1111
# There are two dashes used between job and checksum to avoid x86_64 using the x86_64-musl cache
12-
- v3-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }}
12+
- v4-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }}
1313
- run:
1414
name: "Download Web"
1515
command: |
@@ -52,7 +52,24 @@ version: 2
5252
- run:
5353
name: "Test"
5454
command: |
55-
[[ "$CIRCLE_JOB" != "x86_64-musl" ]] || time cargo test --release --target $TARGET
55+
if [[ "$CIRCLE_JOB" != "x86_64-musl" ]]; then
56+
exit 0
57+
fi
58+
59+
# These flags are used so the test results can be used for code coverage
60+
export CARGO_INCREMENTAL=0
61+
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Zno-landing-pads"
62+
63+
time cargo test
64+
- run:
65+
name: "Upload Code Coverage"
66+
command: |
67+
if [[ "$CIRCLE_JOB" != "x86_64-musl" ]]; then
68+
exit 0
69+
fi
70+
71+
grcov target -t lcov --branch --ignore-not-existing --ignore-dir "/*" --ignore-dir "*build.rs" -o lcov.info
72+
bash <(curl -s https://codecov.io/bash) -f lcov.info
5673
- run:
5774
name: "Build DEB"
5875
command: |
@@ -61,7 +78,7 @@ version: 2
6178
mv ../pihole-api*.deb .
6279
[[ "$CIRCLE_JOB" != "arm" ]] || for file in pihole-api*.deb; do mv $file ${file//armhf/arm}; done
6380
- run:
64-
name: "Upload"
81+
name: "Upload Artifacts"
6582
command: |
6683
[[ -z "$FTL_SECRET" || "$CIRCLE_PR_NUMBER" != "" ]] && exit 0
6784
DIR="${CIRCLE_TAG:-${CIRCLE_BRANCH}}"
@@ -89,7 +106,7 @@ version: 2
89106
- debian/pihole-API.service
90107
- rpm/pihole-api.spec
91108
- save_cache:
92-
key: v3-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }}
109+
key: v4-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }}
93110
paths:
94111
- target
95112
- /root/.cargo

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ CMakeLists.txt
1616
.idea
1717
!.idea/codeStyles/*
1818
!.idea/codeStyleSettings.xml
19+
20+
### Testing
21+
# Code coverage info file
22+
lcov.info
23+
24+
# Code coverage HTML report
25+
/report/

docker/x86_64-musl/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ RUN apt-get update && \
1111

1212
ENV PATH="/root/.cargo/bin:$PATH"
1313

14-
RUN rustup component add rustfmt clippy
14+
RUN rustup component add rustfmt clippy && \
15+
cargo install grcov
1516

1617
# Install ghr for GitHub Releases: https://github.com/tcnksm/ghr
1718
RUN curl -L -o ghr.tar.gz https://github.com/tcnksm/ghr/releases/download/v0.12.0/ghr_v0.12.0_linux_amd64.tar.gz && \

src/service.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! implement. The code which uses the service references it as a trait object.
1616
//!
1717
//! Example:
18-
//! ```
18+
//! ```rust,ignore
1919
//! trait MyService {
2020
//! fn something(&self);
2121
//! }
@@ -51,7 +51,7 @@ use rocket::State;
5151
/// the request guard which will be created.
5252
///
5353
/// Example:
54-
/// ```
54+
/// ```rust,ignore
5555
/// service!(MyServiceGuard, MyService, MyServiceImpl, MyServiceMock);
5656
///
5757
/// // Now you can use the guard

0 commit comments

Comments
 (0)