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

Add code coverage to CI #204

Merged
merged 8 commits into from
Jul 27, 2019
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
25 changes: 21 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: 2
keys:
# Find a cache corresponding to this specific target and Cargo.lock checksum.
# There are two dashes used between job and checksum to avoid x86_64 using the x86_64-musl cache
- v3-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }}
- v4-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }}
- run:
name: "Download Web"
command: |
Expand Down Expand Up @@ -52,7 +52,24 @@ version: 2
- run:
name: "Test"
command: |
[[ "$CIRCLE_JOB" != "x86_64-musl" ]] || time cargo test --release --target $TARGET
if [[ "$CIRCLE_JOB" != "x86_64-musl" ]]; then
exit 0
fi

# These flags are used so the test results can be used for code coverage
export CARGO_INCREMENTAL=0
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Zno-landing-pads"

time cargo test
- run:
name: "Upload Code Coverage"
command: |
if [[ "$CIRCLE_JOB" != "x86_64-musl" ]]; then
exit 0
fi

grcov target -t lcov --branch --ignore-not-existing --ignore-dir "/*" --ignore-dir "*build.rs" -o lcov.info
bash <(curl -s https://codecov.io/bash) -f lcov.info
- run:
name: "Build DEB"
command: |
Expand All @@ -61,7 +78,7 @@ version: 2
mv ../pihole-api*.deb .
[[ "$CIRCLE_JOB" != "arm" ]] || for file in pihole-api*.deb; do mv $file ${file//armhf/arm}; done
- run:
name: "Upload"
name: "Upload Artifacts"
command: |
[[ -z "$FTL_SECRET" || "$CIRCLE_PR_NUMBER" != "" ]] && exit 0
DIR="${CIRCLE_TAG:-${CIRCLE_BRANCH}}"
Expand Down Expand Up @@ -89,7 +106,7 @@ version: 2
- debian/pihole-API.service
- rpm/pihole-api.spec
- save_cache:
key: v3-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }}
key: v4-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }}
paths:
- target
- /root/.cargo
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ CMakeLists.txt
.idea
!.idea/codeStyles/*
!.idea/codeStyleSettings.xml

### Testing
# Code coverage info file
lcov.info

# Code coverage HTML report
/report/
3 changes: 2 additions & 1 deletion docker/x86_64-musl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ RUN apt-get update && \

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

RUN rustup component add rustfmt clippy
RUN rustup component add rustfmt clippy && \
cargo install grcov

# Install ghr for GitHub Releases: https://github.com/tcnksm/ghr
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 && \
Expand Down
4 changes: 2 additions & 2 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! implement. The code which uses the service references it as a trait object.
//!
//! Example:
//! ```
//! ```rust,ignore
//! trait MyService {
//! fn something(&self);
//! }
Expand Down Expand Up @@ -51,7 +51,7 @@ use rocket::State;
/// the request guard which will be created.
///
/// Example:
/// ```
/// ```rust,ignore
/// service!(MyServiceGuard, MyService, MyServiceImpl, MyServiceMock);
///
/// // Now you can use the guard
Expand Down