Skip to content

Commit cacb4fe

Browse files
committed
add test coverage for build_stamp implementation
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 9e1c9fd commit cacb4fe

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/bootstrap/src/utils/build_stamp.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use crate::core::config::TargetSelection;
1010
use crate::utils::helpers::mtime;
1111
use crate::{Compiler, Mode, t};
1212

13+
#[cfg(test)]
14+
mod tests;
15+
1316
/// Manages a stamp file to track build state. The file is created in the given
1417
/// directory and can have custom content and name.
1518
#[derive(Clone)]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use std::path::PathBuf;
2+
3+
use crate::{BuildStamp, Config, Flags};
4+
5+
fn temp_dir() -> PathBuf {
6+
let config =
7+
Config::parse(Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]));
8+
config.tempdir()
9+
}
10+
11+
#[test]
12+
#[should_panic(expected = "prefix can not start or end with '.'")]
13+
fn test_with_invalid_prefix() {
14+
let dir = temp_dir();
15+
BuildStamp::new(&dir).with_prefix(".invalid");
16+
}
17+
18+
#[test]
19+
#[should_panic(expected = "prefix can not start or end with '.'")]
20+
fn test_with_invalid_prefix2() {
21+
let dir = temp_dir();
22+
BuildStamp::new(&dir).with_prefix("invalid.");
23+
}
24+
25+
#[test]
26+
fn test_is_up_to_date() {
27+
let dir = temp_dir();
28+
29+
let mut build_stamp = BuildStamp::new(&dir).with_stamp("v1.0.0");
30+
build_stamp.write().unwrap();
31+
32+
assert!(
33+
build_stamp.is_up_to_date(),
34+
"Expected stamp file to be up-to-date, but contents do not match the expected value."
35+
);
36+
37+
build_stamp.stamp = "dummy value".to_owned();
38+
assert!(
39+
!build_stamp.is_up_to_date(),
40+
"Stamp should no longer be up-to-date as we changed its content right above."
41+
);
42+
43+
build_stamp.remove().unwrap();
44+
}

0 commit comments

Comments
 (0)