Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lib: reduce .block_on().unwrap() calls in tests with extension trait
  • Loading branch information
martinvonz committed Mar 8, 2026
commit bffcccda6411c829be9a96637b5fddaf66bebb17
10 changes: 5 additions & 5 deletions cli/src/commands/arrange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,8 @@ fn render(
#[cfg(test)]
mod tests {
use maplit::hashset;
use pollster::FutureExt as _;
use testutils::CommitBuilderExt as _;
use testutils::FutureTestExt as _;
use testutils::TestRepo;

use super::*;
Expand Down Expand Up @@ -768,8 +768,8 @@ mod tests {
vec![store.root_commit_id().clone()];
plan.rewrites.get_mut(commit_f.id()).unwrap().new_parents = vec![commit_a.id().clone()];

let rewritten = plan.execute(tx.repo_mut()).block_on().unwrap();
tx.repo_mut().rebase_descendants().block_on().unwrap();
let rewritten = plan.execute(tx.repo_mut()).block_unwrap();
tx.repo_mut().rebase_descendants().block_unwrap();
assert_eq!(
rewritten.keys().collect::<HashSet<_>>(),
hashset![
Expand Down Expand Up @@ -830,8 +830,8 @@ mod tests {
action: RewriteAction::Abandon,
};

let rewritten = plan.execute(tx.repo_mut()).block_on().unwrap();
tx.repo_mut().rebase_descendants().block_on().unwrap();
let rewritten = plan.execute(tx.repo_mut()).block_unwrap();
tx.repo_mut().rebase_descendants().block_unwrap();
assert_eq!(rewritten.keys().sorted().collect_vec(), vec![commit_d.id()]);
let new_commit_d = rewritten.get(commit_d.id()).unwrap();
assert_eq!(new_commit_d.parent_ids(), &[commit_a.id().clone()]);
Expand Down
5 changes: 2 additions & 3 deletions cli/src/commands/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async fn visit_collapsed_untracked_files(

#[cfg(test)]
mod test {
use pollster::FutureExt as _;
use testutils::FutureTestExt as _;
use testutils::TestRepo;
use testutils::TestTreeBuilder;
use testutils::repo_path;
Expand All @@ -314,8 +314,7 @@ mod test {
result.push('\n');
Ok(())
})
.block_on()
.unwrap();
.block_unwrap();
result
}

Expand Down
49 changes: 22 additions & 27 deletions cli/src/merge_tools/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ mod tests {
use proptest_state_machine::StateMachineTest;
use proptest_state_machine::prop_state_machine;
use test_case::test_matrix;
use testutils::FutureTestExt as _;
use testutils::TestRepo;
use testutils::assert_tree_eq;
use testutils::dump_tree;
Expand Down Expand Up @@ -805,8 +806,7 @@ mod tests {
tree_diff,
ConflictMarkerStyle::Diff,
)
.block_on()
.unwrap()
.block_unwrap()
}

fn apply_diff(
Expand Down Expand Up @@ -1035,8 +1035,7 @@ mod tests {

let get_actual_executables = |tree: &MergedTree| {
tree.path_value_async(file_path)
.block_on()
.unwrap()
.block_unwrap()
.to_executable_merge()
.expect("The path should point to an existing file.")
};
Expand Down Expand Up @@ -1153,16 +1152,15 @@ mod tests {
}
}
let tree = apply_diff(store, &left_tree, &right_tree, &changed_files, &files);
let actual_copy_ids =
tree.path_value_async(file_path)
.block_on()
.unwrap()
.map(|tree_value| {
let Some(TreeValue::File { copy_id, .. }) = tree_value else {
panic!("The path should point to an existing file.");
};
copy_id.clone()
});
let actual_copy_ids = tree
.path_value_async(file_path)
.block_unwrap()
.map(|tree_value| {
let Some(TreeValue::File { copy_id, .. }) = tree_value else {
panic!("The path should point to an existing file.");
};
copy_id.clone()
});
assert_eq!(
actual_copy_ids.resolve_trivial(SameChange::Accept),
Some(&copy_id),
Expand Down Expand Up @@ -1202,16 +1200,15 @@ mod tests {
let tree =
apply_merge_builtin(store, &tree, vec![file_path.to_owned()], &[merge_file]).unwrap();

let actual_copy_ids =
tree.path_value_async(file_path)
.block_on()
.unwrap()
.map(|tree_value| {
let Some(TreeValue::File { copy_id, .. }) = tree_value else {
panic!("The path should point to an existing file.");
};
copy_id.clone()
});
let actual_copy_ids = tree
.path_value_async(file_path)
.block_unwrap()
.map(|tree_value| {
let Some(TreeValue::File { copy_id, .. }) = tree_value else {
panic!("The path should point to an existing file.");
};
copy_id.clone()
});
assert_eq!(
actual_copy_ids.resolve_trivial(SameChange::Accept),
Some(&new_copy_id),
Expand Down Expand Up @@ -2091,9 +2088,7 @@ mod tests {
to_file_id(base_tree.path_value(path).unwrap()),
to_file_id(right_tree.path_value(path).unwrap()),
]);
let content = extract_as_single_hunk(&merge, store, path)
.block_on()
.unwrap();
let content = extract_as_single_hunk(&merge, store, path).block_unwrap();
let merge_result = files::merge_hunks(&content, store.merge_options());
let sections = make_merge_sections(merge_result).unwrap();
insta::assert_debug_snapshot!(sections, @r#"
Expand Down
7 changes: 4 additions & 3 deletions lib/src/file_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ mod tests {
use itertools::Itertools as _;
use pollster::FutureExt as _;
use test_case::test_case;
use testutils::FutureTestExt as _;

use super::*;
use crate::tests::new_temp_dir;
Expand Down Expand Up @@ -697,11 +698,11 @@ mod tests {
let mut async_reader = BlockingAsyncReader::new(sync_reader);

let mut buf = [0u8; 3];
let num_bytes_read = async_reader.read(&mut buf).block_on().unwrap();
let num_bytes_read = async_reader.read(&mut buf).block_unwrap();
assert_eq!(num_bytes_read, 3);
assert_eq!(&buf, &input[0..3]);

let num_bytes_read = async_reader.read(&mut buf).block_on().unwrap();
let num_bytes_read = async_reader.read(&mut buf).block_unwrap();
assert_eq!(num_bytes_read, 2);
assert_eq!(&buf[0..2], &input[3..5]);
}
Expand All @@ -713,7 +714,7 @@ mod tests {
let mut async_reader = BlockingAsyncReader::new(sync_reader);

let mut buf = vec![];
let num_bytes_read = async_reader.read_to_end(&mut buf).block_on().unwrap();
let num_bytes_read = async_reader.read_to_end(&mut buf).block_unwrap();
assert_eq!(num_bytes_read, input.len());
assert_eq!(&buf, &input);
}
Expand Down
41 changes: 18 additions & 23 deletions lib/src/git_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,7 @@ mod tests {
use gix::objs::CommitRef;
use indoc::indoc;
use pollster::FutureExt as _;
use testutils::FutureTestExt as _;

use super::*;
use crate::config::StackedConfig;
Expand Down Expand Up @@ -1706,7 +1707,7 @@ mod tests {
.collect_vec();
assert_eq!(git_refs, vec![git_commit_id2]);

let commit = backend.read_commit(&commit_id).block_on().unwrap();
let commit = backend.read_commit(&commit_id).block_unwrap();
assert_eq!(&commit.change_id, &change_id);
assert_eq!(commit.parents, vec![CommitId::from_bytes(&[0; 20])]);
assert_eq!(commit.predecessors, vec![]);
Expand Down Expand Up @@ -1735,8 +1736,7 @@ mod tests {
RepoPath::root(),
&TreeId::from_bytes(root_tree_id.as_bytes()),
)
.block_on()
.unwrap();
.block_unwrap();
let mut root_entries = root_tree.entries();
let dir = root_entries.next().unwrap();
assert_eq!(root_entries.next(), None);
Expand All @@ -1751,8 +1751,7 @@ mod tests {
RepoPath::from_internal_string("dir").unwrap(),
&TreeId::from_bytes(dir_tree_id.as_bytes()),
)
.block_on()
.unwrap();
.block_unwrap();
let mut entries = dir_tree.entries();
let file = entries.next().unwrap();
let symlink = entries.next().unwrap();
Expand All @@ -1772,7 +1771,7 @@ mod tests {
&TreeValue::Symlink(SymlinkId::from_bytes(blob2.as_bytes()))
);

let commit2 = backend.read_commit(&commit_id2).block_on().unwrap();
let commit2 = backend.read_commit(&commit_id2).block_unwrap();
assert_eq!(commit2.parents, vec![commit_id.clone()]);
assert_eq!(commit.predecessors, vec![]);
assert_eq!(
Expand Down Expand Up @@ -1870,8 +1869,7 @@ mod tests {

let commit = backend
.read_commit(&CommitId::from_bytes(git_commit_id.as_bytes()))
.block_on()
.unwrap();
.block_unwrap();

let sig = commit.secure_sig.expect("failed to read the signature");

Expand Down Expand Up @@ -1976,9 +1974,8 @@ mod tests {
secure_sig: None,
};

let (initial_commit_id, _init_commit) =
backend.write_commit(commit, None).block_on().unwrap();
let commit = backend.read_commit(&initial_commit_id).block_on().unwrap();
let (initial_commit_id, _init_commit) = backend.write_commit(commit, None).block_unwrap();
let commit = backend.read_commit(&initial_commit_id).block_unwrap();
assert_eq!(
commit.change_id, original_change_id,
"The change-id header did not roundtrip"
Expand All @@ -1991,8 +1988,7 @@ mod tests {
GitBackend::init_external(&settings, &empty_store_path, git_repo.path()).unwrap();
let no_extra_commit = no_extra_backend
.read_commit(&initial_commit_id)
.block_on()
.unwrap();
.block_unwrap();

assert_eq!(
no_extra_commit.change_id, original_change_id,
Expand Down Expand Up @@ -2082,15 +2078,15 @@ mod tests {
// Only root commit as parent
commit.parents = vec![backend.root_commit_id().clone()];
let first_id = write_commit(commit.clone()).unwrap().0;
let first_commit = backend.read_commit(&first_id).block_on().unwrap();
let first_commit = backend.read_commit(&first_id).block_unwrap();
assert_eq!(first_commit, commit);
let first_git_commit = git_repo.find_commit(git_id(&first_id)).unwrap();
assert!(first_git_commit.parent_ids().collect_vec().is_empty());

// Only non-root commit as parent
commit.parents = vec![first_id.clone()];
let second_id = write_commit(commit.clone()).unwrap().0;
let second_commit = backend.read_commit(&second_id).block_on().unwrap();
let second_commit = backend.read_commit(&second_id).block_unwrap();
assert_eq!(second_commit, commit);
let second_git_commit = git_repo.find_commit(git_id(&second_id)).unwrap();
assert_eq!(
Expand All @@ -2101,7 +2097,7 @@ mod tests {
// Merge commit
commit.parents = vec![first_id.clone(), second_id.clone()];
let merge_id = write_commit(commit.clone()).unwrap().0;
let merge_commit = backend.read_commit(&merge_id).block_on().unwrap();
let merge_commit = backend.read_commit(&merge_id).block_unwrap();
assert_eq!(merge_commit, commit);
let merge_git_commit = git_repo.find_commit(git_id(&merge_id)).unwrap();
assert_eq!(
Expand Down Expand Up @@ -2162,7 +2158,7 @@ mod tests {
// When writing a tree-level conflict, the root tree on the git side has the
// individual trees as subtrees.
let read_commit_id = write_commit(commit.clone()).unwrap().0;
let read_commit = backend.read_commit(&read_commit_id).block_on().unwrap();
let read_commit = backend.read_commit(&read_commit_id).block_unwrap();
assert_eq!(read_commit, commit);
let git_commit = git_repo
.find_commit(gix::ObjectId::from_bytes_or_panic(
Expand Down Expand Up @@ -2224,7 +2220,7 @@ mod tests {
// regular git tree.
commit.root_tree = Merge::resolved(create_tree(5));
let read_commit_id = write_commit(commit.clone()).unwrap().0;
let read_commit = backend.read_commit(&read_commit_id).block_on().unwrap();
let read_commit = backend.read_commit(&read_commit_id).block_unwrap();
assert_eq!(read_commit, commit);
let git_commit = git_repo
.find_commit(gix::ObjectId::from_bytes_or_panic(
Expand Down Expand Up @@ -2262,7 +2258,7 @@ mod tests {
committer: signature,
secure_sig: None,
};
let commit_id = backend.write_commit(commit, None).block_on().unwrap().0;
let commit_id = backend.write_commit(commit, None).block_unwrap().0;
let git_refs = git_repo.references().unwrap();
let git_ref_ids: Vec<_> = git_refs
.prefixed("refs/jj/keep/")
Expand Down Expand Up @@ -2355,7 +2351,7 @@ mod tests {
let (commit_id2, mut actual_commit2) = write_commit(commit2.clone()).unwrap();
// The returned matches the ID
assert_eq!(
backend.read_commit(&commit_id2).block_on().unwrap(),
backend.read_commit(&commit_id2).block_unwrap(),
actual_commit2
);
assert_ne!(commit_id2, commit_id1);
Expand Down Expand Up @@ -2394,8 +2390,7 @@ mod tests {

let (id, commit) = backend
.write_commit(commit, Some(&mut signer as &mut SigningFn))
.block_on()
.unwrap();
.block_unwrap();

let git_repo = backend.git_repo();
let obj = git_repo
Expand All @@ -2414,7 +2409,7 @@ mod tests {

let returned_sig = commit.secure_sig.expect("failed to return the signature");

let commit = backend.read_commit(&id).block_on().unwrap();
let commit = backend.read_commit(&id).block_unwrap();

let sig = commit.secure_sig.expect("failed to read the signature");
assert_eq!(&sig, &returned_sig);
Expand Down
9 changes: 5 additions & 4 deletions lib/src/simple_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ fn signature_from_proto(proto: crate::protos::simple_store::commit::Signature) -
mod tests {
use assert_matches::assert_matches;
use pollster::FutureExt as _;
use testutils::FutureTestExt as _;

use super::*;
use crate::merge::Merge;
Expand Down Expand Up @@ -543,25 +544,25 @@ mod tests {
// Only root commit as parent
commit.parents = vec![backend.root_commit_id().clone()];
let first_id = write_commit(commit.clone()).unwrap().0;
let first_commit = backend.read_commit(&first_id).block_on().unwrap();
let first_commit = backend.read_commit(&first_id).block_unwrap();
assert_eq!(first_commit, commit);

// Only non-root commit as parent
commit.parents = vec![first_id.clone()];
let second_id = write_commit(commit.clone()).unwrap().0;
let second_commit = backend.read_commit(&second_id).block_on().unwrap();
let second_commit = backend.read_commit(&second_id).block_unwrap();
assert_eq!(second_commit, commit);

// Merge commit
commit.parents = vec![first_id.clone(), second_id.clone()];
let merge_id = write_commit(commit.clone()).unwrap().0;
let merge_commit = backend.read_commit(&merge_id).block_on().unwrap();
let merge_commit = backend.read_commit(&merge_id).block_unwrap();
assert_eq!(merge_commit, commit);

// Merge commit with root as one parent
commit.parents = vec![first_id, backend.root_commit_id().clone()];
let root_merge_id = write_commit(commit.clone()).unwrap().0;
let root_merge_commit = backend.read_commit(&root_merge_id).block_on().unwrap();
let root_merge_commit = backend.read_commit(&root_merge_id).block_unwrap();
assert_eq!(root_merge_commit, commit);
}

Expand Down
Loading