Skip to content

Commit

Permalink
tests: test views, operations, and mutable repos only with test backend
Browse files Browse the repository at this point in the history
I don't think the backend type should matter for any of these.
  • Loading branch information
martinvonz committed Sep 20, 2023
1 parent e3f82cd commit 6f53d3a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 109 deletions.
135 changes: 57 additions & 78 deletions lib/tests/test_mut_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@
use jj_lib::op_store::{RefTarget, WorkspaceId};
use jj_lib::repo::Repo;
use maplit::hashset;
use test_case::test_case;
use testutils::{
assert_rebased, create_random_commit, write_random_commit, CommitGraphBuilder, TestRepo,
TestRepoBackend,
};

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_edit(backend: TestRepoBackend) {
#[test]
fn test_edit() {
// Test that MutableRepo::edit() uses the requested commit (not a new child)
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand All @@ -40,12 +37,11 @@ fn test_edit(backend: TestRepoBackend) {
assert_eq!(repo.view().get_wc_commit_id(&ws_id), Some(wc_commit.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_checkout(backend: TestRepoBackend) {
#[test]
fn test_checkout() {
// Test that MutableRepo::check_out() creates a child
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand All @@ -65,13 +61,12 @@ fn test_checkout(backend: TestRepoBackend) {
assert_eq!(repo.view().get_wc_commit_id(&ws_id), Some(wc_commit.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_checkout_previous_not_empty(backend: TestRepoBackend) {
#[test]
fn test_checkout_previous_not_empty() {
// Test that MutableRepo::check_out() does not usually abandon the previous
// commit.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand All @@ -89,13 +84,12 @@ fn test_checkout_previous_not_empty(backend: TestRepoBackend) {
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_checkout_previous_empty(backend: TestRepoBackend) {
#[test]
fn test_checkout_previous_empty() {
// Test that MutableRepo::check_out() abandons the previous commit if it was
// empty.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand All @@ -120,13 +114,12 @@ fn test_checkout_previous_empty(backend: TestRepoBackend) {
assert!(!mut_repo.view().heads().contains(old_wc_commit.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_checkout_previous_empty_with_description(backend: TestRepoBackend) {
#[test]
fn test_checkout_previous_empty_with_description() {
// Test that MutableRepo::check_out() does not abandon the previous commit if it
// has a non-empty description.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand All @@ -152,13 +145,12 @@ fn test_checkout_previous_empty_with_description(backend: TestRepoBackend) {
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_checkout_previous_empty_with_local_branch(backend: TestRepoBackend) {
#[test]
fn test_checkout_previous_empty_with_local_branch() {
// Test that MutableRepo::check_out() does not abandon the previous commit if it
// is pointed by local branch.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand All @@ -184,13 +176,12 @@ fn test_checkout_previous_empty_with_local_branch(backend: TestRepoBackend) {
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_checkout_previous_empty_non_head(backend: TestRepoBackend) {
#[test]
fn test_checkout_previous_empty_non_head() {
// Test that MutableRepo::check_out() does not abandon the previous commit if it
// was empty and is not a head
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand Down Expand Up @@ -226,13 +217,12 @@ fn test_checkout_previous_empty_non_head(backend: TestRepoBackend) {
);
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_edit_initial(backend: TestRepoBackend) {
#[test]
fn test_edit_initial() {
// Test that MutableRepo::edit() can be used on the initial working-copy commit
// in a workspace
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand All @@ -251,13 +241,12 @@ fn test_edit_initial(backend: TestRepoBackend) {
);
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_add_head_success(backend: TestRepoBackend) {
#[test]
fn test_add_head_success() {
// Test that MutableRepo::add_head() adds the head, and that it's still there
// after commit. It should also be indexed.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

// Create a commit outside of the repo by using a temporary transaction. Then
Expand All @@ -278,13 +267,12 @@ fn test_add_head_success(backend: TestRepoBackend) {
assert!(repo.index().has_id(new_commit.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_add_head_ancestor(backend: TestRepoBackend) {
#[test]
fn test_add_head_ancestor() {
// Test that MutableRepo::add_head() does not add a head if it's an ancestor of
// an existing head.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand All @@ -301,13 +289,12 @@ fn test_add_head_ancestor(backend: TestRepoBackend) {
assert_eq!(repo.view().heads(), &hashset! {commit3.id().clone()});
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_add_head_not_immediate_child(backend: TestRepoBackend) {
#[test]
fn test_add_head_not_immediate_child() {
// Test that MutableRepo::add_head() can be used for adding a head that is not
// an immediate child of a current head.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand Down Expand Up @@ -341,14 +328,13 @@ fn test_add_head_not_immediate_child(backend: TestRepoBackend) {
assert!(mut_repo.index().has_id(child.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_remove_head(backend: TestRepoBackend) {
#[test]
fn test_remove_head() {
// Test that MutableRepo::remove_head() removes the head, and that it's still
// removed after commit. It should remain in the index, since we otherwise would
// have to reindex everything.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand Down Expand Up @@ -379,13 +365,12 @@ fn test_remove_head(backend: TestRepoBackend) {
assert!(repo.index().has_id(commit3.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_add_public_head(backend: TestRepoBackend) {
#[test]
fn test_add_public_head() {
// Test that MutableRepo::add_public_head() adds the head, and that it's still
// there after commit.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand All @@ -401,13 +386,12 @@ fn test_add_public_head(backend: TestRepoBackend) {
assert!(repo.view().public_heads().contains(commit1.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_add_public_head_ancestor(backend: TestRepoBackend) {
#[test]
fn test_add_public_head_ancestor() {
// Test that MutableRepo::add_public_head() does not add a public head if it's
// an ancestor of an existing public head.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand All @@ -426,13 +410,12 @@ fn test_add_public_head_ancestor(backend: TestRepoBackend) {
assert!(!repo.view().public_heads().contains(commit1.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_remove_public_head(backend: TestRepoBackend) {
#[test]
fn test_remove_public_head() {
// Test that MutableRepo::remove_public_head() removes the head, and that it's
// still removed after commit.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand All @@ -450,14 +433,13 @@ fn test_remove_public_head(backend: TestRepoBackend) {
assert!(!repo.view().public_heads().contains(commit1.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_has_changed(backend: TestRepoBackend) {
#[test]
fn test_has_changed() {
// Test that MutableRepo::has_changed() reports changes iff the view has changed
// (e.g. not after setting a branch to point to where it was already
// pointing).
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand Down Expand Up @@ -528,14 +510,13 @@ fn test_has_changed(backend: TestRepoBackend) {
assert!(!mut_repo.has_changes());
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_rebase_descendants_simple(backend: TestRepoBackend) {
#[test]
fn test_rebase_descendants_simple() {
// Tests that MutableRepo::create_descendant_rebaser() creates a
// DescendantRebaser that rebases descendants of rewritten and abandoned
// commits.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand Down Expand Up @@ -567,13 +548,12 @@ fn test_rebase_descendants_simple(backend: TestRepoBackend) {
.is_none());
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_rebase_descendants_conflicting_rewrite(backend: TestRepoBackend) {
#[test]
fn test_rebase_descendants_conflicting_rewrite() {
// Tests MutableRepo::create_descendant_rebaser() when a commit has been marked
// as rewritten to several other commits.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings, "test");
Expand Down Expand Up @@ -602,11 +582,10 @@ fn test_rebase_descendants_conflicting_rewrite(backend: TestRepoBackend) {
.is_none());
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_rename_remote(backend: TestRepoBackend) {
#[test]
fn test_rename_remote() {
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let mut tx = repo.start_transaction(&settings, "test");
let mut_repo = tx.mut_repo();
Expand Down
Loading

0 comments on commit 6f53d3a

Please sign in to comment.