Skip to content

Commit 9c30d75

Browse files
committed
testutils: delete bool-typed init() in favor of enum-typed version
It makes the call sites clearer if we pass the `TestRepoBackend` enum instead of the boolean `use_git` value. It's also more extensible (I plan to add another backend for tests).
1 parent 50596c4 commit 9c30d75

25 files changed

+605
-619
lines changed

cli/src/merge_tools/builtin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,13 @@ pub fn edit_merge_builtin(
543543
mod tests {
544544
use jj_lib::conflicts::extract_as_single_hunk;
545545
use jj_lib::repo::Repo;
546-
use testutils::TestRepo;
546+
use testutils::{TestRepo, TestRepoBackend};
547547

548548
use super::*;
549549

550550
#[test]
551551
fn test_edit_diff_builtin() {
552-
let test_repo = TestRepo::init(false);
552+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
553553
let store = test_repo.repo.store();
554554

555555
let unused_path = RepoPath::from_internal_string("unused");
@@ -691,7 +691,7 @@ mod tests {
691691

692692
#[test]
693693
fn test_make_merge_sections() {
694-
let test_repo = TestRepo::init(false);
694+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
695695
let store = test_repo.repo.store();
696696

697697
let path = RepoPath::from_internal_string("file");

lib/tests/test_bad_locking.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use itertools::Itertools;
1818
use jj_lib::repo::{Repo, StoreFactories};
1919
use jj_lib::workspace::Workspace;
2020
use test_case::test_case;
21-
use testutils::{create_random_commit, load_repo_at_head, TestWorkspace};
21+
use testutils::{create_random_commit, load_repo_at_head, TestRepoBackend, TestWorkspace};
2222

2323
fn copy_directory(src: &Path, dst: &Path) {
2424
std::fs::create_dir(dst).ok();
@@ -95,13 +95,13 @@ fn merge_directories(left: &Path, base: &Path, right: &Path, output: &Path) {
9595
}
9696
}
9797

98-
#[test_case(false ; "local backend")]
99-
#[test_case(true ; "git backend")]
100-
fn test_bad_locking_children(use_git: bool) {
98+
#[test_case(TestRepoBackend::Local; "local backend")]
99+
#[test_case(TestRepoBackend::Git; "git backend")]
100+
fn test_bad_locking_children(backend: TestRepoBackend) {
101101
// Test that two new commits created on separate machines are both visible (not
102102
// lost due to lack of locking)
103103
let settings = testutils::user_settings();
104-
let test_workspace = TestWorkspace::init(&settings, use_git);
104+
let test_workspace = TestWorkspace::init_with_backend(&settings, backend);
105105
let repo = &test_workspace.repo;
106106
let workspace_root = test_workspace.workspace.workspace_root();
107107

@@ -161,14 +161,14 @@ fn test_bad_locking_children(use_git: bool) {
161161
assert_eq!(op.parents.len(), 2);
162162
}
163163

164-
#[test_case(false ; "local backend")]
165-
#[test_case(true ; "git backend")]
166-
fn test_bad_locking_interrupted(use_git: bool) {
164+
#[test_case(TestRepoBackend::Local ; "local backend")]
165+
#[test_case(TestRepoBackend::Git ; "git backend")]
166+
fn test_bad_locking_interrupted(backend: TestRepoBackend) {
167167
// Test that an interrupted update of the op-heads resulting in on op-head
168168
// that's a descendant of the other is resolved without creating a new
169169
// operation.
170170
let settings = testutils::user_settings();
171-
let test_workspace = TestWorkspace::init(&settings, use_git);
171+
let test_workspace = TestWorkspace::init_with_backend(&settings, backend);
172172
let repo = &test_workspace.repo;
173173

174174
let mut tx = repo.start_transaction(&settings, "test");

lib/tests/test_commit_builder.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ use jj_lib::repo::Repo;
1919
use jj_lib::repo_path::RepoPath;
2020
use jj_lib::settings::UserSettings;
2121
use test_case::test_case;
22-
use testutils::{assert_rebased, create_tree, CommitGraphBuilder, TestRepo};
22+
use testutils::{assert_rebased, create_tree, CommitGraphBuilder, TestRepo, TestRepoBackend};
2323

24-
#[test_case(false ; "local backend")]
25-
#[test_case(true ; "git backend")]
26-
fn test_initial(use_git: bool) {
24+
#[test_case(TestRepoBackend::Local ; "local backend")]
25+
#[test_case(TestRepoBackend::Git ; "git backend")]
26+
fn test_initial(backend: TestRepoBackend) {
2727
let settings = testutils::user_settings();
28-
let test_repo = TestRepo::init(use_git);
28+
let test_repo = TestRepo::init_with_backend(backend);
2929
let repo = &test_repo.repo;
3030
let store = repo.store();
3131

@@ -92,11 +92,11 @@ fn test_initial(use_git: bool) {
9292
);
9393
}
9494

95-
#[test_case(false ; "local backend")]
96-
#[test_case(true ; "git backend")]
97-
fn test_rewrite(use_git: bool) {
95+
#[test_case(TestRepoBackend::Local ; "local backend")]
96+
#[test_case(TestRepoBackend::Git ; "git backend")]
97+
fn test_rewrite(backend: TestRepoBackend) {
9898
let settings = testutils::user_settings();
99-
let test_repo = TestRepo::init(use_git);
99+
let test_repo = TestRepo::init_with_backend(backend);
100100
let repo = &test_repo.repo;
101101
let store = repo.store().clone();
102102

@@ -188,12 +188,12 @@ fn test_rewrite(use_git: bool) {
188188
}
189189

190190
// An author field with an empty name/email should get filled in on rewrite
191-
#[test_case(false ; "local backend")]
192-
#[test_case(true ; "git backend")]
193-
fn test_rewrite_update_missing_user(use_git: bool) {
191+
#[test_case(TestRepoBackend::Local ; "local backend")]
192+
#[test_case(TestRepoBackend::Git ; "git backend")]
193+
fn test_rewrite_update_missing_user(backend: TestRepoBackend) {
194194
let missing_user_settings =
195195
UserSettings::from_config(config::Config::builder().build().unwrap());
196-
let test_repo = TestRepo::init(use_git);
196+
let test_repo = TestRepo::init_with_backend(backend);
197197
let repo = &test_repo.repo;
198198

199199
let mut tx = repo.start_transaction(&missing_user_settings, "test");
@@ -237,11 +237,11 @@ fn test_rewrite_update_missing_user(use_git: bool) {
237237
);
238238
}
239239

240-
#[test_case(false ; "local backend")]
241-
// #[test_case(true ; "git backend")]
242-
fn test_commit_builder_descendants(use_git: bool) {
240+
#[test_case(TestRepoBackend::Local ; "local backend")]
241+
// #[test_case(TestRepoBackend::Git ; "git backend")]
242+
fn test_commit_builder_descendants(backend: TestRepoBackend) {
243243
let settings = testutils::user_settings();
244-
let test_repo = TestRepo::init(use_git);
244+
let test_repo = TestRepo::init_with_backend(backend);
245245
let repo = &test_repo.repo;
246246
let store = repo.store().clone();
247247

lib/tests/test_commit_concurrent.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::thread;
1919
use jj_lib::dag_walk;
2020
use jj_lib::repo::{ReadonlyRepo, Repo};
2121
use test_case::test_case;
22-
use testutils::{load_repo_at_head, write_random_commit, TestWorkspace};
22+
use testutils::{load_repo_at_head, write_random_commit, TestRepoBackend, TestWorkspace};
2323

2424
fn count_non_merge_operations(repo: &Arc<ReadonlyRepo>) -> usize {
2525
let op_store = repo.op_store();
@@ -38,14 +38,14 @@ fn count_non_merge_operations(repo: &Arc<ReadonlyRepo>) -> usize {
3838
num_ops
3939
}
4040

41-
#[test_case(false ; "local backend")]
42-
#[test_case(true ; "git backend")]
43-
fn test_commit_parallel(use_git: bool) {
41+
#[test_case(TestRepoBackend::Local ; "local backend")]
42+
#[test_case(TestRepoBackend::Git ; "git backend")]
43+
fn test_commit_parallel(backend: TestRepoBackend) {
4444
// This loads a Repo instance and creates and commits many concurrent
4545
// transactions from it. It then reloads the repo. That should merge all the
4646
// operations and all commits should be visible.
4747
let settings = testutils::user_settings();
48-
let test_workspace = TestWorkspace::init(&settings, use_git);
48+
let test_workspace = TestWorkspace::init_with_backend(&settings, backend);
4949
let repo = &test_workspace.repo;
5050

5151
let num_threads = max(num_cpus::get(), 4);
@@ -70,13 +70,13 @@ fn test_commit_parallel(use_git: bool) {
7070
assert_eq!(count_non_merge_operations(&repo), num_threads + 2);
7171
}
7272

73-
#[test_case(false ; "local backend")]
74-
#[test_case(true ; "git backend")]
75-
fn test_commit_parallel_instances(use_git: bool) {
73+
#[test_case(TestRepoBackend::Local ; "local backend")]
74+
#[test_case(TestRepoBackend::Git ; "git backend")]
75+
fn test_commit_parallel_instances(backend: TestRepoBackend) {
7676
// Like the test above but creates a new repo instance for every thread, which
7777
// makes it behave very similar to separate processes.
7878
let settings = testutils::user_settings();
79-
let test_workspace = TestWorkspace::init(&settings, use_git);
79+
let test_workspace = TestWorkspace::init_with_backend(&settings, backend);
8080
let repo = &test_workspace.repo;
8181

8282
let num_threads = max(num_cpus::get(), 4);

lib/tests/test_conflicts.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ use jj_lib::merge::Merge;
2020
use jj_lib::repo::Repo;
2121
use jj_lib::repo_path::RepoPath;
2222
use jj_lib::store::Store;
23-
use testutils::TestRepo;
23+
use testutils::{TestRepo, TestRepoBackend};
2424

2525
#[test]
2626
fn test_materialize_conflict_basic() {
27-
let test_repo = TestRepo::init(false);
27+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
2828
let store = test_repo.repo.store();
2929

3030
let path = RepoPath::from_internal_string("file");
@@ -113,7 +113,7 @@ line 5
113113

114114
#[test]
115115
fn test_materialize_conflict_multi_rebase_conflicts() {
116-
let test_repo = TestRepo::init(false);
116+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
117117
let store = test_repo.repo.store();
118118

119119
// Create changes (a, b, c) on top of the base, and linearize them.
@@ -232,7 +232,7 @@ line 3
232232

233233
#[test]
234234
fn test_materialize_parse_roundtrip() {
235-
let test_repo = TestRepo::init(false);
235+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
236236
let store = test_repo.repo.store();
237237

238238
let path = RepoPath::from_internal_string("file");
@@ -334,7 +334,7 @@ line 5 right
334334

335335
#[test]
336336
fn test_materialize_conflict_modify_delete() {
337-
let test_repo = TestRepo::init(false);
337+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
338338
let store = test_repo.repo.store();
339339

340340
let path = RepoPath::from_internal_string("file");
@@ -614,7 +614,7 @@ line 5
614614

615615
#[test]
616616
fn test_update_conflict_from_content() {
617-
let test_repo = TestRepo::init(false);
617+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
618618
let store = test_repo.repo.store();
619619

620620
let path = RepoPath::from_internal_string("dir/file");
@@ -665,7 +665,7 @@ fn test_update_conflict_from_content() {
665665

666666
#[test]
667667
fn test_update_conflict_from_content_modify_delete() {
668-
let test_repo = TestRepo::init(false);
668+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
669669
let store = test_repo.repo.store();
670670

671671
let path = RepoPath::from_internal_string("dir/file");

lib/tests/test_default_revset_graph_iterator.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use jj_lib::repo::{ReadonlyRepo, Repo as _};
2020
use jj_lib::revset::ResolvedExpression;
2121
use jj_lib::revset_graph::RevsetGraphEdge;
2222
use test_case::test_case;
23-
use testutils::{CommitGraphBuilder, TestRepo};
23+
use testutils::{CommitGraphBuilder, TestRepo, TestRepoBackend};
2424

2525
fn revset_for_commits<'index>(
2626
repo: &'index ReadonlyRepo,
@@ -53,7 +53,7 @@ fn missing(commit: &Commit) -> RevsetGraphEdge {
5353
#[test_case(true ; "skip transitive edges")]
5454
fn test_graph_iterator_linearized(skip_transitive_edges: bool) {
5555
let settings = testutils::user_settings();
56-
let test_repo = TestRepo::init(true);
56+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git);
5757
let repo = &test_repo.repo;
5858

5959
// Tests that a fork and a merge becomes a single edge:
@@ -89,7 +89,7 @@ fn test_graph_iterator_linearized(skip_transitive_edges: bool) {
8989
#[test_case(true ; "skip transitive edges")]
9090
fn test_graph_iterator_virtual_octopus(skip_transitive_edges: bool) {
9191
let settings = testutils::user_settings();
92-
let test_repo = TestRepo::init(true);
92+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git);
9393
let repo = &test_repo.repo;
9494

9595
// Tests that merges outside the set can result in more parent edges than there
@@ -140,7 +140,7 @@ fn test_graph_iterator_virtual_octopus(skip_transitive_edges: bool) {
140140
#[test_case(true ; "skip transitive edges")]
141141
fn test_graph_iterator_simple_fork(skip_transitive_edges: bool) {
142142
let settings = testutils::user_settings();
143-
let test_repo = TestRepo::init(true);
143+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git);
144144
let repo = &test_repo.repo;
145145

146146
// Tests that the branch with "C" gets emitted correctly:
@@ -182,7 +182,7 @@ fn test_graph_iterator_simple_fork(skip_transitive_edges: bool) {
182182
#[test_case(true ; "skip transitive edges")]
183183
fn test_graph_iterator_multiple_missing(skip_transitive_edges: bool) {
184184
let settings = testutils::user_settings();
185-
let test_repo = TestRepo::init(true);
185+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git);
186186
let repo = &test_repo.repo;
187187

188188
// Tests that we get missing edges to "a" and "c" and not just one missing edge
@@ -224,7 +224,7 @@ fn test_graph_iterator_multiple_missing(skip_transitive_edges: bool) {
224224
#[test_case(true ; "skip transitive edges")]
225225
fn test_graph_iterator_edge_to_ancestor(skip_transitive_edges: bool) {
226226
let settings = testutils::user_settings();
227-
let test_repo = TestRepo::init(true);
227+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git);
228228
let repo = &test_repo.repo;
229229

230230
// Tests that we get both an edge from F to D and to D's ancestor C if we keep
@@ -271,7 +271,7 @@ fn test_graph_iterator_edge_to_ancestor(skip_transitive_edges: bool) {
271271
#[test_case(true ; "skip transitive edges")]
272272
fn test_graph_iterator_edge_escapes_from_(skip_transitive_edges: bool) {
273273
let settings = testutils::user_settings();
274-
let test_repo = TestRepo::init(true);
274+
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git);
275275
let repo = &test_repo.repo;
276276

277277
// Tests a more complex case for skipping transitive edges.

lib/tests/test_diff_summary.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ use jj_lib::matchers::{EverythingMatcher, FilesMatcher};
1616
use jj_lib::merged_tree::DiffSummary;
1717
use jj_lib::repo_path::RepoPath;
1818
use test_case::test_case;
19-
use testutils::{create_tree, TestRepo};
19+
use testutils::{create_tree, TestRepo, TestRepoBackend};
2020

21-
#[test_case(false ; "local backend")]
22-
#[test_case(true ; "git backend")]
23-
fn test_types(use_git: bool) {
24-
let test_repo = TestRepo::init(use_git);
21+
#[test_case(TestRepoBackend::Local ; "local backend")]
22+
#[test_case(TestRepoBackend::Git ; "git backend")]
23+
fn test_types(backend: TestRepoBackend) {
24+
let test_repo = TestRepo::init_with_backend(backend);
2525
let repo = &test_repo.repo;
2626

2727
let clean_path = RepoPath::from_internal_string("clean");
@@ -57,10 +57,10 @@ fn test_types(use_git: bool) {
5757
);
5858
}
5959

60-
#[test_case(false ; "local backend")]
61-
#[test_case(true ; "git backend")]
62-
fn test_tree_file_transition(use_git: bool) {
63-
let test_repo = TestRepo::init(use_git);
60+
#[test_case(TestRepoBackend::Local ; "local backend")]
61+
#[test_case(TestRepoBackend::Git ; "git backend")]
62+
fn test_tree_file_transition(backend: TestRepoBackend) {
63+
let test_repo = TestRepo::init_with_backend(backend);
6464
let repo = &test_repo.repo;
6565

6666
let dir_file_path = RepoPath::from_internal_string("dir/file");
@@ -87,10 +87,10 @@ fn test_tree_file_transition(use_git: bool) {
8787
);
8888
}
8989

90-
#[test_case(false ; "local backend")]
91-
#[test_case(true ; "git backend")]
92-
fn test_sorting(use_git: bool) {
93-
let test_repo = TestRepo::init(use_git);
90+
#[test_case(TestRepoBackend::Local ; "local backend")]
91+
#[test_case(TestRepoBackend::Git ; "git backend")]
92+
fn test_sorting(backend: TestRepoBackend) {
93+
let test_repo = TestRepo::init_with_backend(backend);
9494
let repo = &test_repo.repo;
9595

9696
let a_path = RepoPath::from_internal_string("a");
@@ -152,10 +152,10 @@ fn test_sorting(use_git: bool) {
152152
);
153153
}
154154

155-
#[test_case(false ; "local backend")]
156-
#[test_case(true ; "git backend")]
157-
fn test_matcher_dir_file_transition(use_git: bool) {
158-
let test_repo = TestRepo::init(use_git);
155+
#[test_case(TestRepoBackend::Local ; "local backend")]
156+
#[test_case(TestRepoBackend::Git ; "git backend")]
157+
fn test_matcher_dir_file_transition(backend: TestRepoBackend) {
158+
let test_repo = TestRepo::init_with_backend(backend);
159159
let repo = &test_repo.repo;
160160

161161
let a_path = RepoPath::from_internal_string("a");
@@ -219,10 +219,10 @@ fn test_matcher_dir_file_transition(use_git: bool) {
219219
);
220220
}
221221

222-
#[test_case(false ; "local backend")]
223-
#[test_case(true ; "git backend")]
224-
fn test_matcher_normal_cases(use_git: bool) {
225-
let test_repo = TestRepo::init(use_git);
222+
#[test_case(TestRepoBackend::Local ; "local backend")]
223+
#[test_case(TestRepoBackend::Git ; "git backend")]
224+
fn test_matcher_normal_cases(backend: TestRepoBackend) {
225+
let test_repo = TestRepo::init_with_backend(backend);
226226
let repo = &test_repo.repo;
227227

228228
let a_path = RepoPath::from_internal_string("a");

0 commit comments

Comments
 (0)