|
1 | 1 | use anyhow::{anyhow, Context, Result}; |
2 | 2 | use assert_cmd::prelude::*; |
3 | 3 | use cargo_metadata::{Dependency, MetadataCommand}; |
4 | | -use dylint_internal::{rustup::SanitizeEnvironment, CommandExt}; |
| 4 | +use dylint_internal::{clone, env::enabled, rustup::SanitizeEnvironment, CommandExt}; |
5 | 5 | use predicates::prelude::*; |
6 | 6 | use regex::Regex; |
7 | 7 | use semver::Version; |
8 | | -use std::{fs::read_to_string, path::Path}; |
| 8 | +use std::{ |
| 9 | + fs::read_to_string, |
| 10 | + io::{stderr, Write}, |
| 11 | + path::Path, |
| 12 | +}; |
9 | 13 | use tempfile::tempdir; |
10 | 14 |
|
11 | 15 | // smoelius: I expected `git2-0.17.2` to build with nightly-2022-06-30, which corresponds to |
@@ -139,6 +143,62 @@ fn downgrade_upgrade_package() { |
139 | 143 | .unwrap(); |
140 | 144 | } |
141 | 145 |
|
| 146 | +const DYLINT_URL: &str = "https://github.com/trailofbits/dylint"; |
| 147 | + |
| 148 | +// smoelius: Each of the following commits is just before an "Upgrade examples" commit. In the |
| 149 | +// upgrades, the changes to the `restriction` lints are small. Thus, the auto-correct option should |
| 150 | +// be able to generate fixes for them. |
| 151 | +const REVS_AND_RUST_VERSIONS: &[(&str, &str)] = &[ |
| 152 | + // smoelius: "Upgrade examples" commit: |
| 153 | + // https://github.com/trailofbits/dylint/commit/33969746aef6947c68d7adb55137ce8a13d9cc47 |
| 154 | + ("5b3792515ac255fdb06a31b10eb3c9f7949a3ed5", "1.80.0"), |
| 155 | + // smoelius: "Upgrade examples" commit: |
| 156 | + // https://github.com/trailofbits/dylint/commit/7bc453f0778dee3b13bc1063773774304ac96cad |
| 157 | + ("23c08c8a0b043d26f66653bf173a0e6722a2d699", "1.79.0"), |
| 158 | +]; |
| 159 | + |
| 160 | +#[test] |
| 161 | +fn upgrade_with_auto_correct() { |
| 162 | + for (rev, rust_version) in REVS_AND_RUST_VERSIONS { |
| 163 | + let tempdir = tempdir().unwrap(); |
| 164 | + |
| 165 | + clone(DYLINT_URL, rev, tempdir.path(), false).unwrap(); |
| 166 | + |
| 167 | + let mut command = std::process::Command::cargo_bin("cargo-dylint").unwrap(); |
| 168 | + command.args([ |
| 169 | + "dylint", |
| 170 | + "upgrade", |
| 171 | + &tempdir |
| 172 | + .path() |
| 173 | + .join("examples/restriction") |
| 174 | + .to_string_lossy(), |
| 175 | + "--auto-correct", |
| 176 | + "--rust-version", |
| 177 | + rust_version, |
| 178 | + ]); |
| 179 | + command.success().unwrap(); |
| 180 | + |
| 181 | + if enabled("DEBUG_DIFF") { |
| 182 | + let mut command = std::process::Command::new("git"); |
| 183 | + command.current_dir(&tempdir); |
| 184 | + command.args(["--no-pager", "diff", "--", "*.rs"]); |
| 185 | + command.success().unwrap(); |
| 186 | + } |
| 187 | + |
| 188 | + dylint_internal::cargo::check("auto-corrected, upgraded library package") |
| 189 | + .build() |
| 190 | + .sanitize_environment() |
| 191 | + .current_dir(tempdir.path().join("examples/restriction")) |
| 192 | + .env("RUSTFLAGS", "--allow=warnings") |
| 193 | + .arg("--quiet") |
| 194 | + .success() |
| 195 | + .unwrap(); |
| 196 | + |
| 197 | + #[allow(clippy::explicit_write)] |
| 198 | + writeln!(stderr(), "Success").unwrap(); |
| 199 | + } |
| 200 | +} |
| 201 | + |
142 | 202 | #[allow(dead_code)] |
143 | 203 | fn rust_version(path: &Path) -> Result<Version> { |
144 | 204 | let re = Regex::new(r#"^clippy_utils = .*\btag = "rust-([^"]*)""#).unwrap(); |
|
0 commit comments