Skip to content

Commit

Permalink
add fmt and clippy tests as part of the test process
Browse files Browse the repository at this point in the history
So we don't have to have a separate CI target.
This is easier to reason, and it's a single test
  • Loading branch information
Glauber Costa authored and HippoBaro committed Nov 28, 2021
1 parent d48789e commit 5612d71
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 51 deletions.
63 changes: 12 additions & 51 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@ on:
branches: [ master ]

jobs:
fmt:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Cache setup
uses: ./.github/actions/cache-setup

- name: Install nightly for rustfmt features
run: |
FMT_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/rustfmt)
rustup install nightly
rustup default "$FMT_NIGHTLY"
rustup component add rustfmt
- name: Check formatting
run: cargo fmt --all -- --check

doc:
runs-on: ubuntu-latest

Expand All @@ -50,35 +30,6 @@ jobs:
# - name: Validate links
# run: cargo deadlinks --dir target/doc/glommio

toml:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Cache setup
uses: ./.github/actions/cache-setup

- name: Install cargo-sort
run: cargo install cargo-sort

- name: Sort Cargo.toml
run: cargo sort -w --check

clippy:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Cache setup
uses: ./.github/actions/cache-setup

- name: Run linters
run: cargo clippy --all-targets --all-features -- -D warnings

build:
runs-on: ubuntu-latest

Expand All @@ -102,5 +53,15 @@ jobs:
- name: Cache setup
uses: ./.github/actions/cache-setup

- name: Test all targets
run: sudo bash -c "ulimit -Sl 512 && ulimit -Hl 512 && PATH=$PATH:/usr/share/rust/.cargo/bin && RUSTUP_TOOLCHAIN=stable cargo test --all-features"
- name: Install cargo helpers and test all targets
run: |
cat << EOF > "run-gha-workflow.sh"
PATH=$PATH:/usr/share/rust/.cargo/bin
rustup install nightly
rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu
rustup show
rustup default stable
cargo install cargo-sort
cargo test --all-features
EOF
sudo -E bash -c "ulimit -Sl 512 && ulimit -Hl 512 && bash run-gha-workflow.sh"
49 changes: 49 additions & 0 deletions glommio/tests/linters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the MIT/Apache-2.0 License, at your convenience
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2020
// Datadog, Inc.
#[cfg(test)]
mod tests {
use std::process::Command;
#[test]
fn check_formating() {
let status = Command::new("cargo")
.args(["+nightly", "fmt", "--all", "--", "--check"])
.status()
.unwrap();
assert!(
status.success(),
"cargo fmt failed. Note that glommio uses nightly for formatting, so please invoke \
cargo with +nightly"
);
}

#[test]
fn check_clippy() {
let status = Command::new("cargo")
.args([
"clippy",
"--all-targets",
"--all-features",
"--",
"-D",
"warnings",
])
.status()
.unwrap();
assert!(status.success());
}

#[test]
fn check_dependencies_sorted() {
let status = Command::new("cargo")
.args(["sort", "-w", "-c"])
.status()
.unwrap();
assert!(
status.success(),
"cargo-sort not installed or cargo.toml dependencies not sorted"
);
}
}

0 comments on commit 5612d71

Please sign in to comment.