Skip to content

Commit

Permalink
Reorganize expensive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Sep 8, 2024
1 parent 1d97137 commit aba051e
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 96 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: CI
on:
merge_group:
pull_request:
schedule:
- cron: "0 3 * * tue"
workflow_dispatch:

concurrency:
Expand Down Expand Up @@ -98,8 +100,6 @@ jobs:
environment: [ubuntu-latest, macos-latest, windows-latest]
package: [cargo-dylint, cargo-dylint-cargo-lib, dylint_examples, other]
include:
- environment: ubuntu-latest
package: alpine
- environment: ubuntu-latest
package: cargo-dylint-ci

Expand Down Expand Up @@ -180,7 +180,12 @@ jobs:
elif [[ '${{ matrix.package }}' != 'other' ]]; then
cargo test -p '${{ matrix.package }}' -- --nocapture
else
cargo test --all-features --workspace --exclude cargo-dylint --exclude dylint_examples --exclude alpine -- --nocapture
EXCLUDE_EXPENSIVE=
if [[ '${{ github.event_name }}' != 'schedule' && '${{ github.event_name }}' != 'workflow_dispatch' ]]; then
EXCLUDE_EXPENSIVE='--exclude expensive'
fi
# shellcheck disable=SC2086
cargo test --all-features --workspace --exclude cargo-dylint --exclude dylint_examples $EXCLUDE_EXPENSIVE -- --nocapture
pushd driver
cargo test --all-features -- --nocapture
Expand Down
13 changes: 9 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ members = [
"dylint",
"dylint-link",
"examples",
"expensive",
"internal",
"tests/alpine",
# "utils/linting",
"utils/testing",
]
Expand Down
62 changes: 0 additions & 62 deletions cargo-dylint/tests/custom_toolchain.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2505,13 +2505,13 @@
"not_audited": {
"foreign_crates": [],
"local_crates": [
"alpine",
"cargo-dylint",
"dylint",
"dylint-link",
"dylint_examples",
"dylint_internal",
"dylint_testing"
"dylint_testing",
"expensive"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2505,13 +2505,13 @@
"not_audited": {
"foreign_crates": [],
"local_crates": [
"alpine",
"cargo-dylint",
"dylint",
"dylint-link",
"dylint_examples",
"dylint_internal",
"dylint_testing"
"dylint_testing",
"expensive"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2424,13 +2424,13 @@
"not_audited": {
"foreign_crates": [],
"local_crates": [
"alpine",
"cargo-dylint",
"dylint",
"dylint-link",
"dylint_examples",
"dylint_internal",
"dylint_testing"
"dylint_testing",
"expensive"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2470,13 +2470,13 @@
"not_audited": {
"foreign_crates": [],
"local_crates": [
"alpine",
"cargo-dylint",
"dylint",
"dylint-link",
"dylint_examples",
"dylint_internal",
"dylint_testing"
"dylint_testing",
"expensive"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4625,13 +4625,13 @@
"not_audited": {
"foreign_crates": [],
"local_crates": [
"alpine",
"cargo-dylint",
"dylint",
"dylint-link",
"dylint_examples",
"dylint_internal",
"dylint_testing"
"dylint_testing",
"expensive"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4625,13 +4625,13 @@
"not_audited": {
"foreign_crates": [],
"local_crates": [
"alpine",
"cargo-dylint",
"dylint",
"dylint-link",
"dylint_examples",
"dylint_internal",
"dylint_testing"
"dylint_testing",
"expensive"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4541,13 +4541,13 @@
"not_audited": {
"foreign_crates": [],
"local_crates": [
"alpine",
"cargo-dylint",
"dylint",
"dylint-link",
"dylint_examples",
"dylint_internal",
"dylint_testing"
"dylint_testing",
"expensive"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4571,13 +4571,13 @@
"not_audited": {
"foreign_crates": [],
"local_crates": [
"alpine",
"cargo-dylint",
"dylint",
"dylint-link",
"dylint_examples",
"dylint_internal",
"dylint_testing"
"dylint_testing",
"expensive"
]
}
}
19 changes: 19 additions & 0 deletions expensive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "expensive"
version = "3.1.2"
edition = "2021"
publish = false

[dev-dependencies]
anyhow = "1.0"
tempfile = "3.12"

dylint_internal = { version = "=3.1.2", path = "../internal", features = [
"clippy_utils",
"rustup",
"sed",
"testing",
] }

[lints]
workspace = true
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/alpine/tests/alpine.rs → expensive/tests/alpine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fn alpine() {
"build",
"--progress=plain",
"-f",
"tests/alpine/Dockerfile",
"expensive/tests/Dockerfile",
".",
])
.current_dir("../..")
.current_dir("..")
.status()
.unwrap();
assert!(status.success());
Expand Down
90 changes: 90 additions & 0 deletions expensive/tests/custom_toolchain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// smoelius: As per `dylint-link/src/main.rs`:
// "Only the MSVC toolchain is supported on Windows"
#![cfg(not(target_os = "windows"))]

use anyhow::{anyhow, Context, Result};
use dylint_internal::{
clippy_utils::set_toolchain_channel, find_and_replace, rustup::SanitizeEnvironment,
testing::new_template, CommandExt,
};
use std::{path::Path, process::Command};
use tempfile::{tempdir, NamedTempFile, TempDir};

const RUST_URL: &str = "https://github.com/rust-lang/rust";

#[test]
fn custom_toolchain() {
let tempdir = tempdir().unwrap();

new_template(tempdir.path()).unwrap();

let (_toolchain_dir, custom_toolchain) = build_custom_toolchain().unwrap();

patch_dylint_template(tempdir.path(), &custom_toolchain).unwrap();

dylint_internal::cargo::test(&format!("with custom toolchain `{custom_toolchain}`"))
.build()
.sanitize_environment()
.current_dir(&tempdir)
.success()
.unwrap();

uninstall_toolchain(&custom_toolchain).unwrap();
}

fn build_custom_toolchain() -> Result<(TempDir, String)> {
let tempdir = tempdir().unwrap();

Command::new("git")
.args([
"clone",
"--depth=1",
RUST_URL,
&tempdir.path().to_string_lossy(),
])
.success()?;

// smoelius: Build the stage 2 compiler. This makes the `rustc_private` crates available for the
// stage 1 compiler.
Command::new("./x.py")
.current_dir(&tempdir)
.args(["build", "--stage=2"])
.success()?;

let toolchain = random_string()?;

// smoelius: Return a link to the stage 1 compiler.
Command::new("rustup")
.current_dir(&tempdir)
.args([
"toolchain",
"link",
&toolchain,
"build/x86_64-unknown-linux-gnu/stage1",
])
.success()?;

Ok((tempdir, toolchain))
}

fn random_string() -> Result<String> {
let tempfile = NamedTempFile::new().with_context(|| "Could not create named temp file")?;
tempfile
.path()
.file_name()
.map(|s| s.to_string_lossy().trim_start_matches('.').to_string())
.ok_or_else(|| anyhow!("Could not get file name"))
}

fn patch_dylint_template(path: &Path, channel: &str) -> Result<()> {
// smoelius: `clippy_utils` may not build with the new toolchain.
find_and_replace(&path.join("Cargo.toml"), "\r?\nclippy_utils = [^\r\n]*", "")?;

set_toolchain_channel(path, channel)
}

fn uninstall_toolchain(toolchain: &str) -> Result<()> {
Command::new("rustup")
.args(["toolchain", "uninstall", toolchain])
.success()
}
Loading

0 comments on commit aba051e

Please sign in to comment.