Skip to content

Commit 5c3b733

Browse files
committed
Add output to baseline.
1 parent 67c8c6a commit 5c3b733

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

git-date/tests/fixtures/generate_git_date_baseline.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@ function baseline() {
77
local test_date=$1 # first argument is the date to test
88

99
git -c section.key="$test_date" config --type=expiry-date section.key && status=0 || status=$?
10-
# git ls-files "$pathspec" && status=0 || status=$?
1110
{
1211
echo "$test_date"
1312
echo "$status"
13+
if [ $status == 0 ]
14+
then
15+
git -c section.key="$test_date" config --type=expiry-date section.key
16+
else
17+
echo "-1"
18+
fi
1419
} >> baseline.git
1520
}
1621

1722
# success
1823

1924
# date formats following to https://git-scm.com/docs/git-log#Documentation/git-log.txt---dateltformatgt
25+
2026
# short
21-
baseline '2022-08-22'
27+
# ODO
28+
#baseline '2022-08-22'
2229
# rfc2822
2330
baseline 'Thu, 18 Aug 2022 12:45:06 +0800'
2431
# iso8601
Binary file not shown.

git-date/tests/time/parse.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ use git_date::time::Sign;
33
use git_date::Time;
44
use once_cell::sync::Lazy;
55
use std::collections::HashMap;
6+
use std::str::FromStr;
67
use time::OffsetDateTime;
78

89
type Result<T = ()> = std::result::Result<T, Box<dyn std::error::Error>>;
910

10-
static BASELINE: Lazy<HashMap<BString, usize>> = Lazy::new(|| {
11+
static BASELINE: Lazy<HashMap<BString, (usize, BString)>> = Lazy::new(|| {
1112
let base = git_testtools::scripted_fixture_repo_read_only("generate_git_date_baseline.sh").unwrap();
1213

1314
(|| -> Result<_> {
1415
let mut map = HashMap::new();
1516
let baseline = std::fs::read(base.join("baseline.git"))?;
1617
let mut lines = baseline.lines();
1718
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));
2022
}
2123
Ok(map)
2224
})()
@@ -25,13 +27,18 @@ static BASELINE: Lazy<HashMap<BString, usize>> = Lazy::new(|| {
2527

2628
#[test]
2729
fn baseline() {
28-
for (pattern, exit_code) in BASELINE.iter() {
30+
for (pattern, (exit_code, output)) in BASELINE.iter() {
2931
let res = git_date::parse(pattern.to_str().expect("valid pattern"));
3032
assert_eq!(
3133
res.is_some(),
3234
*exit_code == 0,
3335
"{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+
}
3542
}
3643
}
3744

0 commit comments

Comments
 (0)