diff --git a/src/bootstrap/src/core/build_steps/setup.rs b/src/bootstrap/src/core/build_steps/setup.rs index dd9c68aba7f7e..5b434eddb7158 100644 --- a/src/bootstrap/src/core/build_steps/setup.rs +++ b/src/bootstrap/src/core/build_steps/setup.rs @@ -14,7 +14,6 @@ use std::str::FromStr; use std::{fmt, fs, io}; #[cfg(test)] -#[path = "../../tests/setup.rs"] mod tests; #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] diff --git a/src/bootstrap/src/tests/setup.rs b/src/bootstrap/src/core/build_steps/setup/tests.rs similarity index 100% rename from src/bootstrap/src/tests/setup.rs rename to src/bootstrap/src/core/build_steps/setup/tests.rs diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 3770d0687b242..dac8393de6b4c 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -32,7 +32,6 @@ use clap::ValueEnum; use once_cell::sync::Lazy; #[cfg(test)] -#[path = "../tests/builder.rs"] mod tests; pub struct Builder<'a> { diff --git a/src/bootstrap/src/tests/builder.rs b/src/bootstrap/src/core/builder/tests.rs similarity index 100% rename from src/bootstrap/src/tests/builder.rs rename to src/bootstrap/src/core/builder/tests.rs diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index fcdd742e69c22..c0dd1e1208484 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -3,10 +3,6 @@ //! This module implements parsing `config.toml` configuration files to tweak //! how the build runs. -#[cfg(test)] -#[path = "../../tests/config.rs"] -mod tests; - use std::cell::{Cell, RefCell}; use std::cmp; use std::collections::{HashMap, HashSet}; @@ -1203,7 +1199,7 @@ impl Config { Self::parse_inner(args, get_toml) } - fn parse_inner(args: &[String], get_toml: impl Fn(&Path) -> TomlConfig) -> Config { + pub(crate) fn parse_inner(args: &[String], get_toml: impl Fn(&Path) -> TomlConfig) -> Config { let mut flags = Flags::parse(&args); let mut config = Config::default_opts(); diff --git a/src/bootstrap/src/core/config/mod.rs b/src/bootstrap/src/core/config/mod.rs index 9c6861826d605..99412848abbb7 100644 --- a/src/bootstrap/src/core/config/mod.rs +++ b/src/bootstrap/src/core/config/mod.rs @@ -1,4 +1,6 @@ pub(crate) mod config; pub(crate) mod flags; +#[cfg(test)] +mod tests; pub use config::*; diff --git a/src/bootstrap/src/tests/config.rs b/src/bootstrap/src/core/config/tests.rs similarity index 99% rename from src/bootstrap/src/tests/config.rs rename to src/bootstrap/src/core/config/tests.rs index c65067f8e8f76..201d11571c48a 100644 --- a/src/bootstrap/src/tests/config.rs +++ b/src/bootstrap/src/core/config/tests.rs @@ -1,4 +1,4 @@ -use super::{Config, Flags}; +use super::{flags::Flags, Config}; use crate::core::config::{LldMode, TomlConfig}; use clap::CommandFactory; diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index 327b4674acfdb..0d5e2600b73a9 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -2,6 +2,9 @@ //! with the goal of keeping developers synchronized with important modifications in //! the bootstrap. +#[cfg(test)] +mod tests; + #[derive(Clone, Debug)] pub struct ChangeInfo { /// Represents the ID of PR caused major change on bootstrap. diff --git a/src/bootstrap/src/utils/change_tracker/tests.rs b/src/bootstrap/src/utils/change_tracker/tests.rs new file mode 100644 index 0000000000000..d2bfc07d1727b --- /dev/null +++ b/src/bootstrap/src/utils/change_tracker/tests.rs @@ -0,0 +1,10 @@ +use crate::{find_recent_config_change_ids, CONFIG_CHANGE_HISTORY}; + +#[test] +fn test_find_recent_config_change_ids() { + // If change-id is greater than the most recent one, result should be empty. + assert!(find_recent_config_change_ids(usize::MAX).is_empty()); + + // There is no change-id equal to or less than 0, result should include the entire change history. + assert_eq!(find_recent_config_change_ids(0).len(), CONFIG_CHANGE_HISTORY.len()); +} diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index 0c917c3d57933..d1f713af91709 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -21,7 +21,6 @@ use crate::LldMode; pub use crate::utils::dylib::{dylib_path, dylib_path_var}; #[cfg(test)] -#[path = "../tests/helpers.rs"] mod tests; /// A helper macro to `unwrap` a result except also print out details like: diff --git a/src/bootstrap/src/tests/helpers.rs b/src/bootstrap/src/utils/helpers/tests.rs similarity index 62% rename from src/bootstrap/src/tests/helpers.rs rename to src/bootstrap/src/utils/helpers/tests.rs index 2d626fad417d7..9cfaa3eb67b5c 100644 --- a/src/bootstrap/src/tests/helpers.rs +++ b/src/bootstrap/src/utils/helpers/tests.rs @@ -1,5 +1,14 @@ -use crate::utils::helpers::{check_cfg_arg, extract_beta_rev, hex_encode, make}; -use std::path::PathBuf; +use crate::{ + utils::helpers::{ + check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, symlink_dir, + }, + Config, +}; +use std::{ + fs::{self, remove_file, File}, + io::Write, + path::PathBuf, +}; #[test] fn test_make() { @@ -70,3 +79,38 @@ fn test_check_cfg_arg() { "--check-cfg=cfg(target_os,values(\"nixos\",\"nix2\"))" ); } + +#[test] +fn test_program_out_of_date() { + let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]); + let tempfile = config.tempdir().join(".tmp-stamp-file"); + File::create(&tempfile).unwrap().write_all(b"dummy value").unwrap(); + assert!(tempfile.exists()); + + // up-to-date + assert!(!program_out_of_date(&tempfile, "dummy value")); + // out-of-date + assert!(program_out_of_date(&tempfile, "")); + + remove_file(tempfile).unwrap(); +} + +#[test] +fn test_symlink_dir() { + let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]); + let tempdir = config.tempdir().join(".tmp-dir"); + let link_path = config.tempdir().join(".tmp-link"); + + fs::create_dir_all(&tempdir).unwrap(); + symlink_dir(&config, &tempdir, &link_path).unwrap(); + + let link_source = fs::read_link(&link_path).unwrap(); + assert_eq!(link_source, tempdir); + + fs::remove_dir(tempdir).unwrap(); + + #[cfg(windows)] + fs::remove_dir(link_path).unwrap(); + #[cfg(not(windows))] + fs::remove_file(link_path).unwrap(); +}