From 972931b1cccbd9ecd3cb528f0a4f6093789b3118 Mon Sep 17 00:00:00 2001 From: aon <21188659+aon@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:34:54 -0300 Subject: [PATCH] Improve CI tests --- .github/workflows/general-rust.yml | 73 ++++++++++--------- .../tests/integration_test.rs | 11 +++ 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/.github/workflows/general-rust.yml b/.github/workflows/general-rust.yml index e5093145..e4787225 100644 --- a/.github/workflows/general-rust.yml +++ b/.github/workflows/general-rust.yml @@ -21,48 +21,49 @@ env: CARGO_TERM_COLOR: always jobs: - # test: - # name: Test - # runs-on: ubuntu-latest - # steps: - # - name: Checkout repository - # uses: actions/checkout@v3 - - # - name: Cache cargo-scout dependencies - # id: cache-cargo-scout-dependencies - # uses: actions/cache@v3 - # with: - # path: ./apps/cargo-scout-audit/target - # key: ${{ runner.os }}-cargo-${{ hashFiles('apps/cargo-scout-audit/Cargo.lock') }} - - # - name: Cache other dependencies - # id: cache-other-dependencies - # uses: actions/cache@v3 - # with: - # path: | - # ~/.cargo/registry - # ~/.cargo/git - # ./detectors/**/target - # ./test-cases/**/target - # key: ${{ runner.os }}-other-dependencies + scout-audit-test: + name: Test Scout Audit + runs-on: ubuntu-latest + strategy: + matrix: + test: ["panic-error"] + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Cache cargo-scout dependencies + id: cache-cargo-scout-dependencies + uses: actions/cache@v3 + with: + path: ./apps/cargo-scout-audit/target + key: ${{ runner.os }}-cargo-${{ hashFiles('apps/cargo-scout-audit/Cargo.lock') }} + + - name: Cache other dependencies + id: cache-other-dependencies + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-other-dependencies - # - name: Update Rust - # run: rustup update + - name: Update Rust + run: rustup update - # - name: Install Rust nightly-2023-01-27 - # run: rustup install nightly-2023-01-27 --profile minimal + - name: Install Rust nightly-2023-01-27 + run: rustup install nightly-2023-01-27 --profile minimal - # - name: Install Rust nightly-2023-04-23 - # run: rustup install nightly-2023-04-23 --profile minimal + - name: Install Rust nightly-2023-04-23 + run: rustup install nightly-2023-04-23 --profile minimal - # - name: Install dylint-link - # run: cargo install dylint-link + - name: Install dylint-link + run: cargo install dylint-link - # - name: Install cargo-scout - # run: cargo install --path apps/cargo-scout-audit + - name: Install cargo-scout + run: cargo install --path apps/cargo-scout-audit - # - name: Run cargo test - # run: make test + - name: Run tests + run: INTEGRATION_TESTS_TO_RUN=${{ matrix.test }} cargo test -- --nocapture fmt: name: Rustfmt diff --git a/apps/cargo-scout-audit/tests/integration_test.rs b/apps/cargo-scout-audit/tests/integration_test.rs index 63283000..2278a166 100644 --- a/apps/cargo-scout-audit/tests/integration_test.rs +++ b/apps/cargo-scout-audit/tests/integration_test.rs @@ -39,11 +39,22 @@ fn test() { print_cargo_scout_not_found() ); + // Get environment variable to determine integration tests to run + let integration_tests_to_run = std::env::var("INTEGRATION_TESTS_TO_RUN") + .ok() + .map(|e| e.split(',').map(|s| s.to_string()).collect::>()); + // Get the configuration let configuration = get_configuration() .unwrap_or_else(|_| panic!("{}", "Failed to get the configuration".red().to_string())); for (detector_name, detector_config) in configuration.detectors.iter() { + if let Some(integration_tests_to_run) = &integration_tests_to_run { + if !integration_tests_to_run.contains(&detector_name) { + continue; + } + } + println!("\n{} {}", "Running detector:".bright_cyan(), detector_name); for example in detector_config.examples.iter() { execute_and_validate_example(