add dry_run flag in config builder and remove runtime test hacks

This commit is contained in:
bit-aloo 2025-09-21 19:34:49 +05:30
parent 9189bf79d4
commit 671aabd4eb
No known key found for this signature in database
5 changed files with 15 additions and 7 deletions

View file

@ -234,7 +234,7 @@ fn invalid_rust_optimize() {
#[test]
fn verify_file_integrity() {
let config = TestCtx::new().config("check").create_config();
let config = TestCtx::new().config("check").no_dry_run().create_config();
let tempfile = config.tempdir().join(".tmp-test-file");
File::create(&tempfile).unwrap().write_all(b"dummy value").unwrap();

View file

@ -857,7 +857,7 @@ pub(crate) fn verify(exec_ctx: &ExecutionContext, path: &Path, expected: &str) -
println!("verifying {}", path.display());
});
if exec_ctx.dry_run() && !cfg!(test) {
if exec_ctx.dry_run() {
return false;
}

View file

@ -160,7 +160,7 @@ impl Drop for TimeIt {
/// Symlinks two directories, using junctions on Windows and normal symlinks on
/// Unix.
pub fn symlink_dir(config: &Config, original: &Path, link: &Path) -> io::Result<()> {
if config.dry_run() && !cfg!(test) {
if config.dry_run() {
return Ok(());
}
let _ = fs::remove_dir_all(link);

View file

@ -60,7 +60,7 @@ fn test_check_cfg_arg() {
#[test]
fn test_symlink_dir() {
let config = TestCtx::new().config("check").create_config();
let config = TestCtx::new().config("check").no_dry_run().create_config();
let tempdir = config.tempdir().join(".tmp-dir");
let link_path = config.tempdir().join(".tmp-link");

View file

@ -49,6 +49,7 @@ pub struct ConfigBuilder {
args: Vec<String>,
directory: PathBuf,
override_download_ci_llvm: bool,
dry_run: bool,
}
impl ConfigBuilder {
@ -57,6 +58,7 @@ impl ConfigBuilder {
args: args.iter().copied().map(String::from).collect(),
directory,
override_download_ci_llvm: true,
dry_run: true,
}
}
@ -116,10 +118,16 @@ impl ConfigBuilder {
self
}
pub fn create_config(mut self) -> Config {
// Run in dry-check, otherwise the test would be too slow
self.args.push("--dry-run".to_string());
pub fn no_dry_run(mut self) -> Self {
self.dry_run = false;
self
}
pub fn create_config(mut self) -> Config {
if self.dry_run {
// Run in dry-check, otherwise the test would be too slow
self.args.push("--dry-run".to_string());
}
// Ignore submodules
self.args.push("--set".to_string());
self.args.push("build.submodules=false".to_string());