@@ -3,20 +3,22 @@ use git_date::time::Sign;
3
3
use git_date:: Time ;
4
4
use once_cell:: sync:: Lazy ;
5
5
use std:: collections:: HashMap ;
6
+ use std:: str:: FromStr ;
6
7
use time:: OffsetDateTime ;
7
8
8
9
type Result < T = ( ) > = std:: result:: Result < T , Box < dyn std:: error:: Error > > ;
9
10
10
- static BASELINE : Lazy < HashMap < BString , usize > > = Lazy :: new ( || {
11
+ static BASELINE : Lazy < HashMap < BString , ( usize , BString ) > > = Lazy :: new ( || {
11
12
let base = git_testtools:: scripted_fixture_repo_read_only ( "generate_git_date_baseline.sh" ) . unwrap ( ) ;
12
13
13
14
( || -> Result < _ > {
14
15
let mut map = HashMap :: new ( ) ;
15
16
let baseline = std:: fs:: read ( base. join ( "baseline.git" ) ) ?;
16
17
let mut lines = baseline. lines ( ) ;
17
18
while let Some ( date_str) = lines. next ( ) {
18
- let exit_code = lines. next ( ) . expect ( "two lines per baseline" ) . to_str ( ) ?. parse ( ) ?;
19
- map. insert ( date_str. into ( ) , exit_code) ;
19
+ let exit_code = lines. next ( ) . expect ( "three lines per baseline" ) . to_str ( ) ?. parse ( ) ?;
20
+ let output = lines. next ( ) . expect ( "three lines per baseline" ) . into ( ) ;
21
+ map. insert ( date_str. into ( ) , ( exit_code, output) ) ;
20
22
}
21
23
Ok ( map)
22
24
} ) ( )
@@ -25,13 +27,18 @@ static BASELINE: Lazy<HashMap<BString, usize>> = Lazy::new(|| {
25
27
26
28
#[ test]
27
29
fn baseline ( ) {
28
- for ( pattern, exit_code) in BASELINE . iter ( ) {
30
+ for ( pattern, ( exit_code, output ) ) in BASELINE . iter ( ) {
29
31
let res = git_date:: parse ( pattern. to_str ( ) . expect ( "valid pattern" ) ) ;
30
32
assert_eq ! (
31
33
res. is_some( ) ,
32
34
* exit_code == 0 ,
33
35
"{pattern:?} disagrees with baseline: {res:?}"
34
- )
36
+ ) ;
37
+ if * exit_code == 0 {
38
+ let actual = res. unwrap ( ) . seconds_since_unix_epoch ;
39
+ let expected = u32:: from_str ( output. to_str ( ) . expect ( "valid utf" ) ) . expect ( "valid epoch value" ) ;
40
+ assert_eq ! ( actual, expected, "{pattern:?} disagrees with baseline: {res:?}" )
41
+ }
35
42
}
36
43
}
37
44
0 commit comments