Skip to content

Commit

Permalink
test: use test backend in most remaining tests too
Browse files Browse the repository at this point in the history
I don't think the backend should matter for any of these tests, so
let's test with only one, and let's make that the strictest one - the
new test backend.

This reduces the number of tests by 74 (from 974 to 900), but saves no
measurable run time.
  • Loading branch information
martinvonz committed Sep 24, 2023
1 parent acf84f5 commit f34aae5
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 340 deletions.
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, TestRepoBackend};
use testutils::{CommitGraphBuilder, TestRepo};

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_with_backend(TestRepoBackend::Git);
let test_repo = TestRepo::init();
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_with_backend(TestRepoBackend::Git);
let test_repo = TestRepo::init();
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_with_backend(TestRepoBackend::Git);
let test_repo = TestRepo::init();
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_with_backend(TestRepoBackend::Git);
let test_repo = TestRepo::init();
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_with_backend(TestRepoBackend::Git);
let test_repo = TestRepo::init();
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_with_backend(TestRepoBackend::Git);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

// Tests a more complex case for skipping transitive edges.
Expand Down
38 changes: 16 additions & 22 deletions lib/tests/test_diff_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
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, TestRepoBackend};
use testutils::{create_tree, TestRepo};

#[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);
#[test]
fn test_types() {
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

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

#[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);
#[test]
fn test_tree_file_transition() {
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

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

#[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);
#[test]
fn test_sorting() {
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

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

#[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);
#[test]
fn test_matcher_dir_file_transition() {
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

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

#[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);
#[test]
fn test_matcher_normal_cases() {
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let a_path = RepoPath::from_internal_string("a");
Expand Down
77 changes: 33 additions & 44 deletions lib/tests/test_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ use jj_lib::default_index_store::{
use jj_lib::index::Index as _;
use jj_lib::repo::{MutableRepo, ReadonlyRepo, Repo};
use jj_lib::settings::UserSettings;
use test_case::test_case;
use testutils::{
create_random_commit, load_repo_at_head, write_random_commit, CommitGraphBuilder, TestRepo,
TestRepoBackend,
};

fn child_commit<'repo>(
Expand All @@ -49,10 +47,9 @@ fn to_positions_vec(index: CompositeIndex<'_>, commit_ids: &[CommitId]) -> Vec<I
.collect()
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_index_commits_empty_repo(backend: TestRepoBackend) {
let test_repo = TestRepo::init_with_backend(backend);
#[test]
fn test_index_commits_empty_repo() {
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let index = as_readonly_composite(repo);
Expand All @@ -63,11 +60,10 @@ fn test_index_commits_empty_repo(backend: TestRepoBackend) {
assert_eq!(generation_number(index, repo.store().root_commit_id()), 0);
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_index_commits_standard_cases(backend: TestRepoBackend) {
#[test]
fn test_index_commits_standard_cases() {
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

// o H
Expand Down Expand Up @@ -131,11 +127,10 @@ fn test_index_commits_standard_cases(backend: TestRepoBackend) {
assert!(index.is_ancestor(commit_a.id(), commit_h.id()));
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_index_commits_criss_cross(backend: TestRepoBackend) {
#[test]
fn test_index_commits_criss_cross() {
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let num_generations = 50;
Expand Down Expand Up @@ -264,12 +259,11 @@ fn test_index_commits_criss_cross(backend: TestRepoBackend) {
);
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_index_commits_previous_operations(backend: TestRepoBackend) {
#[test]
fn test_index_commits_previous_operations() {
// Test that commits visible only in previous operations are indexed.
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

// Remove commit B and C in one operation and make sure they're still
Expand Down Expand Up @@ -313,11 +307,10 @@ fn test_index_commits_previous_operations(backend: TestRepoBackend) {
assert_eq!(generation_number(index, commit_c.id()), 3);
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_index_commits_incremental(backend: TestRepoBackend) {
#[test]
fn test_index_commits_incremental() {
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 in one operation, then B and C in another. Check that the index is
Expand Down Expand Up @@ -367,11 +360,10 @@ fn test_index_commits_incremental(backend: TestRepoBackend) {
assert_eq!(generation_number(index, commit_c.id()), 3);
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_index_commits_incremental_empty_transaction(backend: TestRepoBackend) {
#[test]
fn test_index_commits_incremental_empty_transaction() {
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 in one operation, then just an empty transaction. Check that the
Expand Down Expand Up @@ -410,12 +402,11 @@ fn test_index_commits_incremental_empty_transaction(backend: TestRepoBackend) {
assert_eq!(generation_number(index, commit_a.id()), 1);
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_index_commits_incremental_already_indexed(backend: TestRepoBackend) {
#[test]
fn test_index_commits_incremental_already_indexed() {
// Tests that trying to add a commit that's already been added is a no-op.
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 in one operation, then try to add it again an new transaction.
Expand Down Expand Up @@ -483,29 +474,28 @@ fn commits_by_level(repo: &Arc<ReadonlyRepo>) -> Vec<u32> {
.collect()
}

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_index_commits_incremental_squashed(backend: TestRepoBackend) {
#[test]
fn test_index_commits_incremental_squashed() {
let settings = testutils::user_settings();

let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let repo = create_n_commits(&settings, repo, 1);
assert_eq!(commits_by_level(&repo), vec![2]);
let repo = create_n_commits(&settings, &repo, 1);
assert_eq!(commits_by_level(&repo), vec![3]);

let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let repo = create_n_commits(&settings, repo, 2);
assert_eq!(commits_by_level(&repo), vec![3]);

let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let repo = create_n_commits(&settings, repo, 100);
assert_eq!(commits_by_level(&repo), vec![101]);

let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let repo = create_n_commits(&settings, repo, 1);
let repo = create_n_commits(&settings, &repo, 2);
Expand All @@ -515,7 +505,7 @@ fn test_index_commits_incremental_squashed(backend: TestRepoBackend) {
let repo = create_n_commits(&settings, &repo, 32);
assert_eq!(commits_by_level(&repo), vec![64]);

let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let repo = create_n_commits(&settings, repo, 32);
let repo = create_n_commits(&settings, &repo, 16);
Expand All @@ -524,7 +514,7 @@ fn test_index_commits_incremental_squashed(backend: TestRepoBackend) {
let repo = create_n_commits(&settings, &repo, 2);
assert_eq!(commits_by_level(&repo), vec![57, 6]);

let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let repo = create_n_commits(&settings, repo, 30);
let repo = create_n_commits(&settings, &repo, 15);
Expand All @@ -533,7 +523,7 @@ fn test_index_commits_incremental_squashed(backend: TestRepoBackend) {
let repo = create_n_commits(&settings, &repo, 1);
assert_eq!(commits_by_level(&repo), vec![31, 15, 7, 3, 1]);

let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let repo = create_n_commits(&settings, repo, 10);
let repo = create_n_commits(&settings, &repo, 10);
Expand All @@ -549,11 +539,10 @@ fn test_index_commits_incremental_squashed(backend: TestRepoBackend) {

/// Test that .jj/repo/index/type is created when the repo is created, and that
/// it is created when an old repo is loaded.
#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_index_store_type(backend: TestRepoBackend) {
#[test]
fn test_index_store_type() {
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(backend);
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

assert_eq!(as_readonly_composite(repo).num_commits(), 1);
Expand Down
26 changes: 17 additions & 9 deletions lib/tests/test_load_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use jj_lib::repo::{RepoLoader, StoreFactories};
use test_case::test_case;
use testutils::{write_random_commit, TestRepo, TestRepoBackend};
use jj_lib::repo::RepoLoader;
use testutils::{write_random_commit, TestRepo};

#[test_case(TestRepoBackend::Local ; "local backend")]
#[test_case(TestRepoBackend::Git ; "git backend")]
fn test_load_at_operation(backend: TestRepoBackend) {
#[test]
fn test_load_at_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 mut tx = repo.start_transaction(&settings, "add commit");
Expand All @@ -33,13 +31,23 @@ fn test_load_at_operation(backend: TestRepoBackend) {

// If we load the repo at head, we should not see the commit since it was
// removed
let loader = RepoLoader::init(&settings, repo.repo_path(), &StoreFactories::default()).unwrap();
let loader = RepoLoader::init(
&settings,
repo.repo_path(),
&TestRepo::default_store_factories(),
)
.unwrap();
let head_repo = loader.load_at_head(&settings).unwrap();
assert!(!head_repo.view().heads().contains(commit.id()));

// If we load the repo at the previous operation, we should see the commit since
// it has not been removed yet
let loader = RepoLoader::init(&settings, repo.repo_path(), &StoreFactories::default()).unwrap();
let loader = RepoLoader::init(
&settings,
repo.repo_path(),
&TestRepo::default_store_factories(),
)
.unwrap();
let old_repo = loader.load_at(repo.operation()).unwrap();
assert!(old_repo.view().heads().contains(commit.id()));
}
Loading

0 comments on commit f34aae5

Please sign in to comment.