Skip to content

Commit

Permalink
testutils: delete bool-typed init() in favor of enum-typed version
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
martinvonz committed Sep 18, 2023
1 parent 76e9de5 commit 0b24a17
Show file tree
Hide file tree
Showing 25 changed files with 605 additions and 619 deletions.
6 changes: 3 additions & 3 deletions cli/src/merge_tools/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,13 @@ pub fn edit_merge_builtin(
mod tests {
use jj_lib::conflicts::extract_as_single_hunk;
use jj_lib::repo::Repo;
use testutils::TestRepo;
use testutils::{TestRepo, TestRepoBackend};

use super::*;

#[test]
fn test_edit_diff_builtin() {
let test_repo = TestRepo::init(false);
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
let store = test_repo.repo.store();

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

#[test]
fn test_make_merge_sections() {
let test_repo = TestRepo::init(false);
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
let store = test_repo.repo.store();

let path = RepoPath::from_internal_string("file");
Expand Down
18 changes: 9 additions & 9 deletions lib/tests/test_bad_locking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use itertools::Itertools;
use jj_lib::repo::{Repo, StoreFactories};
use jj_lib::workspace::Workspace;
use test_case::test_case;
use testutils::{create_random_commit, load_repo_at_head, TestWorkspace};
use testutils::{create_random_commit, load_repo_at_head, TestRepoBackend, TestWorkspace};

fn copy_directory(src: &Path, dst: &Path) {
std::fs::create_dir(dst).ok();
Expand Down Expand Up @@ -95,13 +95,13 @@ fn merge_directories(left: &Path, base: &Path, right: &Path, output: &Path) {
}
}

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

Expand Down Expand Up @@ -161,14 +161,14 @@ fn test_bad_locking_children(use_git: bool) {
assert_eq!(op.parents.len(), 2);
}

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

let mut tx = repo.start_transaction(&settings, "test");
Expand Down
34 changes: 17 additions & 17 deletions lib/tests/test_commit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ use jj_lib::repo::Repo;
use jj_lib::repo_path::RepoPath;
use jj_lib::settings::UserSettings;
use test_case::test_case;
use testutils::{assert_rebased, create_tree, CommitGraphBuilder, TestRepo};
use testutils::{assert_rebased, create_tree, CommitGraphBuilder, TestRepo, TestRepoBackend};

#[test_case(false ; "local backend")]
#[test_case(true ; "git backend")]
fn test_initial(use_git: bool) {
#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_initial(backend: TestRepoBackend) {
let settings = testutils::user_settings();
let test_repo = TestRepo::init(use_git);
let test_repo = TestRepo::init_with_backend(backend);
let repo = &test_repo.repo;
let store = repo.store();

Expand Down Expand Up @@ -92,11 +92,11 @@ fn test_initial(use_git: bool) {
);
}

#[test_case(false ; "local backend")]
#[test_case(true ; "git backend")]
fn test_rewrite(use_git: bool) {
#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_rewrite(backend: TestRepoBackend) {
let settings = testutils::user_settings();
let test_repo = TestRepo::init(use_git);
let test_repo = TestRepo::init_with_backend(backend);
let repo = &test_repo.repo;
let store = repo.store().clone();

Expand Down Expand Up @@ -188,12 +188,12 @@ fn test_rewrite(use_git: bool) {
}

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

let mut tx = repo.start_transaction(&missing_user_settings, "test");
Expand Down Expand Up @@ -237,11 +237,11 @@ fn test_rewrite_update_missing_user(use_git: bool) {
);
}

#[test_case(false ; "local backend")]
// #[test_case(true ; "git backend")]
fn test_commit_builder_descendants(use_git: bool) {
#[test_case(TestRepoBackend::Local ; "local backend")]
// #[test_case(TestRepoBackend::Git ; "git backend")]
fn test_commit_builder_descendants(backend: TestRepoBackend) {
let settings = testutils::user_settings();
let test_repo = TestRepo::init(use_git);
let test_repo = TestRepo::init_with_backend(backend);
let repo = &test_repo.repo;
let store = repo.store().clone();

Expand Down
18 changes: 9 additions & 9 deletions lib/tests/test_commit_concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::thread;
use jj_lib::dag_walk;
use jj_lib::repo::{ReadonlyRepo, Repo};
use test_case::test_case;
use testutils::{load_repo_at_head, write_random_commit, TestWorkspace};
use testutils::{load_repo_at_head, write_random_commit, TestRepoBackend, TestWorkspace};

fn count_non_merge_operations(repo: &Arc<ReadonlyRepo>) -> usize {
let op_store = repo.op_store();
Expand All @@ -38,14 +38,14 @@ fn count_non_merge_operations(repo: &Arc<ReadonlyRepo>) -> usize {
num_ops
}

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

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

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

let num_threads = max(num_cpus::get(), 4);
Expand Down
14 changes: 7 additions & 7 deletions lib/tests/test_conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use jj_lib::merge::Merge;
use jj_lib::repo::Repo;
use jj_lib::repo_path::RepoPath;
use jj_lib::store::Store;
use testutils::TestRepo;
use testutils::{TestRepo, TestRepoBackend};

#[test]
fn test_materialize_conflict_basic() {
let test_repo = TestRepo::init(false);
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
let store = test_repo.repo.store();

let path = RepoPath::from_internal_string("file");
Expand Down Expand Up @@ -113,7 +113,7 @@ line 5

#[test]
fn test_materialize_conflict_multi_rebase_conflicts() {
let test_repo = TestRepo::init(false);
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
let store = test_repo.repo.store();

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

#[test]
fn test_materialize_parse_roundtrip() {
let test_repo = TestRepo::init(false);
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
let store = test_repo.repo.store();

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

#[test]
fn test_materialize_conflict_modify_delete() {
let test_repo = TestRepo::init(false);
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
let store = test_repo.repo.store();

let path = RepoPath::from_internal_string("file");
Expand Down Expand Up @@ -614,7 +614,7 @@ line 5

#[test]
fn test_update_conflict_from_content() {
let test_repo = TestRepo::init(false);
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
let store = test_repo.repo.store();

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

#[test]
fn test_update_conflict_from_content_modify_delete() {
let test_repo = TestRepo::init(false);
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Local);
let store = test_repo.repo.store();

let path = RepoPath::from_internal_string("dir/file");
Expand Down
14 changes: 7 additions & 7 deletions lib/tests/test_default_revset_graph_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use jj_lib::repo::{ReadonlyRepo, Repo as _};
use jj_lib::revset::ResolvedExpression;
use jj_lib::revset_graph::RevsetGraphEdge;
use test_case::test_case;
use testutils::{CommitGraphBuilder, TestRepo};
use testutils::{CommitGraphBuilder, TestRepo, TestRepoBackend};

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

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

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

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

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

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

// Tests a more complex case for skipping transitive edges.
Expand Down
42 changes: 21 additions & 21 deletions lib/tests/test_diff_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use jj_lib::matchers::{EverythingMatcher, FilesMatcher};
use jj_lib::merged_tree::DiffSummary;
use jj_lib::repo_path::RepoPath;
use test_case::test_case;
use testutils::{create_tree, TestRepo};
use testutils::{create_tree, TestRepo, TestRepoBackend};

#[test_case(false ; "local backend")]
#[test_case(true ; "git backend")]
fn test_types(use_git: bool) {
let test_repo = TestRepo::init(use_git);
#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_types(backend: TestRepoBackend) {
let test_repo = TestRepo::init_with_backend(backend);
let repo = &test_repo.repo;

let clean_path = RepoPath::from_internal_string("clean");
Expand Down Expand Up @@ -57,10 +57,10 @@ fn test_types(use_git: bool) {
);
}

#[test_case(false ; "local backend")]
#[test_case(true ; "git backend")]
fn test_tree_file_transition(use_git: bool) {
let test_repo = TestRepo::init(use_git);
#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_tree_file_transition(backend: TestRepoBackend) {
let test_repo = TestRepo::init_with_backend(backend);
let repo = &test_repo.repo;

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

#[test_case(false ; "local backend")]
#[test_case(true ; "git backend")]
fn test_sorting(use_git: bool) {
let test_repo = TestRepo::init(use_git);
#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_sorting(backend: TestRepoBackend) {
let test_repo = TestRepo::init_with_backend(backend);
let repo = &test_repo.repo;

let a_path = RepoPath::from_internal_string("a");
Expand Down Expand Up @@ -152,10 +152,10 @@ fn test_sorting(use_git: bool) {
);
}

#[test_case(false ; "local backend")]
#[test_case(true ; "git backend")]
fn test_matcher_dir_file_transition(use_git: bool) {
let test_repo = TestRepo::init(use_git);
#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_matcher_dir_file_transition(backend: TestRepoBackend) {
let test_repo = TestRepo::init_with_backend(backend);
let repo = &test_repo.repo;

let a_path = RepoPath::from_internal_string("a");
Expand Down Expand Up @@ -219,10 +219,10 @@ fn test_matcher_dir_file_transition(use_git: bool) {
);
}

#[test_case(false ; "local backend")]
#[test_case(true ; "git backend")]
fn test_matcher_normal_cases(use_git: bool) {
let test_repo = TestRepo::init(use_git);
#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_matcher_normal_cases(backend: TestRepoBackend) {
let test_repo = TestRepo::init_with_backend(backend);
let repo = &test_repo.repo;

let a_path = RepoPath::from_internal_string("a");
Expand Down
Loading

0 comments on commit 0b24a17

Please sign in to comment.