tests: move commit_transactions() helper to testutils

This commit is contained in:
Yuya Nishihara 2023-08-09 17:14:10 +09:00
parent dd3b4bfb33
commit 552c71ed36
2 changed files with 22 additions and 23 deletions

View file

@ -12,15 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::sync::Arc;
use jj_lib::op_store::{BranchTarget, RefTarget, WorkspaceId};
use jj_lib::repo::{ReadonlyRepo, Repo};
use jj_lib::settings::UserSettings;
use jj_lib::transaction::Transaction;
use jj_lib::repo::Repo;
use maplit::{btreemap, hashset};
use test_case::test_case;
use testutils::{create_random_commit, write_random_commit, CommitGraphBuilder, TestRepo};
use testutils::{
commit_transactions, create_random_commit, write_random_commit, CommitGraphBuilder, TestRepo,
};
#[test_case(false ; "local backend")]
#[test_case(true ; "git backend")]
@ -450,23 +448,6 @@ fn test_merge_views_git_heads() {
assert_eq!(repo.view().git_head(), &expected_git_head);
}
fn commit_transactions(settings: &UserSettings, txs: Vec<Transaction>) -> Arc<ReadonlyRepo> {
let repo_loader = txs[0].base_repo().loader();
let mut op_ids = vec![];
for tx in txs {
op_ids.push(tx.commit().op_id().clone());
std::thread::sleep(std::time::Duration::from_millis(1));
}
let repo = repo_loader.load_at_head(settings).unwrap();
// Test the setup. The assumption here is that the parent order matches the
// order in which they were merged (which currently matches the transaction
// commit order), so we want to know make sure they appear in a certain
// order, so the caller can decide the order by passing them to this
// function in a certain order.
assert_eq!(*repo.operation().parent_ids(), op_ids);
repo
}
#[test]
fn test_merge_views_divergent() {
// We start with just commit A. Operation 1 rewrites it as A2. Operation 2

View file

@ -28,6 +28,7 @@ use jj_lib::repo_path::RepoPath;
use jj_lib::rewrite::RebasedDescendant;
use jj_lib::settings::UserSettings;
use jj_lib::store::Store;
use jj_lib::transaction::Transaction;
use jj_lib::tree::Tree;
use jj_lib::tree_builder::TreeBuilder;
use jj_lib::working_copy::SnapshotOptions;
@ -183,6 +184,23 @@ pub fn load_repo_at_head(settings: &UserSettings, repo_path: &Path) -> Arc<Reado
.unwrap()
}
pub fn commit_transactions(settings: &UserSettings, txs: Vec<Transaction>) -> Arc<ReadonlyRepo> {
let repo_loader = txs[0].base_repo().loader();
let mut op_ids = vec![];
for tx in txs {
op_ids.push(tx.commit().op_id().clone());
std::thread::sleep(std::time::Duration::from_millis(1));
}
let repo = repo_loader.load_at_head(settings).unwrap();
// Test the setup. The assumption here is that the parent order matches the
// order in which they were merged (which currently matches the transaction
// commit order), so we want to know make sure they appear in a certain
// order, so the caller can decide the order by passing them to this
// function in a certain order.
assert_eq!(*repo.operation().parent_ids(), op_ids);
repo
}
pub fn read_file(store: &Store, path: &RepoPath, id: &FileId) -> Vec<u8> {
let mut reader = store.read_file(path, id).unwrap();
let mut content = vec![];