Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an enum for backend to use in tests #2265

Merged
merged 4 commits into from
Sep 18, 2023
Merged
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
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
86 changes: 46 additions & 40 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 All @@ -38,45 +38,51 @@ fn merge_directories(left: &Path, base: &Path, right: &Path, output: &Path) {
std::fs::create_dir(output).unwrap();
let mut sub_dirs = vec![];
// Walk the left side and copy to the output
for entry in std::fs::read_dir(left).unwrap() {
let path = entry.unwrap().path();
let base_name = path.file_name().unwrap();
let child_left = left.join(base_name);
let child_output = output.join(base_name);
if child_left.is_dir() {
sub_dirs.push(base_name.to_os_string());
} else {
std::fs::copy(&child_left, child_output).unwrap();
if left.exists() {
for entry in std::fs::read_dir(left).unwrap() {
let path = entry.unwrap().path();
let base_name = path.file_name().unwrap();
let child_left = left.join(base_name);
let child_output = output.join(base_name);
if child_left.is_dir() {
sub_dirs.push(base_name.to_os_string());
} else {
std::fs::copy(&child_left, child_output).unwrap();
}
}
}
// Walk the base and find files removed in the right side, then remove them in
// the output
for entry in std::fs::read_dir(base).unwrap() {
let path = entry.unwrap().path();
let base_name = path.file_name().unwrap();
let child_base = base.join(base_name);
let child_right = right.join(base_name);
let child_output = output.join(base_name);
if child_base.is_dir() {
sub_dirs.push(base_name.to_os_string());
} else if !child_right.exists() {
std::fs::remove_file(child_output).ok();
if base.exists() {
for entry in std::fs::read_dir(base).unwrap() {
let path = entry.unwrap().path();
let base_name = path.file_name().unwrap();
let child_base = base.join(base_name);
let child_right = right.join(base_name);
let child_output = output.join(base_name);
if child_base.is_dir() {
sub_dirs.push(base_name.to_os_string());
} else if !child_right.exists() {
std::fs::remove_file(child_output).ok();
}
}
}
// Walk the right side and find files added in the right side, then add them in
// the output
for entry in std::fs::read_dir(right).unwrap() {
let path = entry.unwrap().path();
let base_name = path.file_name().unwrap();
let child_base = base.join(base_name);
let child_right = right.join(base_name);
let child_output = output.join(base_name);
if child_right.is_dir() {
sub_dirs.push(base_name.to_os_string());
} else if !child_base.exists() {
// This overwrites the left side if that's been written. That's fine, since the
// point of the test is that it should be okay for either side to win.
std::fs::copy(&child_right, child_output).unwrap();
if right.exists() {
for entry in std::fs::read_dir(right).unwrap() {
let path = entry.unwrap().path();
let base_name = path.file_name().unwrap();
let child_base = base.join(base_name);
let child_right = right.join(base_name);
let child_output = output.join(base_name);
if child_right.is_dir() {
sub_dirs.push(base_name.to_os_string());
} else if !child_base.exists() {
// This overwrites the left side if that's been written. That's fine, since the
// point of the test is that it should be okay for either side to win.
std::fs::copy(&child_right, child_output).unwrap();
}
}
}
// Do the merge in subdirectories
Expand All @@ -89,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 @@ -155,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
Loading