File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ use crate::core::config::TargetSelection;
1010use crate :: utils:: helpers:: mtime;
1111use 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 ) ]
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments