tests: compare trees without using .diff_summary()

I don't think modification types matter here. Testing paths should be good
enough.
This commit is contained in:
Yuya Nishihara 2024-08-05 17:30:04 +09:00
parent 0b1a6cd9e0
commit d435a8a793

View file

@ -12,16 +12,29 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use futures::StreamExt as _;
use itertools::Itertools; use itertools::Itertools;
use jj_lib::backend::{ChangeId, MillisSinceEpoch, Signature, Timestamp}; use jj_lib::backend::{ChangeId, MillisSinceEpoch, Signature, Timestamp};
use jj_lib::matchers::EverythingMatcher; use jj_lib::matchers::EverythingMatcher;
use jj_lib::merged_tree::DiffSummary; use jj_lib::merged_tree::MergedTree;
use jj_lib::repo::Repo; use jj_lib::repo::Repo;
use jj_lib::repo_path::{RepoPath, RepoPathBuf}; use jj_lib::repo_path::{RepoPath, RepoPathBuf};
use jj_lib::settings::UserSettings; use jj_lib::settings::UserSettings;
use pollster::FutureExt as _;
use test_case::test_case; use test_case::test_case;
use testutils::{assert_rebased_onto, create_tree, CommitGraphBuilder, TestRepo, TestRepoBackend}; use testutils::{assert_rebased_onto, create_tree, CommitGraphBuilder, TestRepo, TestRepoBackend};
fn diff_paths(from_tree: &MergedTree, to_tree: &MergedTree) -> Vec<RepoPathBuf> {
from_tree
.diff_stream(to_tree, &EverythingMatcher)
.map(|(path, diff)| {
let _ = diff.unwrap();
path
})
.collect()
.block_on()
}
fn to_owned_path_vec(paths: &[&RepoPath]) -> Vec<RepoPathBuf> { fn to_owned_path_vec(paths: &[&RepoPath]) -> Vec<RepoPathBuf> {
paths.iter().map(|&path| path.to_owned()).collect() paths.iter().map(|&path| path.to_owned()).collect()
} }
@ -85,17 +98,11 @@ fn test_initial(backend: TestRepoBackend) {
assert_eq!(commit.author(), &author_signature); assert_eq!(commit.author(), &author_signature);
assert_eq!(commit.committer(), &committer_signature); assert_eq!(commit.committer(), &committer_signature);
assert_eq!( assert_eq!(
store diff_paths(
.root_commit() &store.root_commit().tree().unwrap(),
.tree() &commit.tree().unwrap(),
.unwrap() ),
.diff_summary(&commit.tree().unwrap(), &EverythingMatcher) to_owned_path_vec(&[dir_file_path, root_file_path]),
.unwrap(),
DiffSummary {
modified: vec![],
added: to_owned_path_vec(&[dir_file_path, root_file_path]),
removed: vec![],
}
); );
} }
@ -169,29 +176,18 @@ fn test_rewrite(backend: TestRepoBackend) {
rewrite_settings.user_email() rewrite_settings.user_email()
); );
assert_eq!( assert_eq!(
store diff_paths(
.root_commit() &store.root_commit().tree().unwrap(),
.tree() &rewritten_commit.tree().unwrap(),
.unwrap() ),
.diff_summary(&rewritten_commit.tree().unwrap(), &EverythingMatcher) to_owned_path_vec(&[dir_file_path, root_file_path]),
.unwrap(),
DiffSummary {
modified: vec![],
added: to_owned_path_vec(&[dir_file_path, root_file_path]),
removed: vec![],
}
); );
assert_eq!( assert_eq!(
initial_commit diff_paths(
.tree() &initial_commit.tree().unwrap(),
.unwrap() &rewritten_commit.tree().unwrap(),
.diff_summary(&rewritten_commit.tree().unwrap(), &EverythingMatcher) ),
.unwrap(), to_owned_path_vec(&[dir_file_path]),
DiffSummary {
modified: to_owned_path_vec(&[dir_file_path]),
added: vec![],
removed: vec![],
}
); );
} }