Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
tests: Replace another ~600 unwrap()s in tests with ?
  • Loading branch information
ilyagr authored and glehmann committed Mar 18, 2026
commit e758f76002486d55704b078b534bb0874174f514
4 changes: 2 additions & 2 deletions cli/src/merge_tools/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ mod tests {
let tree = tree_builder.write_merged_tree();

let merge_tool_file = MergeToolFile::from_tree_and_path(&tree, file_path).block_on()?;
let merge_file = make_merge_file(&merge_tool_file, store.merge_options()).unwrap();
let merge_file = make_merge_file(&merge_tool_file, store.merge_options())?;
let tree = apply_merge_builtin(store, &tree, vec![file_path.to_owned()], &[merge_file])
.block_on()?;

Expand Down Expand Up @@ -2098,7 +2098,7 @@ mod tests {
]);
let content = extract_as_single_hunk(&merge, store, path).block_on()?;
let merge_result = files::merge_hunks(&content, store.merge_options());
let sections = make_merge_sections(merge_result).unwrap();
let sections = make_merge_sections(merge_result)?;
insta::assert_debug_snapshot!(sections, @r#"
[
Changed {
Expand Down
151 changes: 62 additions & 89 deletions lib/src/git_backend.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions lib/src/simple_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,25 +545,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_id = write_commit(commit.clone())?.0;
let first_commit = backend.read_commit(&first_id).block_on()?;
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_id = write_commit(commit.clone())?.0;
let second_commit = backend.read_commit(&second_id).block_on()?;
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_id = write_commit(commit.clone())?.0;
let merge_commit = backend.read_commit(&merge_id).block_on()?;
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_id = write_commit(commit.clone())?.0;
let root_merge_commit = backend.read_commit(&root_merge_id).block_on()?;
assert_eq!(root_merge_commit, commit);
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions lib/src/simple_op_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ mod tests {
let root_data = RootOperationData {
root_commit_id: CommitId::from_hex("000000"),
};
let store = SimpleOpStore::init(temp_dir.path(), root_data).unwrap();
let store = SimpleOpStore::init(temp_dir.path(), root_data)?;
let view = create_view();
let view_id = store.write_view(&view).block_on()?;
let read_view = store.read_view(&view_id).block_on()?;
Expand All @@ -1084,7 +1084,7 @@ mod tests {
let root_data = RootOperationData {
root_commit_id: CommitId::from_hex("000000"),
};
let store = SimpleOpStore::init(temp_dir.path(), root_data).unwrap();
let store = SimpleOpStore::init(temp_dir.path(), root_data)?;
let operation = create_operation();
let op_id = store.write_operation(&operation).block_on()?;
let read_operation = store.read_operation(&op_id).block_on()?;
Expand Down
9 changes: 3 additions & 6 deletions lib/tests/test_bad_locking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ fn test_bad_locking_children(backend: TestRepoBackend) -> TestResult {
&machine1_root,
&StoreFactories::default(),
&default_working_copy_factories(),
)
.unwrap();
)?;
let machine1_repo = machine1_workspace.repo_loader().load_at_head().block_on()?;
let mut machine1_tx = machine1_repo.start_transaction();
let child1 = write_random_commit_with_parents(machine1_tx.repo_mut(), &[&initial]);
Expand All @@ -139,8 +138,7 @@ fn test_bad_locking_children(backend: TestRepoBackend) -> TestResult {
&machine2_root,
&StoreFactories::default(),
&default_working_copy_factories(),
)
.unwrap();
)?;
let machine2_repo = machine2_workspace.repo_loader().load_at_head().block_on()?;
let mut machine2_tx = machine2_repo.start_transaction();
let child2 = write_random_commit_with_parents(machine2_tx.repo_mut(), &[&initial]);
Expand All @@ -155,8 +153,7 @@ fn test_bad_locking_children(backend: TestRepoBackend) -> TestResult {
&merged_path,
&StoreFactories::default(),
&default_working_copy_factories(),
)
.unwrap();
)?;
let merged_repo = merged_workspace.repo_loader().load_at_head().block_on()?;
assert!(merged_repo.view().heads().contains(child1.id()));
assert!(merged_repo.view().heads().contains(child2.id()));
Expand Down
53 changes: 22 additions & 31 deletions lib/tests/test_commit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,21 @@ fn test_rewrite(backend: TestRepoBackend) -> TestResult {
);

let mut config = StackedConfig::with_defaults();
config.add_layer(
ConfigLayer::parse(
ConfigSource::User,
indoc! {"
config.add_layer(ConfigLayer::parse(
ConfigSource::User,
indoc! {"
user.name = 'Rewrite User'
user.email = 'rewrite.user@example.com'
"},
)
.unwrap(),
);
let rewrite_settings = UserSettings::from_config(config).unwrap();
)?);
let rewrite_settings = UserSettings::from_config(config)?;
let repo = test_env.load_repo_at_head(&rewrite_settings, test_repo.repo_path());
let store = repo.store();
// We have a new store instance, so we need to associate the old tree with the
// new store instance.
let (tree_ids, labels) = rewritten_tree.into_tree_ids_and_labels();
let rewritten_tree = MergedTree::new(store.clone(), tree_ids, labels);
let initial_commit = store.get_commit(initial_commit.id()).unwrap();
let initial_commit = store.get_commit(initial_commit.id())?;
let mut tx = repo.start_transaction();
let rewritten_commit = tx
.repo_mut()
Expand Down Expand Up @@ -238,7 +235,7 @@ fn test_rewrite(backend: TestRepoBackend) -> TestResult {
#[test_case(TestRepoBackend::Simple ; "simple backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_rewrite_update_missing_user(backend: TestRepoBackend) -> TestResult {
let missing_user_settings = UserSettings::from_config(StackedConfig::with_defaults()).unwrap();
let missing_user_settings = UserSettings::from_config(StackedConfig::with_defaults())?;
let test_repo = TestRepo::init_with_backend_and_settings(backend, &missing_user_settings);
let test_env = &test_repo.env;
let repo = &test_repo.repo;
Expand All @@ -258,19 +255,16 @@ fn test_rewrite_update_missing_user(backend: TestRepoBackend) -> TestResult {
tx.commit("test").block_on()?;

let mut config = StackedConfig::with_defaults();
config.add_layer(
ConfigLayer::parse(
ConfigSource::User,
indoc! {"
config.add_layer(ConfigLayer::parse(
ConfigSource::User,
indoc! {"
user.name = 'Configured User'
user.email = 'configured.user@example.com'
"},
)
.unwrap(),
);
let settings = UserSettings::from_config(config).unwrap();
)?);
let settings = UserSettings::from_config(config)?;
let repo = test_env.load_repo_at_head(&settings, test_repo.repo_path());
let initial_commit = repo.store().get_commit(initial_commit.id()).unwrap();
let initial_commit = repo.store().get_commit(initial_commit.id())?;
let mut tx = repo.start_transaction();
let rewritten_commit = tx.repo_mut().rewrite_commit(&initial_commit).write_unwrap();

Expand All @@ -295,8 +289,7 @@ fn test_rewrite_resets_author_timestamp(backend: TestRepoBackend) -> TestResult

// Create discardable commit
let initial_timestamp = "2001-02-03T04:05:06+07:00";
let settings =
UserSettings::from_config(config_with_commit_timestamp(initial_timestamp)).unwrap();
let settings = UserSettings::from_config(config_with_commit_timestamp(initial_timestamp))?;
let repo = test_env.load_repo_at_head(&settings, test_repo.repo_path());
let mut tx = repo.start_transaction();
let initial_commit = tx
Expand All @@ -309,16 +302,15 @@ fn test_rewrite_resets_author_timestamp(backend: TestRepoBackend) -> TestResult
tx.commit("test").block_on()?;

let initial_timestamp =
Timestamp::from_datetime(chrono::DateTime::parse_from_rfc3339(initial_timestamp).unwrap());
Timestamp::from_datetime(chrono::DateTime::parse_from_rfc3339(initial_timestamp)?);
assert_eq!(initial_commit.author().timestamp, initial_timestamp);
assert_eq!(initial_commit.committer().timestamp, initial_timestamp);

// Rewrite discardable commit to no longer be discardable
let new_timestamp_1 = "2002-03-04T05:06:07+08:00";
let settings =
UserSettings::from_config(config_with_commit_timestamp(new_timestamp_1)).unwrap();
let settings = UserSettings::from_config(config_with_commit_timestamp(new_timestamp_1))?;
let repo = test_env.load_repo_at_head(&settings, test_repo.repo_path());
let initial_commit = repo.store().get_commit(initial_commit.id()).unwrap();
let initial_commit = repo.store().get_commit(initial_commit.id())?;
let mut tx = repo.start_transaction();
let rewritten_commit_1 = tx
.repo_mut()
Expand All @@ -329,7 +321,7 @@ fn test_rewrite_resets_author_timestamp(backend: TestRepoBackend) -> TestResult
tx.commit("test").block_on()?;

let new_timestamp_1 =
Timestamp::from_datetime(chrono::DateTime::parse_from_rfc3339(new_timestamp_1).unwrap());
Timestamp::from_datetime(chrono::DateTime::parse_from_rfc3339(new_timestamp_1)?);
assert_ne!(new_timestamp_1, initial_timestamp);

assert_eq!(rewritten_commit_1.author().timestamp, new_timestamp_1);
Expand All @@ -338,10 +330,9 @@ fn test_rewrite_resets_author_timestamp(backend: TestRepoBackend) -> TestResult

// Rewrite non-discardable commit
let new_timestamp_2 = "2003-04-05T06:07:08+09:00";
let settings =
UserSettings::from_config(config_with_commit_timestamp(new_timestamp_2)).unwrap();
let settings = UserSettings::from_config(config_with_commit_timestamp(new_timestamp_2))?;
let repo = test_env.load_repo_at_head(&settings, test_repo.repo_path());
let rewritten_commit_1 = repo.store().get_commit(rewritten_commit_1.id()).unwrap();
let rewritten_commit_1 = repo.store().get_commit(rewritten_commit_1.id())?;
let mut tx = repo.start_transaction();
let rewritten_commit_2 = tx
.repo_mut()
Expand All @@ -352,7 +343,7 @@ fn test_rewrite_resets_author_timestamp(backend: TestRepoBackend) -> TestResult
tx.commit("test").block_on()?;

let new_timestamp_2 =
Timestamp::from_datetime(chrono::DateTime::parse_from_rfc3339(new_timestamp_2).unwrap());
Timestamp::from_datetime(chrono::DateTime::parse_from_rfc3339(new_timestamp_2)?);
assert_ne!(new_timestamp_2, new_timestamp_1);

assert_eq!(rewritten_commit_2.author().timestamp, new_timestamp_1);
Expand All @@ -364,7 +355,7 @@ fn test_rewrite_resets_author_timestamp(backend: TestRepoBackend) -> TestResult
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_rewrite_to_identical_commit(backend: TestRepoBackend) -> TestResult {
let timestamp = "2001-02-03T04:05:06+07:00";
let settings = UserSettings::from_config(config_with_commit_timestamp(timestamp)).unwrap();
let settings = UserSettings::from_config(config_with_commit_timestamp(timestamp))?;
let test_repo = TestRepo::init_with_backend_and_settings(backend, &settings);
let repo = test_repo.repo;
let store = repo.store();
Expand Down
18 changes: 6 additions & 12 deletions lib/tests/test_default_revset_graph_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ fn test_graph_iterator_linearized(skip_transitive_edges: bool, padding: u32) ->
let revset = revset_for_commits(repo.as_ref(), &[&commit_a, &commit_d]);
let commits: Vec<_> = revset
.iter_graph_impl(skip_transitive_edges)
.try_collect()
.unwrap();
.try_collect()?;
assert_eq!(commits.len(), 2);
assert_eq!(commits[0].0, *commit_d.id());
assert_eq!(commits[1].0, *commit_a.id());
Expand Down Expand Up @@ -123,8 +122,7 @@ fn test_graph_iterator_virtual_octopus(skip_transitive_edges: bool, padding: u32
let revset = revset_for_commits(repo.as_ref(), &[&commit_a, &commit_b, &commit_c, &commit_f]);
let commits: Vec<_> = revset
.iter_graph_impl(skip_transitive_edges)
.try_collect()
.unwrap();
.try_collect()?;
assert_eq!(commits.len(), 4);
assert_eq!(commits[0].0, *commit_f.id());
assert_eq!(commits[1].0, *commit_c.id());
Expand Down Expand Up @@ -178,8 +176,7 @@ fn test_graph_iterator_simple_fork(skip_transitive_edges: bool, padding: u32) ->
let revset = revset_for_commits(repo.as_ref(), &[&commit_a, &commit_c, &commit_e]);
let commits: Vec<_> = revset
.iter_graph_impl(skip_transitive_edges)
.try_collect()
.unwrap();
.try_collect()?;
assert_eq!(commits.len(), 3);
assert_eq!(commits[0].0, *commit_e.id());
assert_eq!(commits[1].0, *commit_c.id());
Expand Down Expand Up @@ -223,8 +220,7 @@ fn test_graph_iterator_multiple_missing(skip_transitive_edges: bool, padding: u3
let revset = revset_for_commits(repo.as_ref(), &[&commit_b, &commit_f]);
let commits: Vec<_> = revset
.iter_graph_impl(skip_transitive_edges)
.try_collect()
.unwrap();
.try_collect()?;
assert_eq!(commits.len(), 2);
assert_eq!(commits[0].0, *commit_f.id());
assert_eq!(commits[1].0, *commit_b.id());
Expand Down Expand Up @@ -271,8 +267,7 @@ fn test_graph_iterator_edge_to_ancestor(skip_transitive_edges: bool, padding: u3
let revset = revset_for_commits(repo.as_ref(), &[&commit_c, &commit_d, &commit_f]);
let commits: Vec<_> = revset
.iter_graph_impl(skip_transitive_edges)
.try_collect()
.unwrap();
.try_collect()?;
assert_eq!(commits.len(), 3);
assert_eq!(commits[0].0, *commit_f.id());
assert_eq!(commits[1].0, *commit_d.id());
Expand Down Expand Up @@ -334,8 +329,7 @@ fn test_graph_iterator_edge_escapes_from_(skip_transitive_edges: bool, padding:
);
let commits: Vec<_> = revset
.iter_graph_impl(skip_transitive_edges)
.try_collect()
.unwrap();
.try_collect()?;
assert_eq!(commits.len(), 5);
assert_eq!(commits[0].0, *commit_j.id());
assert_eq!(commits[1].0, *commit_h.id());
Expand Down
6 changes: 2 additions & 4 deletions lib/tests/test_evolution_predecessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,9 @@ fn test_accumulate_predecessors() -> TestResult {
// Stabilize commit IDs
let mut config = testutils::base_user_config();
let mut layer = ConfigLayer::empty(ConfigSource::User);
layer
.set_value("debug.commit-timestamp", "2001-02-03T04:05:06+07:00")
.unwrap();
layer.set_value("debug.commit-timestamp", "2001-02-03T04:05:06+07:00")?;
config.add_layer(layer);
let settings = UserSettings::from_config(config).unwrap();
let settings = UserSettings::from_config(config)?;

let test_repo = TestRepo::init_with_settings(&settings);
let repo_0 = test_repo.repo;
Expand Down
21 changes: 7 additions & 14 deletions lib/tests/test_fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ fn test_fix_one_file() -> TestResult {

let new_commit_a = repo
.store()
.get_commit(summary.rewrites.get(&commit_a).unwrap())
.unwrap();
.get_commit(summary.rewrites.get(&commit_a).unwrap())?;
assert_tree_eq!(new_commit_a.tree(), expected_tree_a);
Ok(())
}
Expand Down Expand Up @@ -287,8 +286,7 @@ fn test_unchanged_file_is_fixed() -> TestResult {

let new_commit_b = repo
.store()
.get_commit(summary.rewrites.get(&commit_b).unwrap())
.unwrap();
.get_commit(summary.rewrites.get(&commit_b).unwrap())?;
assert_tree_eq!(new_commit_b.tree(), expected_tree_b);
Ok(())
}
Expand Down Expand Up @@ -328,13 +326,11 @@ fn test_already_fixed_descendant() -> TestResult {

let new_commit_a = repo
.store()
.get_commit(summary.rewrites.get(&commit_a).unwrap())
.unwrap();
.get_commit(summary.rewrites.get(&commit_a).unwrap())?;
assert_tree_eq!(new_commit_a.tree(), tree2);
let new_commit_b = repo
.store()
.get_commit(summary.rewrites.get(&commit_a).unwrap())
.unwrap();
.get_commit(summary.rewrites.get(&commit_a).unwrap())?;
assert_tree_eq!(new_commit_b.tree(), tree2);
Ok(())
}
Expand Down Expand Up @@ -370,8 +366,7 @@ fn test_parallel_fixer_basic() -> TestResult {

let new_commit_a = repo
.store()
.get_commit(summary.rewrites.get(&commit_a).unwrap())
.unwrap();
.get_commit(summary.rewrites.get(&commit_a).unwrap())?;
assert_tree_eq!(new_commit_a.tree(), expected_tree_a);
Ok(())
}
Expand Down Expand Up @@ -415,8 +410,7 @@ fn test_parallel_fixer_fixes_files() -> TestResult {

let new_commit_a = repo
.store()
.get_commit(summary.rewrites.get(&commit_a).unwrap())
.unwrap();
.get_commit(summary.rewrites.get(&commit_a).unwrap())?;
assert_tree_eq!(new_commit_a.tree(), expected_tree_a);
Ok(())
}
Expand Down Expand Up @@ -534,8 +528,7 @@ fn test_fix_multiple_revisions() -> TestResult {

let new_commit_a = repo
.store()
.get_commit(summary.rewrites.get(&commit_a).unwrap())
.unwrap();
.get_commit(summary.rewrites.get(&commit_a).unwrap())?;
assert_tree_eq!(new_commit_a.tree(), expected_tree_a);
Ok(())
}
Loading