|
| 1 | +use std::process::{Command, Output}; |
| 2 | + |
| 3 | +const VERSIONS: [&str; 7] = [ |
| 4 | + "2.3.5", "2.3.4", "2.3.3", "2.3.2", "2.3.1", "2.2.0", "2.1.0", |
| 5 | +]; |
| 6 | + |
| 7 | +#[test] |
| 8 | +fn test_old_versions() { |
| 9 | + let cargo_new: Output = Command::new("cargo") |
| 10 | + .args(["new", "--lib", "compliance_tester_temp"]) |
| 11 | + .output() |
| 12 | + .expect("Failed to test old versions"); |
| 13 | + |
| 14 | + assert!(cargo_new.status.success()); |
| 15 | + |
| 16 | + std::fs::write( |
| 17 | + "compliance_tester_temp/src/lib.rs", |
| 18 | + include_str!("tests.rs") |
| 19 | + .replace( |
| 20 | + "use crate::WhitespaceSifter;", |
| 21 | + "#[allow(unused_imports)] use whitespace_sifter::WhitespaceSifter;", |
| 22 | + ) |
| 23 | + .as_bytes(), |
| 24 | + ) |
| 25 | + .expect("Failed to inject test code"); |
| 26 | + |
| 27 | + for ver in VERSIONS.iter().rev() { |
| 28 | + std::fs::write( |
| 29 | + "compliance_tester_temp/Cargo.toml", |
| 30 | + &format!( |
| 31 | + " |
| 32 | + [package] |
| 33 | + name = \"compliance_tester_temp\" |
| 34 | + version = \"0.1.0\" |
| 35 | + edition = \"2021\" |
| 36 | +
|
| 37 | + [dependencies] |
| 38 | + whitespace-sifter = \"={ver}\" |
| 39 | + " |
| 40 | + ), |
| 41 | + ) |
| 42 | + .expect("Failed to inject Cargo.toml base"); |
| 43 | + |
| 44 | + let cargo_test: Output = Command::new("cargo") |
| 45 | + .arg("test") |
| 46 | + .current_dir( |
| 47 | + std::env::current_dir() |
| 48 | + .expect("Failed to get current directory") |
| 49 | + .join("compliance_tester_temp"), |
| 50 | + ) |
| 51 | + .output() |
| 52 | + .expect("Failed to run cargo test"); |
| 53 | + |
| 54 | + assert!(!String::from_utf8_lossy(&cargo_test.stdout).contains("FAIL")); |
| 55 | + assert!(!String::from_utf8_lossy(&cargo_test.stderr).contains("FAIL")); |
| 56 | + } |
| 57 | + |
| 58 | + std::fs::remove_dir_all( |
| 59 | + std::env::current_dir() |
| 60 | + .expect("Failed to get current directory") |
| 61 | + .join("compliance_tester_temp"), |
| 62 | + ) |
| 63 | + .expect("Failed to remove compliance_tester_temp directory"); |
| 64 | +} |
0 commit comments