forked from mirrors/jj
tests: test views, operations, and mutable repos only with test backend
I don't think the backend type should matter for any of these.
This commit is contained in:
parent
e3f82cd99a
commit
6f53d3a103
3 changed files with 79 additions and 109 deletions
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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();
|
||||
|
|
|
@ -16,8 +16,7 @@ use std::path::Path;
|
|||
|
||||
use jj_lib::backend::{CommitId, ObjectId};
|
||||
use jj_lib::repo::Repo;
|
||||
use test_case::test_case;
|
||||
use testutils::{create_random_commit, write_random_commit, TestRepo, TestRepoBackend};
|
||||
use testutils::{create_random_commit, write_random_commit, TestRepo};
|
||||
|
||||
fn list_dir(dir: &Path) -> Vec<String> {
|
||||
std::fs::read_dir(dir)
|
||||
|
@ -26,12 +25,11 @@ fn list_dir(dir: &Path) -> Vec<String> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
#[test_case(TestRepoBackend::Local ; "local backend")]
|
||||
#[test_case(TestRepoBackend::Git ; "git backend")]
|
||||
fn test_unpublished_operation(backend: TestRepoBackend) {
|
||||
#[test]
|
||||
fn test_unpublished_operation() {
|
||||
// Test that the operation doesn't get published until that's requested.
|
||||
let settings = testutils::user_settings();
|
||||
let test_repo = TestRepo::init_with_backend(backend);
|
||||
let test_repo = TestRepo::init();
|
||||
let repo = &test_repo.repo;
|
||||
|
||||
let op_heads_dir = repo.repo_path().join("op_heads").join("heads");
|
||||
|
@ -48,13 +46,12 @@ fn test_unpublished_operation(backend: TestRepoBackend) {
|
|||
assert_eq!(list_dir(&op_heads_dir), vec![op_id1.hex()]);
|
||||
}
|
||||
|
||||
#[test_case(TestRepoBackend::Local ; "local backend")]
|
||||
#[test_case(TestRepoBackend::Git ; "git backend")]
|
||||
fn test_consecutive_operations(backend: TestRepoBackend) {
|
||||
#[test]
|
||||
fn test_consecutive_operations() {
|
||||
// Test that consecutive operations result in a single op-head on disk after
|
||||
// each operation
|
||||
let settings = testutils::user_settings();
|
||||
let test_repo = TestRepo::init_with_backend(backend);
|
||||
let test_repo = TestRepo::init();
|
||||
let repo = &test_repo.repo;
|
||||
|
||||
let op_heads_dir = repo.repo_path().join("op_heads").join("heads");
|
||||
|
@ -81,13 +78,12 @@ fn test_consecutive_operations(backend: TestRepoBackend) {
|
|||
assert_eq!(list_dir(&op_heads_dir), vec![op_id2.hex()]);
|
||||
}
|
||||
|
||||
#[test_case(TestRepoBackend::Local ; "local backend")]
|
||||
#[test_case(TestRepoBackend::Git ; "git backend")]
|
||||
fn test_concurrent_operations(backend: TestRepoBackend) {
|
||||
#[test]
|
||||
fn test_concurrent_operations() {
|
||||
// Test that consecutive operations result in multiple op-heads on disk until
|
||||
// the repo has been reloaded (which currently happens right away).
|
||||
let settings = testutils::user_settings();
|
||||
let test_repo = TestRepo::init_with_backend(backend);
|
||||
let test_repo = TestRepo::init();
|
||||
let repo = &test_repo.repo;
|
||||
|
||||
let op_heads_dir = repo.repo_path().join("op_heads").join("heads");
|
||||
|
@ -127,12 +123,11 @@ fn assert_heads(repo: &dyn Repo, expected: Vec<&CommitId>) {
|
|||
assert_eq!(*repo.view().heads(), expected);
|
||||
}
|
||||
|
||||
#[test_case(TestRepoBackend::Local ; "local backend")]
|
||||
#[test_case(TestRepoBackend::Git ; "git backend")]
|
||||
fn test_isolation(backend: TestRepoBackend) {
|
||||
#[test]
|
||||
fn test_isolation() {
|
||||
// Test that two concurrent transactions don't see each other's changes.
|
||||
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");
|
||||
|
|
|
@ -18,13 +18,11 @@ use maplit::{btreemap, hashset};
|
|||
use test_case::test_case;
|
||||
use testutils::{
|
||||
commit_transactions, create_random_commit, write_random_commit, CommitGraphBuilder, TestRepo,
|
||||
TestRepoBackend,
|
||||
};
|
||||
|
||||
#[test_case(TestRepoBackend::Local ; "local backend")]
|
||||
#[test_case(TestRepoBackend::Git ; "git backend")]
|
||||
fn test_heads_empty(backend: TestRepoBackend) {
|
||||
let test_repo = TestRepo::init_with_backend(backend);
|
||||
#[test]
|
||||
fn test_heads_empty() {
|
||||
let test_repo = TestRepo::init();
|
||||
let repo = &test_repo.repo;
|
||||
|
||||
assert_eq!(
|
||||
|
@ -37,11 +35,10 @@ fn test_heads_empty(backend: TestRepoBackend) {
|
|||
);
|
||||
}
|
||||
|
||||
#[test_case(TestRepoBackend::Local ; "local backend")]
|
||||
#[test_case(TestRepoBackend::Git ; "git backend")]
|
||||
fn test_heads_fork(backend: TestRepoBackend) {
|
||||
#[test]
|
||||
fn test_heads_fork() {
|
||||
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");
|
||||
|
||||
|
@ -60,11 +57,10 @@ fn test_heads_fork(backend: TestRepoBackend) {
|
|||
);
|
||||
}
|
||||
|
||||
#[test_case(TestRepoBackend::Local ; "local backend")]
|
||||
#[test_case(TestRepoBackend::Git ; "git backend")]
|
||||
fn test_heads_merge(backend: TestRepoBackend) {
|
||||
#[test]
|
||||
fn test_heads_merge() {
|
||||
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");
|
||||
|
||||
|
|
Loading…
Reference in a new issue