Skip to content

Commit 9e89b47

Browse files
committed
Fix macro hygene error in repo_test
1 parent 714beb6 commit 9e89b47

File tree

4 files changed

+61
-50
lines changed

4 files changed

+61
-50
lines changed

src/blame.rs

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -290,35 +290,41 @@ mod tests {
290290
use std::fs::{self, File};
291291
use std::path::Path;
292292

293-
repo_test!(smoke, Typical, TypicalWorktree, BareWorktree {
294-
let mut index = repo.index().unwrap();
295-
296-
let root = repo.path().parent().unwrap();
297-
fs::create_dir(&root.join("foo")).unwrap();
298-
File::create(&root.join("foo/bar")).unwrap();
299-
index.add_path(Path::new("foo/bar")).unwrap();
300-
301-
let id = index.write_tree().unwrap();
302-
let tree = repo.find_tree(id).unwrap();
303-
let sig = repo.signature().unwrap();
304-
let id = repo.refname_to_id("HEAD").unwrap();
305-
let parent = repo.find_commit(id).unwrap();
306-
let commit = repo
307-
.commit(Some("HEAD"), &sig, &sig, "commit", &tree, &[&parent])
308-
.unwrap();
309-
310-
let blame = repo.blame_file(Path::new("foo/bar"), None).unwrap();
311-
312-
assert_eq!(blame.len(), 1);
313-
assert_eq!(blame.iter().count(), 1);
314-
315-
let hunk = blame.get_index(0).unwrap();
316-
assert_eq!(hunk.final_commit_id(), commit);
317-
assert_eq!(hunk.final_signature().name(), sig.name());
318-
assert_eq!(hunk.final_signature().email(), sig.email());
319-
assert_eq!(hunk.final_start_line(), 1);
320-
assert_eq!(hunk.path(), Some(Path::new("foo/bar")));
321-
assert_eq!(hunk.lines_in_hunk(), 0);
322-
assert!(!hunk.is_boundary())
323-
});
293+
use crate::Repository;
294+
295+
repo_test!(
296+
smoke,
297+
(Typical, TypicalWorktree, BareWorktree),
298+
|repo: &Repository| {
299+
let mut index = repo.index().unwrap();
300+
301+
let root = repo.path().parent().unwrap();
302+
fs::create_dir(&root.join("foo")).unwrap();
303+
File::create(&root.join("foo/bar")).unwrap();
304+
index.add_path(Path::new("foo/bar")).unwrap();
305+
306+
let id = index.write_tree().unwrap();
307+
let tree = repo.find_tree(id).unwrap();
308+
let sig = repo.signature().unwrap();
309+
let id = repo.refname_to_id("HEAD").unwrap();
310+
let parent = repo.find_commit(id).unwrap();
311+
let commit = repo
312+
.commit(Some("HEAD"), &sig, &sig, "commit", &tree, &[&parent])
313+
.unwrap();
314+
315+
let blame = repo.blame_file(Path::new("foo/bar"), None).unwrap();
316+
317+
assert_eq!(blame.len(), 1);
318+
assert_eq!(blame.iter().count(), 1);
319+
320+
let hunk = blame.get_index(0).unwrap();
321+
assert_eq!(hunk.final_commit_id(), commit);
322+
assert_eq!(hunk.final_signature().name(), sig.name());
323+
assert_eq!(hunk.final_signature().email(), sig.email());
324+
assert_eq!(hunk.final_start_line(), 1);
325+
assert_eq!(hunk.path(), Some(Path::new("foo/bar")));
326+
assert_eq!(hunk.lines_in_hunk(), 0);
327+
assert!(!hunk.is_boundary())
328+
}
329+
);
324330
}

src/branch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'repo> Drop for Branches<'repo> {
153153
mod tests {
154154
use crate::BranchType;
155155

156-
repo_test!(smoke, Typical, TypicalWorktree, BareWorktree {
156+
repo_test!(smoke, (Typical, TypicalWorktree, BareWorktree), |_| {
157157
let (_td, repo) = crate::test::repo_init();
158158
let head = repo.head().unwrap();
159159
let target = head.target().unwrap();

src/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ macro_rules! t {
1919

2020
// `repo_test! will
2121
macro_rules! repo_test {
22-
($test_name:ident, $($repo_type:ident),+ $test_body:block) => {
22+
($test_name:ident, ($($repo_type:ident),+), $test_body:expr) => {
2323
paste::item! {
2424
$(#[test]
2525
fn [<$test_name _ $repo_type:snake>]() {
2626
#[allow(unused_variables)]
2727
let (td, repo) = $crate::test::repo_init2($crate::test::RepoType::$repo_type);
28-
$test_body
28+
($test_body)(&repo);
2929
})+
3030
}
3131
}

src/worktree.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,12 @@ impl Drop for Worktree {
260260

261261
#[cfg(test)]
262262
mod tests {
263+
use crate::Repository;
263264
use crate::WorktreeAddOptions;
264265
use crate::WorktreeLockStatus;
265266
use tempfile::TempDir;
266267

267-
repo_test!(smoke_add_no_ref, Typical, Bare {
268+
repo_test!(smoke_add_no_ref, (Typical, Bare), |repo: &Repository| {
268269
let wtdir = TempDir::new().unwrap();
269270
let wt_path = wtdir.path().join("tree-no-ref-dir");
270271
let opts = WorktreeAddOptions::new(None);
@@ -279,7 +280,7 @@ mod tests {
279280
assert_eq!(status, WorktreeLockStatus::Unlocked);
280281
});
281282

282-
repo_test!(smoke_add_locked, Typical, Bare {
283+
repo_test!(smoke_add_locked, (Typical, Bare), |repo: &Repository| {
283284
let wtdir = TempDir::new().unwrap();
284285
let wt_path = wtdir.path().join("locked-tree");
285286
let mut opts = WorktreeAddOptions::new(None);
@@ -302,18 +303,22 @@ mod tests {
302303
);
303304
});
304305

305-
repo_test!(smoke_add_from_branch, Typical, Bare {
306-
let (wt_top, branch) = crate::test::worktrees_env_init(&repo);
307-
let wt_path = wt_top.path().join("test");
308-
let opts = WorktreeAddOptions::new(Some(branch.into_reference()));
309-
310-
let wt = repo.worktree_add("test-worktree", &wt_path, &opts).unwrap();
311-
assert_eq!(wt.name(), Some("test-worktree"));
312-
assert_eq!(
313-
wt.path().canonicalize().unwrap(),
314-
wt_path.canonicalize().unwrap()
315-
);
316-
let status = wt.is_locked().unwrap();
317-
assert_eq!(status, WorktreeLockStatus::Unlocked);
318-
});
306+
repo_test!(
307+
smoke_add_from_branch,
308+
(Typical, Bare),
309+
|repo: &Repository| {
310+
let (wt_top, branch) = crate::test::worktrees_env_init(&repo);
311+
let wt_path = wt_top.path().join("test");
312+
let opts = WorktreeAddOptions::new(Some(branch.into_reference()));
313+
314+
let wt = repo.worktree_add("test-worktree", &wt_path, &opts).unwrap();
315+
assert_eq!(wt.name(), Some("test-worktree"));
316+
assert_eq!(
317+
wt.path().canonicalize().unwrap(),
318+
wt_path.canonicalize().unwrap()
319+
);
320+
let status = wt.is_locked().unwrap();
321+
assert_eq!(status, WorktreeLockStatus::Unlocked);
322+
}
323+
);
319324
}

0 commit comments

Comments
 (0)