Rust lint and coverage on Travis

This commit is contained in:
Guy Taylor
2019-02-21 19:45:27 +00:00
parent 39e6baa9c0
commit b5ff80a541
3 changed files with 102 additions and 13 deletions

View File

@@ -1,19 +1,64 @@
language: rust
os:
- linux
- osx
dist: xenial
sudo: false
addons:
apt:
packages:
# necessary for kcov
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- libiberty-dev
- binutils-dev
- cmake
- gcc
language: rust
rust:
- stable
- nightly
before_script:
- pip2 install 'travis-cargo<0.2' --user && export PATH=$HOME/Library/Python/2.7/bin:$HOME/.local/bin:$PATH
script:
- travis-cargo test
- travis-cargo build -- --manifest-path examples/drive_example/Cargo.toml
- travis-cargo build -- --manifest-path examples/service_account/Cargo.toml
- travis-cargo test -- --no-default-features --features no-openssl
after_success:
- "[[ $TRAVIS_OS_NAME = linux ]] && travis-cargo --only stable coveralls"
env:
global:
- TRAVIS_CARGO_NIGHTLY_FEATURE=""
stages:
- name: test
- name: lint
- name: coverage
install: true
# Default script is the "test" stage
script:
- cargo build
- cargo test
- cargo build --manifest-path examples/drive_example/Cargo.toml
- cargo build --manifest-path examples/service_account/Cargo.toml
- cargo test --no-default-features --features no-openssl
jobs:
include:
- stage: lint
if: os = linux
rust: stable
install:
- rustup component add clippy
- rustup component add rustfmt
script:
- cargo fmt --all -- --check || true
- cargo clippy --all-targets --all-features -- -D warnings || true
- stage: coverage
if: os = linux
sudo: true
rust: stable
env:
- RUSTFLAGS="-C link-dead-code -C debuginfo=2 -C opt-level=0"
- CACHE_NAME="coverage"
install:
- ./.travis/install-kcov.sh "v36" "29ccdde3bd44f14e0d7c88d709e1e5ff9b448e735538ae45ee08b73c19a2ea0b" && export PATH="kcov/usr/bin:${PATH}";
script:
- cargo test --no-run
- ./.travis/run-kcov.sh "yup_oauth2"
- bash <(curl -s https://codecov.io/bash) -F "${TRAVIS_RUST_VERSION}"
cache: cargo

29
.travis/install-kcov.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -o verbose
set -o errexit
set -o pipefail
KCOV_VERSION="${1}"
KCOV_SHA256_HASH="${2}"
curl -L --output "kcov.tar.gz" "https://github.com/SimonKagstrom/kcov/archive/${KCOV_VERSION}.tar.gz"
sha256sum "kcov.tar.gz"
echo "${KCOV_SHA256_HASH} kcov.tar.gz" | sha256sum -c
mkdir kcov-src
mkdir kcov
cd kcov-src
tar -xf ../kcov.tar.gz --strip-components=1
rm ../kcov.tar.gz
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ..
make -j 2
make install DESTDIR=../../kcov
cd ../../
rm -r kcov-src
echo "kcov should not be available via 'kcov/usr/bin/kcov'"

15
.travis/run-kcov.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -o verbose
set -o errexit
set -o pipefail
PROGRAM_NAME="${1}"
echo "Coverage testing of ${PROGRAM_NAME}"
for file in target/debug/${PROGRAM_NAME}-*; do
[ -x "${file}" ] || continue
mkdir -p "target/cov/$(basename ${file})";
kcov --exclude-pattern='/.cargo,/usr/lib' --verify "target/cov/$(basename ${file})" "${file}";
done