Skip to content

Commit

Permalink
Move some tests into a scheduled package
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Feb 11, 2025
1 parent 39afc81 commit d61ce1b
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 147 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ jobs:
;;
cargo-dylint-ci)
cargo test -p cargo-dylint --test ci
if [[ '${{ github.event_name }}' = 'schedule' || '${{ github.event_name }}' = 'workflow_dispatch' ]] ||
git diff --name-only ${{ github.event.pull_request.base.sha }} | grep -w 'scheduled'
then
cargo test -p scheduled
fi
;;
*)
exit 1
Expand All @@ -215,7 +220,7 @@ jobs:
fi
cargo test -p "$PACKAGE" "$TEST" -- --nocapture
else
cargo test --all-features --workspace --exclude cargo-dylint --exclude dylint_examples --exclude expensive -- --nocapture
cargo test --all-features --workspace --exclude cargo-dylint --exclude dylint_examples --exclude expensive --exclude scheduled -- --nocapture
pushd driver
cargo test --all-features -- --nocapture
Expand Down
14 changes: 14 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"examples",
"expensive",
"internal",
"scheduled",
# "utils/linting",
"utils/testing",
]
Expand Down
143 changes: 1 addition & 142 deletions cargo-dylint/tests/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@ use std::{
fmt::Write as _,
fs::{read_dir, read_to_string, write},
io::{stderr, Write as _},
path::{Component, Path, PathBuf},
process,
str::FromStr,
path::{Component, Path},
sync::Mutex,
};

const TARGETS: [&str; 4] = [
"aarch64-apple-darwin",
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
];

static METADATA: Lazy<Metadata> = Lazy::new(|| current_metadata().unwrap());

#[ctor::ctor]
Expand Down Expand Up @@ -229,71 +220,6 @@ fn format_util_readmes() {
});
}

#[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))]
#[test]
fn duplicate_dependencies() {
for target in TARGETS {
let mut command = Command::new("cargo");
command.args(["tree", "--duplicates", "--target", target]);
let assert = command.assert().success();

let stdout_actual = std::str::from_utf8(&assert.get_output().stdout).unwrap();
let package_versions = stdout_actual
.lines()
.filter(|line| line.chars().next().is_some_and(char::is_alphabetic))
.map(|line| {
<[_; 2]>::try_from(line.split_ascii_whitespace().take(2).collect::<Vec<_>>())
.unwrap()
})
.collect::<Vec<_>>();
#[allow(clippy::format_collect)]
let stdout_filtered = {
const PACKAGE: usize = 0;
const VERSION: usize = 1;
let mut package_versions_filtered = package_versions
.windows(2)
.filter(|w| w[0][PACKAGE] == w[1][PACKAGE])
.filter(|w| w[0][VERSION] != w[1][VERSION])
.flatten()
.collect::<Vec<_>>();
// smoelius: If `package_versions` contains three versions of a package, then
// `package_versions_filtered` will contain:
// ```
// package version-0
// package version-1
// package version-1
// package version-2
// ```
package_versions_filtered.dedup();
package_versions_filtered
.into_iter()
.map(|package_version| {
format!(
"{} {}\n",
package_version[PACKAGE], package_version[VERSION]
)
})
.collect::<String>()
};

let path = PathBuf::from(format!(
"cargo-dylint/tests/duplicate_dependencies/{target}.txt"
));

let stdout_expected = read_to_string(&path).unwrap();

if env::enabled("BLESS") {
write(path, stdout_filtered).unwrap();
} else {
assert!(
stdout_expected == stdout_filtered,
"{}",
SimpleDiff::from_str(&stdout_expected, &stdout_filtered, "left", "right")
);
}
}
}

#[test]
fn hack_feature_powerset_udeps() {
Command::new("rustup")
Expand Down Expand Up @@ -577,65 +503,6 @@ fn sort() {
}
}

// smoelius: `supply_chain` is the only test that uses `supply_chain.json`. So there is no race.
#[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))]
#[test]
fn supply_chain() {
let mut command = process::Command::new("cargo");
command.args(["supply-chain", "update", "--cache-max-age=0s"]);
let _: process::ExitStatus = command.status().unwrap();

for target in TARGETS {
let mut command = Command::new("cargo");
command.args(["supply-chain", "json", "--no-dev", "--target", target]);
let assert = command.assert().success();

let stdout_actual = std::str::from_utf8(&assert.get_output().stdout).unwrap();
// smoelius: Sanity. (I have nothing against Redox OS.)
assert!(!stdout_actual.contains("redox"));
let mut value = serde_json::Value::from_str(stdout_actual).unwrap();
remove_avatars(&mut value);
let stdout_normalized = serde_json::to_string_pretty(&value).unwrap();

let path = PathBuf::from(format!("cargo-dylint/tests/supply_chain/{target}.json"));

let stdout_expected = read_to_string(&path).unwrap();

if env::enabled("BLESS") {
write(path, stdout_normalized).unwrap();
} else {
assert!(
stdout_expected == stdout_normalized,
"{}",
SimpleDiff::from_str(&stdout_expected, &stdout_normalized, "left", "right")
);
}
}
}

fn remove_avatars(value: &mut serde_json::Value) {
match value {
serde_json::Value::Null
| serde_json::Value::Bool(_)
| serde_json::Value::Number(_)
| serde_json::Value::String(_) => {}
serde_json::Value::Array(array) => {
for value in array {
remove_avatars(value);
}
}
serde_json::Value::Object(object) => {
object.retain(|key, value| {
if key == "avatar" {
return false;
}
remove_avatars(value);
true
});
}
}
}

#[test]
fn update() {
preserves_cleanliness("update", false, || {
Expand All @@ -656,14 +523,6 @@ fn update() {
});
}

#[test]
fn unmaintained() {
Command::new("cargo")
.args(["unmaintained", "--color=never", "--fail-fast"])
.assert()
.success();
}

fn readme_contents(dir: impl AsRef<Path>) -> Result<String> {
read_to_string(dir.as_ref().join("README.md")).map_err(Into::into)
}
Expand Down
22 changes: 22 additions & 0 deletions scheduled/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "scheduled"
description = "Scheduled tests"
version = "3.5.0"
edition = "2021"
publish = false

[dependencies]

[dev-dependencies]
anyhow = { workspace = true }
assert_cmd = { workspace = true }
once_cell = { workspace = true }
predicates = { workspace = true }
regex = { workspace = true }
serde_json = { workspace = true }
similar-asserts = { workspace = true }

dylint_internal = { version = "=3.5.0", path = "../internal" }

[lints]
workspace = true
1 change: 1 addition & 0 deletions scheduled/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
Expand Up @@ -2636,7 +2636,8 @@
"dylint_examples",
"dylint_internal",
"dylint_testing",
"expensive"
"expensive",
"scheduled"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2636,7 +2636,8 @@
"dylint_examples",
"dylint_internal",
"dylint_testing",
"expensive"
"expensive",
"scheduled"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2580,7 +2580,8 @@
"dylint_examples",
"dylint_internal",
"dylint_testing",
"expensive"
"expensive",
"scheduled"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,8 @@
"dylint_examples",
"dylint_internal",
"dylint_testing",
"expensive"
"expensive",
"scheduled"
]
}
}
Loading

0 comments on commit d61ce1b

Please sign in to comment.