Elffuss BraidHub

utopia-ia/elffuss-braid public

main · 2.1 KiBRawPermalink
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 UtopiaIA
3
4//! The round trip on a real history: the repository these tests live in.
5
6use std::path::Path;
7
8use braid_git::{Error, ImportOptions, RoundTripReport, verify_round_trip, verify_round_trip_with};
9
10/// Runs a round trip of this repository, or says why it cannot.
11fn round_trip(options: &ImportOptions) -> Option<RoundTripReport> {
12 let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
13 if !root.join(".git").exists() {
14 eprintln!("skipped: the sources are not in a git checkout");
15 return None;
16 }
17 let tmp = tempfile::tempdir().unwrap();
18 match verify_round_trip_with(&root, tmp.path(), options) {
19 Ok(report) => Some(report),
20 // A shallow checkout cannot be imported, by design.
21 Err(Error::Shallow) => {
22 eprintln!("skipped: this checkout is shallow");
23 None
24 }
25 Err(err) => panic!("{err}"),
26 }
27}
28
29#[test]
30fn the_history_of_head_round_trips() {
31 // A checkout always has HEAD, even when it has no local branch.
32 let options = ImportOptions {
33 refs: vec![b"HEAD".to_vec()],
34 };
35 if let Some(report) = round_trip(&options) {
36 assert!(report.commits >= 3, "{report:?}");
37 assert!(report.trees > 0 && report.blobs > 0, "{report:?}");
38 assert_eq!(report.refs, 1);
39 }
40}
41
42#[test]
43fn every_branch_and_tag_round_trips() {
44 if let Some(report) = round_trip(&ImportOptions::default()) {
45 eprintln!("{report:?}");
46 }
47}
48
49/// The round trip of any repository, on request:
50/// `BRAID_ROUND_TRIP_REPO=<path> cargo test -p elffuss-braid-git --release --test this_repository -- --ignored`
51#[test]
52#[ignore = "needs BRAID_ROUND_TRIP_REPO"]
53fn another_repository_round_trips() {
54 let Some(path) = std::env::var_os("BRAID_ROUND_TRIP_REPO") else {
55 eprintln!("set BRAID_ROUND_TRIP_REPO to the repository to check");
56 return;
57 };
58 let tmp = tempfile::tempdir().unwrap();
59 let report =
60 verify_round_trip(Path::new(&path), tmp.path()).unwrap_or_else(|err| panic!("{err}"));
61 eprintln!("{report:?}");
62}