Skip to content

Commit 7bc1409

Browse files
committed
Run gix-commitgraph tests for both SHA1 and SHA256
1 parent 419ea66 commit 7bc1409

9 files changed

Lines changed: 86 additions & 66 deletions

File tree

gix-commitgraph/tests/access/mod.rs

Lines changed: 80 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,112 +2,129 @@ use crate::{check_common, graph_and_expected, graph_and_expected_named};
22

33
#[test]
44
fn single_parent() {
5-
let (cg, refs) = graph_and_expected("single_parent.sh", &["parent", "child"]);
6-
check_common(&cg, &refs);
5+
for hash_kind in gix_hash::Kind::all() {
6+
let (cg, refs) = graph_and_expected(*hash_kind, "single_parent.sh", &["parent", "child"]);
7+
check_common(&cg, &refs);
78

8-
assert_eq!(cg.commit_at(refs["parent"].pos()).generation(), 1);
9-
assert_eq!(cg.commit_at(refs["child"].pos()).generation(), 2);
9+
assert_eq!(cg.commit_at(refs["parent"].pos()).generation(), 1);
10+
assert_eq!(cg.commit_at(refs["child"].pos()).generation(), 2);
11+
}
1012
}
1113

1214
#[test]
1315
fn single_commit_huge_dates_generation_v2_also_do_not_allow_huge_dates() {
14-
let (cg, refs) = graph_and_expected_named("single_commit_huge_dates.sh", "v2", &["HEAD"]);
15-
let info = &refs["HEAD"];
16-
let actual = cg.commit_by_id(info.id).expect("present");
17-
assert_eq!(
18-
actual.committer_timestamp(),
19-
1,
20-
"overflow happened, can't represent huge dates"
21-
);
22-
assert_eq!(
16+
for hash_kind in gix_hash::Kind::all() {
17+
let (cg, refs) = graph_and_expected_named(*hash_kind, "single_commit_huge_dates.sh", "v2", &["HEAD"]);
18+
let info = &refs["HEAD"];
19+
let actual = cg.commit_by_id(info.id).expect("present");
20+
assert_eq!(
21+
actual.committer_timestamp(),
22+
1,
23+
"overflow happened, can't represent huge dates"
24+
);
25+
assert_eq!(
2326
info.time.seconds, 68719476737,
2427
"this is the value we would want to see, but it's not possible in V2 either, as that is just about generations"
2528
);
26-
assert_eq!(actual.generation(), 1, "generations are fine though");
29+
assert_eq!(actual.generation(), 1, "generations are fine though");
30+
}
2731
}
2832

2933
#[test]
3034
fn single_commit_huge_dates_overflow_v1() {
31-
let (cg, refs) = graph_and_expected_named("single_commit_huge_dates.sh", "v1", &["HEAD"]);
32-
let info = &refs["HEAD"];
33-
let actual = cg.commit_by_id(info.id).expect("present");
34-
assert_eq!(actual.committer_timestamp(), 1, "overflow happened");
35-
assert_eq!(
36-
info.time.seconds, 68719476737,
37-
"this is the value we would want to see, but it's not possible in V1"
38-
);
39-
assert_eq!(actual.generation(), 1, "generations are fine though");
35+
for hash_kind in gix_hash::Kind::all() {
36+
let (cg, refs) = graph_and_expected_named(*hash_kind, "single_commit_huge_dates.sh", "v1", &["HEAD"]);
37+
let info = &refs["HEAD"];
38+
let actual = cg.commit_by_id(info.id).expect("present");
39+
assert_eq!(actual.committer_timestamp(), 1, "overflow happened");
40+
assert_eq!(
41+
info.time.seconds, 68719476737,
42+
"this is the value we would want to see, but it's not possible in V1"
43+
);
44+
assert_eq!(actual.generation(), 1, "generations are fine though");
45+
}
4046
}
4147

4248
#[test]
4349
fn single_commit_future_64bit_dates_work() {
44-
let (cg, refs) = graph_and_expected_named("single_commit_huge_dates.sh", "max-date", &["HEAD"]);
45-
let info = &refs["HEAD"];
46-
let actual = cg.commit_by_id(info.id).expect("present");
47-
assert_eq!(
50+
for hash_kind in gix_hash::Kind::all() {
51+
let (cg, refs) = graph_and_expected_named(*hash_kind, "single_commit_huge_dates.sh", "max-date", &["HEAD"]);
52+
let info = &refs["HEAD"];
53+
let actual = cg.commit_by_id(info.id).expect("present");
54+
assert_eq!(
4855
actual.committer_timestamp(),
4956
info.time.seconds.try_into().expect("timestamps in bound"),
5057
"this is close the highest representable value in the graph, like year 2500, so we are good for longer than I should care about"
5158
);
52-
assert_eq!(actual.generation(), 1);
59+
assert_eq!(actual.generation(), 1);
60+
}
5361
}
5462

5563
#[test]
5664
fn generation_numbers_overflow_is_handled_in_chained_graph() {
5765
let names = ["extra", "old-2", "future-2", "old-1", "future-1"];
58-
let (cg, mut refs) = graph_and_expected("generation_number_overflow.sh", &names);
59-
for (r, expected) in names
60-
.iter()
61-
.map(|n| refs.remove(n.to_owned()).expect("present"))
62-
.zip((1..=5).rev())
63-
{
64-
assert_eq!(
66+
for hash_kind in gix_hash::Kind::all() {
67+
let (cg, mut refs) = graph_and_expected(*hash_kind, "generation_number_overflow.sh", &names);
68+
for (r, expected) in names
69+
.iter()
70+
.map(|n| refs.remove(n.to_owned()).expect("present"))
71+
.zip((1..=5).rev())
72+
{
73+
assert_eq!(
6574
cg.commit_by_id(r.id).expect("present").generation(),
6675
expected,
6776
"actually, this test seems to have valid generation numbers from the get-go. How to repro the actual issue?"
6877
);
78+
}
6979
}
7080
}
7181

7282
#[test]
7383
fn octopus_merges() {
74-
let (cg, refs) = graph_and_expected(
75-
"octopus_merges.sh",
76-
&[
77-
"root",
78-
"parent1",
79-
"parent2",
80-
"parent3",
81-
"parent4",
82-
"three_parents",
83-
"four_parents",
84-
],
85-
);
86-
check_common(&cg, &refs);
84+
for hash_kind in gix_hash::Kind::all() {
85+
let (cg, refs) = graph_and_expected(
86+
*hash_kind,
87+
"octopus_merges.sh",
88+
&[
89+
"root",
90+
"parent1",
91+
"parent2",
92+
"parent3",
93+
"parent4",
94+
"three_parents",
95+
"four_parents",
96+
],
97+
);
98+
check_common(&cg, &refs);
8799

88-
assert_eq!(cg.commit_at(refs["root"].pos()).generation(), 1);
89-
assert_eq!(cg.commit_at(refs["parent1"].pos()).generation(), 2);
90-
assert_eq!(cg.commit_at(refs["parent2"].pos()).generation(), 2);
91-
assert_eq!(cg.commit_at(refs["parent3"].pos()).generation(), 2);
92-
assert_eq!(cg.commit_at(refs["parent4"].pos()).generation(), 2);
93-
assert_eq!(cg.commit_at(refs["three_parents"].pos()).generation(), 3);
94-
assert_eq!(cg.commit_at(refs["four_parents"].pos()).generation(), 3);
100+
assert_eq!(cg.commit_at(refs["root"].pos()).generation(), 1);
101+
assert_eq!(cg.commit_at(refs["parent1"].pos()).generation(), 2);
102+
assert_eq!(cg.commit_at(refs["parent2"].pos()).generation(), 2);
103+
assert_eq!(cg.commit_at(refs["parent3"].pos()).generation(), 2);
104+
assert_eq!(cg.commit_at(refs["parent4"].pos()).generation(), 2);
105+
assert_eq!(cg.commit_at(refs["three_parents"].pos()).generation(), 3);
106+
assert_eq!(cg.commit_at(refs["four_parents"].pos()).generation(), 3);
107+
}
95108
}
96109

97110
#[test]
98111
fn single_commit() {
99-
let (cg, refs) = graph_and_expected("single_commit.sh", &["commit"]);
100-
check_common(&cg, &refs);
112+
for hash_kind in gix_hash::Kind::all() {
113+
let (cg, refs) = graph_and_expected(*hash_kind, "single_commit.sh", &["commit"]);
114+
check_common(&cg, &refs);
101115

102-
assert_eq!(cg.commit_at(refs["commit"].pos()).generation(), 1);
116+
assert_eq!(cg.commit_at(refs["commit"].pos()).generation(), 1);
117+
}
103118
}
104119

105120
#[test]
106121
fn two_parents() {
107-
let (cg, refs) = graph_and_expected("two_parents.sh", &["parent1", "parent2", "child"]);
108-
check_common(&cg, &refs);
122+
for hash_kind in gix_hash::Kind::all() {
123+
let (cg, refs) = graph_and_expected(*hash_kind, "two_parents.sh", &["parent1", "parent2", "child"]);
124+
check_common(&cg, &refs);
109125

110-
assert_eq!(cg.commit_at(refs["parent1"].pos()).generation(), 1);
111-
assert_eq!(cg.commit_at(refs["parent2"].pos()).generation(), 1);
112-
assert_eq!(cg.commit_at(refs["child"].pos()).generation(), 2);
126+
assert_eq!(cg.commit_at(refs["parent1"].pos()).generation(), 1);
127+
assert_eq!(cg.commit_at(refs["parent2"].pos()).generation(), 1);
128+
assert_eq!(cg.commit_at(refs["child"].pos()).generation(), 2);
129+
}
113130
}

gix-commitgraph/tests/commitgraph.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
};
88

99
use gix_commitgraph::{Graph, Position as GraphPosition};
10-
use gix_testtools::scripted_fixture_read_only;
10+
use gix_testtools::scripted_fixture_for_hash_kind_read_only;
1111

1212
mod access;
1313

@@ -64,18 +64,20 @@ pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHa
6464
}
6565

6666
pub fn graph_and_expected(
67+
hash_kind: gix_hash::Kind,
6768
script_path: &str,
6869
refs: &[&'static str],
6970
) -> (gix_commitgraph::Graph, HashMap<String, RefInfo>) {
70-
graph_and_expected_named(script_path, "", refs)
71+
graph_and_expected_named(hash_kind, script_path, "", refs)
7172
}
7273

7374
pub fn graph_and_expected_named(
75+
hash_kind: gix_hash::Kind,
7476
script_path: &str,
7577
name: &str,
7678
refs: &[&'static str],
7779
) -> (gix_commitgraph::Graph, HashMap<String, RefInfo>) {
78-
let repo_dir = scripted_fixture_read_only(script_path)
80+
let repo_dir = scripted_fixture_for_hash_kind_read_only(hash_kind, script_path)
7981
.expect("script succeeds all the time")
8082
.join(name);
8183
let expected = inspect_refs(&repo_dir, refs);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ unit-tests:
161161
cargo nextest run -p gix-hash --no-fail-fast
162162
cargo nextest run -p gix-hash --features sha256 --no-fail-fast
163163
cargo nextest run -p gix-hash --no-default-features --features sha256 --no-fail-fast # TODO: make this actually work by removing 'sha1' from default features.
164+
cargo nextest run -p gix-commitgraph --features sha256 --no-fail-fast
164165
cargo nextest run -p gix-object --no-fail-fast
165166
cargo nextest run -p gix-object --features verbose-object-parsing-errors --no-fail-fast
166167
cargo nextest run -p gix-tempfile --features signals --no-fail-fast

0 commit comments

Comments
 (0)