librustc_incremental: Unconfigure tests during normal build

This commit is contained in:
Vadim Petrochenkov 2019-08-01 03:35:10 +03:00
parent 6cc43db0b7
commit 42c5473d00
3 changed files with 68 additions and 65 deletions

View File

@ -117,6 +117,9 @@ use std::time::{UNIX_EPOCH, SystemTime, Duration};
use rand::{RngCore, thread_rng};
#[cfg(test)]
mod tests;
const LOCK_FILE_EXT: &str = ".lock";
const DEP_GRAPH_FILENAME: &str = "dep-graph.bin";
const WORK_PRODUCTS_FILENAME: &str = "work-products.bin";
@ -894,67 +897,3 @@ fn safe_remove_file(p: &Path) -> io::Result<()> {
Ok(())
}
}
#[test]
fn test_all_except_most_recent() {
assert_eq!(all_except_most_recent(
vec![
(UNIX_EPOCH + Duration::new(4, 0), PathBuf::from("4"), None),
(UNIX_EPOCH + Duration::new(1, 0), PathBuf::from("1"), None),
(UNIX_EPOCH + Duration::new(5, 0), PathBuf::from("5"), None),
(UNIX_EPOCH + Duration::new(3, 0), PathBuf::from("3"), None),
(UNIX_EPOCH + Duration::new(2, 0), PathBuf::from("2"), None),
]).keys().cloned().collect::<FxHashSet<PathBuf>>(),
vec![
PathBuf::from("1"),
PathBuf::from("2"),
PathBuf::from("3"),
PathBuf::from("4"),
].into_iter().collect::<FxHashSet<PathBuf>>()
);
assert_eq!(all_except_most_recent(
vec![
]).keys().cloned().collect::<FxHashSet<PathBuf>>(),
FxHashSet::default()
);
}
#[test]
fn test_timestamp_serialization() {
for i in 0 .. 1_000u64 {
let time = UNIX_EPOCH + Duration::new(i * 1_434_578, (i as u32) * 239_000);
let s = timestamp_to_string(time);
assert_eq!(Ok(time), string_to_timestamp(&s));
}
}
#[test]
fn test_find_source_directory_in_iter() {
let already_visited = FxHashSet::default();
// Find newest
assert_eq!(find_source_directory_in_iter(
vec![PathBuf::from("crate-dir/s-3234-0000-svh"),
PathBuf::from("crate-dir/s-2234-0000-svh"),
PathBuf::from("crate-dir/s-1234-0000-svh")].into_iter(), &already_visited),
Some(PathBuf::from("crate-dir/s-3234-0000-svh")));
// Filter out "-working"
assert_eq!(find_source_directory_in_iter(
vec![PathBuf::from("crate-dir/s-3234-0000-working"),
PathBuf::from("crate-dir/s-2234-0000-svh"),
PathBuf::from("crate-dir/s-1234-0000-svh")].into_iter(), &already_visited),
Some(PathBuf::from("crate-dir/s-2234-0000-svh")));
// Handle empty
assert_eq!(find_source_directory_in_iter(vec![].into_iter(), &already_visited),
None);
// Handle only working
assert_eq!(find_source_directory_in_iter(
vec![PathBuf::from("crate-dir/s-3234-0000-working"),
PathBuf::from("crate-dir/s-2234-0000-working"),
PathBuf::from("crate-dir/s-1234-0000-working")].into_iter(), &already_visited),
None);
}

View File

@ -0,0 +1,65 @@
use super::*;
#[test]
fn test_all_except_most_recent() {
assert_eq!(all_except_most_recent(
vec![
(UNIX_EPOCH + Duration::new(4, 0), PathBuf::from("4"), None),
(UNIX_EPOCH + Duration::new(1, 0), PathBuf::from("1"), None),
(UNIX_EPOCH + Duration::new(5, 0), PathBuf::from("5"), None),
(UNIX_EPOCH + Duration::new(3, 0), PathBuf::from("3"), None),
(UNIX_EPOCH + Duration::new(2, 0), PathBuf::from("2"), None),
]).keys().cloned().collect::<FxHashSet<PathBuf>>(),
vec![
PathBuf::from("1"),
PathBuf::from("2"),
PathBuf::from("3"),
PathBuf::from("4"),
].into_iter().collect::<FxHashSet<PathBuf>>()
);
assert_eq!(all_except_most_recent(
vec![
]).keys().cloned().collect::<FxHashSet<PathBuf>>(),
FxHashSet::default()
);
}
#[test]
fn test_timestamp_serialization() {
for i in 0 .. 1_000u64 {
let time = UNIX_EPOCH + Duration::new(i * 1_434_578, (i as u32) * 239_000);
let s = timestamp_to_string(time);
assert_eq!(Ok(time), string_to_timestamp(&s));
}
}
#[test]
fn test_find_source_directory_in_iter() {
let already_visited = FxHashSet::default();
// Find newest
assert_eq!(find_source_directory_in_iter(
vec![PathBuf::from("crate-dir/s-3234-0000-svh"),
PathBuf::from("crate-dir/s-2234-0000-svh"),
PathBuf::from("crate-dir/s-1234-0000-svh")].into_iter(), &already_visited),
Some(PathBuf::from("crate-dir/s-3234-0000-svh")));
// Filter out "-working"
assert_eq!(find_source_directory_in_iter(
vec![PathBuf::from("crate-dir/s-3234-0000-working"),
PathBuf::from("crate-dir/s-2234-0000-svh"),
PathBuf::from("crate-dir/s-1234-0000-svh")].into_iter(), &already_visited),
Some(PathBuf::from("crate-dir/s-2234-0000-svh")));
// Handle empty
assert_eq!(find_source_directory_in_iter(vec![].into_iter(), &already_visited),
None);
// Handle only working
assert_eq!(find_source_directory_in_iter(
vec![PathBuf::from("crate-dir/s-3234-0000-working"),
PathBuf::from("crate-dir/s-2234-0000-working"),
PathBuf::from("crate-dir/s-1234-0000-working")].into_iter(), &already_visited),
None);
}

View File

@ -29,7 +29,6 @@ pub fn check(root_path: &Path, bad: &mut bool) {
"liballoc",
"librustc",
"librustc_data_structures",
"librustc_incremental/persist",
"librustdoc",
"libstd",
"libsyntax",