fix(cli): stop littering pdb files on windows

This commit is contained in:
DocWilco 2023-09-27 22:02:14 +02:00
parent da3d55ba03
commit 511e334365

View file

@ -9,6 +9,7 @@ use std::process::{self, Command};
const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"]; const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"];
const RUSTC_EDITION_ARGS: &[&str] = &["--edition", "2021"]; const RUSTC_EDITION_ARGS: &[&str] = &["--edition", "2021"];
const RUSTC_NO_DEBUG_ARGS: &[&str] = &["-C", "strip=debuginfo"];
const I_AM_DONE_REGEX: &str = r"(?m)^\s*///?\s*I\s+AM\s+NOT\s+DONE"; const I_AM_DONE_REGEX: &str = r"(?m)^\s*///?\s*I\s+AM\s+NOT\s+DONE";
const CONTEXT: usize = 2; const CONTEXT: usize = 2;
const CLIPPY_CARGO_TOML_PATH: &str = "./exercises/clippy/Cargo.toml"; const CLIPPY_CARGO_TOML_PATH: &str = "./exercises/clippy/Cargo.toml";
@ -113,11 +114,13 @@ impl Exercise {
.args([self.path.to_str().unwrap(), "-o", &temp_file()]) .args([self.path.to_str().unwrap(), "-o", &temp_file()])
.args(RUSTC_COLOR_ARGS) .args(RUSTC_COLOR_ARGS)
.args(RUSTC_EDITION_ARGS) .args(RUSTC_EDITION_ARGS)
.args(RUSTC_NO_DEBUG_ARGS)
.output(), .output(),
Mode::Test => Command::new("rustc") Mode::Test => Command::new("rustc")
.args(["--test", self.path.to_str().unwrap(), "-o", &temp_file()]) .args(["--test", self.path.to_str().unwrap(), "-o", &temp_file()])
.args(RUSTC_COLOR_ARGS) .args(RUSTC_COLOR_ARGS)
.args(RUSTC_EDITION_ARGS) .args(RUSTC_EDITION_ARGS)
.args(RUSTC_NO_DEBUG_ARGS)
.output(), .output(),
Mode::Clippy => { Mode::Clippy => {
let cargo_toml = format!( let cargo_toml = format!(
@ -144,6 +147,7 @@ path = "{}.rs""#,
.args([self.path.to_str().unwrap(), "-o", &temp_file()]) .args([self.path.to_str().unwrap(), "-o", &temp_file()])
.args(RUSTC_COLOR_ARGS) .args(RUSTC_COLOR_ARGS)
.args(RUSTC_EDITION_ARGS) .args(RUSTC_EDITION_ARGS)
.args(RUSTC_NO_DEBUG_ARGS)
.output() .output()
.expect("Failed to compile!"); .expect("Failed to compile!");
// Due to an issue with Clippy, a cargo clean is required to catch all lints. // Due to an issue with Clippy, a cargo clean is required to catch all lints.
@ -289,6 +293,24 @@ mod test {
assert!(!Path::new(&temp_file()).exists()); assert!(!Path::new(&temp_file()).exists());
} }
#[test]
#[cfg(target_os = "windows")]
fn test_no_pdb_file() {
[Mode::Compile, Mode::Test] // Clippy doesn't like to test
.iter()
.for_each(|mode| {
let exercise = Exercise {
name: String::from("example"),
// We want a file that does actually compile
path: PathBuf::from("tests/fixture/state/pending_exercise.rs"),
mode: *mode,
hint: String::from(""),
};
let _ = exercise.compile().unwrap();
assert!(!Path::new(&format!("{}.pdb", temp_file())).exists());
});
}
#[test] #[test]
fn test_pending_state() { fn test_pending_state() {
let exercise = Exercise { let exercise = Exercise {