Skip to content

Commit bc07277

Browse files
committed
First round of experimental multi-repo testing
1 parent ef183a2 commit bc07277

File tree

5 files changed

+59
-20
lines changed

5 files changed

+59
-20
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ structopt = "0.3"
3131
time = "0.1.39"
3232
tempfile = "3.1.0"
3333
thread-id = "3.3.0" # remove when we work with minimal-versions without it
34+
paste = "0.1.12"
3435

3536
[features]
3637
unstable = []

src/blame.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,7 @@ mod tests {
290290
use std::fs::{self, File};
291291
use std::path::Path;
292292

293-
#[test]
294-
fn smoke() {
295-
let (_td, repo) = crate::test::repo_init();
293+
repo_test!(smoke, Typical, TypicalWorktree, BareWorktree {
296294
let mut index = repo.index().unwrap();
297295

298296
let root = repo.path().parent().unwrap();
@@ -322,5 +320,5 @@ mod tests {
322320
assert_eq!(hunk.path(), Some(Path::new("foo/bar")));
323321
assert_eq!(hunk.lines_in_hunk(), 0);
324322
assert!(!hunk.is_boundary())
325-
}
323+
});
326324
}

src/branch.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ impl<'repo> Drop for Branches<'repo> {
153153
mod tests {
154154
use crate::BranchType;
155155

156-
#[test]
157-
fn smoke() {
156+
repo_test!(smoke, Typical, TypicalWorktree, BareWorktree {
158157
let (_td, repo) = crate::test::repo_init();
159158
let head = repo.head().unwrap();
160159
let target = head.target().unwrap();
@@ -174,5 +173,5 @@ mod tests {
174173
b1.set_upstream(None).unwrap();
175174

176175
b1.delete().unwrap();
177-
}
176+
});
178177
}

src/test.rs

+48-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,21 @@ macro_rules! t {
1717
};
1818
}
1919

20-
pub fn repo_init() -> (TempDir, Repository) {
20+
// `repo_test! will
21+
macro_rules! repo_test {
22+
($test_name:ident, $($repo_type:ident),+ $test_body:block) => {
23+
paste::item! {
24+
$(#[test]
25+
fn [<$test_name _ $repo_type:snake>]() {
26+
#[allow(unused_variables)]
27+
let (td, repo) = $crate::test::repo_init2($crate::test::RepoType::$repo_type);
28+
$test_body
29+
})+
30+
}
31+
}
32+
}
33+
34+
pub fn repo_init_typical() -> (TempDir, Repository) {
2135
let td = TempDir::new().unwrap();
2236
let repo = Repository::init(td.path()).unwrap();
2337
{
@@ -35,6 +49,31 @@ pub fn repo_init() -> (TempDir, Repository) {
3549
(td, repo)
3650
}
3751

52+
pub fn repo_init_bare() -> (TempDir, Repository) {
53+
panic!("unimplemented")
54+
}
55+
56+
pub fn repo_init_bare_worktree() -> (TempDir, Repository) {
57+
panic!("unimplemented")
58+
}
59+
60+
pub fn repo_init_typical_worktree() -> (TempDir, Repository) {
61+
panic!("unimplemented")
62+
}
63+
64+
pub fn repo_init() -> (TempDir, Repository) {
65+
repo_init_typical()
66+
}
67+
68+
pub fn repo_init2(repo_type: RepoType) -> (TempDir, Repository) {
69+
match repo_type {
70+
RepoType::Typical => repo_init_typical(),
71+
RepoType::Bare => repo_init_bare(),
72+
RepoType::BareWorktree => repo_init_bare_worktree(),
73+
RepoType::TypicalWorktree => repo_init_typical_worktree(),
74+
}
75+
}
76+
3877
pub fn commit(repo: &Repository) -> (Oid, Oid) {
3978
let mut index = t!(repo.index());
4079
let root = repo.path().parent().unwrap();
@@ -62,6 +101,14 @@ pub fn worktrees_env_init(repo: &Repository) -> (TempDir, Branch<'_>) {
62101
(wtdir, branch)
63102
}
64103

104+
#[derive(Debug,Clone,Copy)]
105+
pub enum RepoType {
106+
Typical,
107+
TypicalWorktree,
108+
Bare,
109+
BareWorktree,
110+
}
111+
65112
#[cfg(windows)]
66113
pub fn realpath(original: &Path) -> io::Result<PathBuf> {
67114
Ok(original.to_path_buf())

src/worktree.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,7 @@ mod tests {
264264
use crate::WorktreeLockStatus;
265265
use tempfile::TempDir;
266266

267-
#[test]
268-
fn smoke_add_no_ref() {
269-
let (_td, repo) = crate::test::repo_init();
267+
repo_test!(smoke_add_no_ref, Typical, Bare {
270268
let wtdir = TempDir::new().unwrap();
271269
let wt_path = wtdir.path().join("tree-no-ref-dir");
272270
let opts = WorktreeAddOptions::new(None);
@@ -279,11 +277,9 @@ mod tests {
279277
);
280278
let status = wt.is_locked().unwrap();
281279
assert_eq!(status, WorktreeLockStatus::Unlocked);
282-
}
280+
});
283281

284-
#[test]
285-
fn smoke_add_locked() {
286-
let (_td, repo) = crate::test::repo_init();
282+
repo_test!(smoke_add_locked, Typical, Bare {
287283
let wtdir = TempDir::new().unwrap();
288284
let wt_path = wtdir.path().join("locked-tree");
289285
let mut opts = WorktreeAddOptions::new(None);
@@ -304,11 +300,9 @@ mod tests {
304300
wt.is_locked().unwrap(),
305301
WorktreeLockStatus::Locked(Some("my reason".to_string()))
306302
);
307-
}
303+
});
308304

309-
#[test]
310-
fn smoke_add_from_branch() {
311-
let (_td, repo) = crate::test::repo_init();
305+
repo_test!(smoke_add_from_branch, Typical, Bare {
312306
let (wt_top, branch) = crate::test::worktrees_env_init(&repo);
313307
let wt_path = wt_top.path().join("test");
314308
let opts = WorktreeAddOptions::new(Some(branch.into_reference()));
@@ -321,5 +315,5 @@ mod tests {
321315
);
322316
let status = wt.is_locked().unwrap();
323317
assert_eq!(status, WorktreeLockStatus::Unlocked);
324-
}
318+
});
325319
}

0 commit comments

Comments
 (0)