From 3f3f68dcaf84c764fbb2e312b8894d7e4f8ddb1e Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Thu, 26 Sep 2024 10:23:19 +0200 Subject: [PATCH] ci work --- .github/workflows/ci.yml | 53 ++++++++++++++++++++++++++++++- examples/simple.rs | 4 --- output.txt | 16 ++++++++++ tests/check-expect-supported.out | 17 ++++++++++ tests/clippy-expect-supported.out | 28 ++++++++++++++++ tests/compare-output.sh | 10 ++++++ tests/simple.rs | 41 ++++++++++++++++++++++++ 7 files changed, 164 insertions(+), 5 deletions(-) delete mode 100644 examples/simple.rs create mode 100644 output.txt create mode 100644 tests/check-expect-supported.out create mode 100644 tests/clippy-expect-supported.out create mode 100755 tests/compare-output.sh create mode 100644 tests/simple.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index febc0ad..741b61d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ env: INLINE_IGNORE_PATTERN: "drop_in_place|::fmt::" jobs: - test: + expect: runs-on: ubuntu-latest strategy: matrix: @@ -28,6 +28,53 @@ jobs: "beta", "nightly", ] + env: + CARGO_NET_GIT_FETCH_WITH_CLI: "true" + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.toolchain }} + components: clippy + - name: cargo check --all-targets + shell: bash + run: | + output=$(cargo check --all-targets 2>&1) + echo "$output" > check_output.txt + if ! diff -u tests/check-expect-supported.out check_output.txt; then + echo "Cargo check output does not match expected output" + exit 1 + fi + - name: cargo clean + run: cargo clean + - name: cargo test + run: cargo test --all-targets + - name: cargo clean + run: cargo clean + - name: cargo clippy + shell: bash + run: | + output=$(cargo clippy --all-targets 2>&1) + echo "$output" > clippy_output.txt + if ! diff -u tests/clippy-expect-supported.out clippy_output.txt; then + echo "Cargo clippy output does not match expected output" + exit 1 + fi + - name: Run cargo check comparison + run: ./tests/compare-output.sh "check" "tests/check-expect-supported.out" + - name: cargo clean + run: cargo clean + - name: cargo test + run: cargo test --all-targets + - name: cargo clean + run: cargo clean + - name: Run cargo clippy comparison + run: ./tests/compare-output.sh "clippy" "tests/clippy-expect-supported.out" + allow: + runs-on: ubuntu-latest + strategy: + matrix: + toolchain: ["1.43.0", "1.80.0"] env: RUSTFLAGS: "-D warnings" CARGO_NET_GIT_FETCH_WITH_CLI: "true" @@ -37,6 +84,10 @@ jobs: with: toolchain: ${{ matrix.toolchain }} components: clippy + - name: cargo check + run: cargo check --all-targets + - name: cargo clean + run: cargo clean - name: cargo test run: cargo test --all-targets - name: cargo clean diff --git a/examples/simple.rs b/examples/simple.rs deleted file mode 100644 index 6bc915f..0000000 --- a/examples/simple.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[flexpect::expect(unused_variables)] -fn main() { - let x = 1; -} diff --git a/output.txt b/output.txt new file mode 100644 index 0000000..daaf4ce --- /dev/null +++ b/output.txt @@ -0,0 +1,16 @@ +warning: this lint expectation is unfulfilled + --> tests/simple.rs:15:20 + | +15 | #[flexpect::expect(unused_variables)] + | ^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unfulfilled_lint_expectations)]` on by default + +warning: this lint expectation is unfulfilled + --> tests/simple.rs:18:20 + | +18 | #[flexpect::expect(clippy::clone_on_copy)] + | ^^^^^^^^^^^^^^^^^^^^^ + +warning: `flexpect` (test "simple") generated 2 warnings + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s diff --git a/tests/check-expect-supported.out b/tests/check-expect-supported.out new file mode 100644 index 0000000..cffe9ae --- /dev/null +++ b/tests/check-expect-supported.out @@ -0,0 +1,17 @@ + Checking flexpect v0.0.1 (/Users/hans/dev/flexpect) +warning: this lint expectation is unfulfilled + --> tests/simple.rs:14:20 + | +14 | #[flexpect::expect(unused_variables)] + | ^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unfulfilled_lint_expectations)]` on by default + +warning: this lint expectation is unfulfilled + --> tests/simple.rs:34:20 + | +34 | #[flexpect::expect(unused_variables, clippy::clone_on_copy)] + | ^^^^^^^^^^^^^^^^ + +warning: `flexpect` (test "simple") generated 2 warnings + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s diff --git a/tests/clippy-expect-supported.out b/tests/clippy-expect-supported.out new file mode 100644 index 0000000..808c96a --- /dev/null +++ b/tests/clippy-expect-supported.out @@ -0,0 +1,28 @@ +warning: this lint expectation is unfulfilled + --> tests/simple.rs:14:20 + | +14 | #[flexpect::expect(unused_variables)] + | ^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unfulfilled_lint_expectations)]` on by default + +warning: this lint expectation is unfulfilled + --> tests/simple.rs:17:20 + | +17 | #[flexpect::expect(clippy::clone_on_copy)] + | ^^^^^^^^^^^^^^^^^^^^^ + +warning: this lint expectation is unfulfilled + --> tests/simple.rs:34:20 + | +34 | #[flexpect::expect(unused_variables, clippy::clone_on_copy)] + | ^^^^^^^^^^^^^^^^ + +warning: this lint expectation is unfulfilled + --> tests/simple.rs:34:38 + | +34 | #[flexpect::expect(unused_variables, clippy::clone_on_copy)] + | ^^^^^^^^^^^^^^^^^^^^^ + +warning: `flexpect` (test "simple") generated 4 warnings + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s diff --git a/tests/compare-output.sh b/tests/compare-output.sh new file mode 100755 index 0000000..ad97e75 --- /dev/null +++ b/tests/compare-output.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -euo pipefail +command=$1 +expected_file=$2 +output=$(cargo ${command} 2>&1) +echo "$output" > output.txt +if ! diff -u ${expected_file} output.txt; then +echo "Cargo ${command} output does not match expected output" +exit 1 +fi diff --git a/tests/simple.rs b/tests/simple.rs new file mode 100644 index 0000000..f8a2f40 --- /dev/null +++ b/tests/simple.rs @@ -0,0 +1,41 @@ +#[test] +#[flexpect::expect(unused_variables)] +fn compiler_warning_correctly_flexpected() { + let x = 1; +} + +#[flexpect::expect(clippy::clone_on_copy)] +#[test] +fn clippy_warning_correctly_flexpected() { + let _ = 32.clone(); +} + +#[test] +#[flexpect::expect(unused_variables)] +fn compiler_warning_incorrectly_flexpected() {} + +#[flexpect::expect(clippy::clone_on_copy)] +#[test] +fn clippy_warning_incorrectly_flexpected() {} + +#[flexpect::expect(unused_variables, clippy::clone_on_copy)] +mod submod_correct { + #[test] + fn compiler_warning_correctly_flexpected() { + let x = 1; + } + + #[test] + fn clippy_warning_correctly_flexpected() { + let _ = 32.clone(); + } +} + +#[flexpect::expect(unused_variables, clippy::clone_on_copy)] +mod submod_incorrect { + #[test] + fn compiler_warning_incorrectly_flexpected() {} + + #[test] + fn clippy_warning_incorrectly_flexpected() {} +}