Skip to content

Commit 2a97216

Browse files
authored
Rollup merge of rust-lang#120172 - onur-ozkan:add-more-tests, r=Mark-Simulacrum
bootstrap: add more unit tests self-explanatory
2 parents 6b4f1c5 + d315a47 commit 2a97216

File tree

11 files changed

+59
-11
lines changed

11 files changed

+59
-11
lines changed

src/bootstrap/src/core/build_steps/setup.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::str::FromStr;
1414
use std::{fmt, fs, io};
1515

1616
#[cfg(test)]
17-
#[path = "../../tests/setup.rs"]
1817
mod tests;
1918

2019
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]

src/bootstrap/src/core/builder.rs

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use clap::ValueEnum;
3232
use once_cell::sync::Lazy;
3333

3434
#[cfg(test)]
35-
#[path = "../tests/builder.rs"]
3635
mod tests;
3736

3837
pub struct Builder<'a> {

src/bootstrap/src/core/config/config.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
//! This module implements parsing `config.toml` configuration files to tweak
44
//! how the build runs.
55
6-
#[cfg(test)]
7-
#[path = "../../tests/config.rs"]
8-
mod tests;
9-
106
use std::cell::{Cell, RefCell};
117
use std::cmp;
128
use std::collections::{HashMap, HashSet};
@@ -1203,7 +1199,7 @@ impl Config {
12031199
Self::parse_inner(args, get_toml)
12041200
}
12051201

1206-
fn parse_inner(args: &[String], get_toml: impl Fn(&Path) -> TomlConfig) -> Config {
1202+
pub(crate) fn parse_inner(args: &[String], get_toml: impl Fn(&Path) -> TomlConfig) -> Config {
12071203
let mut flags = Flags::parse(&args);
12081204
let mut config = Config::default_opts();
12091205

src/bootstrap/src/core/config/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
pub(crate) mod config;
22
pub(crate) mod flags;
3+
#[cfg(test)]
4+
mod tests;
35

46
pub use config::*;

src/bootstrap/src/tests/config.rs renamed to src/bootstrap/src/core/config/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Config, Flags};
1+
use super::{flags::Flags, Config};
22
use crate::core::config::{LldMode, TomlConfig};
33

44
use clap::CommandFactory;

src/bootstrap/src/utils/change_tracker.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
//! with the goal of keeping developers synchronized with important modifications in
33
//! the bootstrap.
44
5+
#[cfg(test)]
6+
mod tests;
7+
58
#[derive(Clone, Debug)]
69
pub struct ChangeInfo {
710
/// Represents the ID of PR caused major change on bootstrap.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use crate::{find_recent_config_change_ids, CONFIG_CHANGE_HISTORY};
2+
3+
#[test]
4+
fn test_find_recent_config_change_ids() {
5+
// If change-id is greater than the most recent one, result should be empty.
6+
assert!(find_recent_config_change_ids(usize::MAX).is_empty());
7+
8+
// There is no change-id equal to or less than 0, result should include the entire change history.
9+
assert_eq!(find_recent_config_change_ids(0).len(), CONFIG_CHANGE_HISTORY.len());
10+
}

src/bootstrap/src/utils/helpers.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::LldMode;
2121
pub use crate::utils::dylib::{dylib_path, dylib_path_var};
2222

2323
#[cfg(test)]
24-
#[path = "../tests/helpers.rs"]
2524
mod tests;
2625

2726
/// A helper macro to `unwrap` a result except also print out details like:

src/bootstrap/src/tests/helpers.rs renamed to src/bootstrap/src/utils/helpers/tests.rs

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
use crate::utils::helpers::{check_cfg_arg, extract_beta_rev, hex_encode, make};
2-
use std::path::PathBuf;
1+
use crate::{
2+
utils::helpers::{
3+
check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, symlink_dir,
4+
},
5+
Config,
6+
};
7+
use std::{
8+
fs::{self, remove_file, File},
9+
io::Write,
10+
path::PathBuf,
11+
};
312

413
#[test]
514
fn test_make() {
@@ -70,3 +79,34 @@ fn test_check_cfg_arg() {
7079
"--check-cfg=cfg(target_os,values(\"nixos\",\"nix2\"))"
7180
);
7281
}
82+
83+
#[test]
84+
fn test_program_out_of_date() {
85+
let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]);
86+
let tempfile = config.tempdir().join(".tmp-stamp-file");
87+
File::create(&tempfile).unwrap().write_all(b"dummy value").unwrap();
88+
assert!(tempfile.exists());
89+
90+
// up-to-date
91+
assert!(!program_out_of_date(&tempfile, "dummy value"));
92+
// out-of-date
93+
assert!(program_out_of_date(&tempfile, ""));
94+
95+
remove_file(tempfile).unwrap();
96+
}
97+
98+
#[test]
99+
fn test_symlink_dir() {
100+
let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]);
101+
let tempdir = config.tempdir().join(".tmp-dir");
102+
let link_path = config.tempdir().join(".tmp-link");
103+
104+
fs::create_dir_all(&tempdir).unwrap();
105+
symlink_dir(&config, &tempdir, &link_path).unwrap();
106+
107+
let link_source = fs::read_link(&link_path).unwrap();
108+
assert_eq!(link_source, tempdir);
109+
110+
fs::remove_dir(tempdir).unwrap();
111+
fs::remove_file(link_path).unwrap();
112+
}

0 commit comments

Comments
 (0)