Skip to content

Commit d58a9f3

Browse files
committed
refactor(common): supersede assert_equivalent fun with a macro
As it produce the error directly in the caller test, allowing to give the line of the failure.
1 parent 8467d3b commit d58a9f3

File tree

9 files changed

+35
-44
lines changed

9 files changed

+35
-44
lines changed

mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ mod tests {
345345
.await
346346
.unwrap();
347347

348-
assert_equivalent(
348+
assert_equivalent!(
349349
locations,
350350
vec![AncillaryLocation::CloudStorage {
351351
uri: "an_uri".to_string(),
@@ -385,7 +385,7 @@ mod tests {
385385
.await
386386
.unwrap();
387387

388-
assert_equivalent(
388+
assert_equivalent!(
389389
locations,
390390
vec![
391391
AncillaryLocation::CloudStorage {

mithril-aggregator/src/artifact_builder/cardano_database_artifacts/digest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ mod tests {
522522

523523
let locations = builder.upload_digest_file(&FileArchive::dummy()).await.unwrap();
524524

525-
assert_equivalent(
525+
assert_equivalent!(
526526
locations,
527527
vec![
528528
DigestLocation::CloudStorage {
@@ -562,7 +562,7 @@ mod tests {
562562

563563
let locations = builder.upload_digest_file(&FileArchive::dummy()).await.unwrap();
564564

565-
assert_equivalent(
565+
assert_equivalent!(
566566
locations,
567567
vec![
568568
DigestLocation::CloudStorage {

mithril-aggregator/src/artifact_builder/cardano_database_artifacts/immutable.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ mod tests {
383383

384384
let upload = builder.upload(2).await.unwrap();
385385

386-
assert_equivalent(
386+
assert_equivalent!(
387387
upload.locations,
388388
vec![ImmutablesLocation::CloudStorage {
389389
uri: MultiFilesUri::Template(TemplateUri("archive.tar.gz".to_string())),
@@ -469,7 +469,7 @@ mod tests {
469469
.await
470470
.unwrap();
471471

472-
assert_equivalent(
472+
assert_equivalent!(
473473
archive_paths,
474474
vec![
475475
work_dir.join("00000.tar.gz"),
@@ -641,7 +641,7 @@ mod tests {
641641
.await
642642
.unwrap();
643643

644-
assert_equivalent(
644+
assert_equivalent!(
645645
archive_paths,
646646
vec![
647647
work_dir.join("00000.tar.gz"),
@@ -683,7 +683,7 @@ mod tests {
683683
.await
684684
.unwrap();
685685

686-
assert_equivalent(
686+
assert_equivalent!(
687687
archive_paths,
688688
vec![
689689
work_dir.join("00000.tar.gz"),
@@ -794,7 +794,7 @@ mod tests {
794794
.await
795795
.unwrap();
796796

797-
assert_equivalent(
797+
assert_equivalent!(
798798
archive_paths,
799799
vec![ImmutablesLocation::CloudStorage {
800800
uri: MultiFilesUri::Template(TemplateUri("archive_2.tar.gz".to_string())),
@@ -836,7 +836,7 @@ mod tests {
836836
.await
837837
.unwrap();
838838

839-
assert_equivalent(
839+
assert_equivalent!(
840840
archive_paths,
841841
vec![
842842
ImmutablesLocation::CloudStorage {

mithril-aggregator/src/commands/config_association.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ macro_rules! extract_all {
7373
mod tests {
7474
use std::collections::HashMap;
7575

76-
use mithril_common::assert_equivalent_macro;
76+
use mithril_common::assert_equivalent;
7777
use mithril_doc::StructDoc;
7878

7979
#[allow(dead_code)]
@@ -167,7 +167,7 @@ mod tests {
167167
"mithril commande subcommande".to_string(),
168168
];
169169

170-
assert_equivalent_macro!(expected, keys);
170+
assert_equivalent!(expected, keys);
171171
}
172172

173173
#[test]

mithril-aggregator/src/database/repository/immutable_file_digest_repository.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ mod tests {
191191
let all_immutable_file_digests =
192192
repository.get_all_immutable_file_digest().await.unwrap();
193193

194-
assert_equivalent(
194+
assert_equivalent!(
195195
vec![
196196
ImmutableFileDigestRecord {
197197
immutable_file_name: "123.chunk".to_string(),

mithril-aggregator/src/http_server/routes/proof_routes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,6 @@ mod tests {
443443
transaction_hashes: format!("{tx1},{tx2},{tx2},{tx1},{tx2}",),
444444
};
445445

446-
assert_equivalent(params.sanitize(), vec![tx1, tx2]);
446+
assert_equivalent!(params.sanitize(), vec![tx1, tx2]);
447447
}
448448
}

mithril-aggregator/src/services/snapshotter/compressed_archive_snapshotter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ mod tests {
470470
let unpacked_files = list_files(&unpack_dir);
471471
let unpacked_immutable_files = list_files(&unpack_dir.join(IMMUTABLE_DIR));
472472

473-
assert_equivalent(vec![IMMUTABLE_DIR.to_string()], unpacked_files);
474-
assert_equivalent(
473+
assert_equivalent!(vec![IMMUTABLE_DIR.to_string()], unpacked_files);
474+
assert_equivalent!(
475475
vec![
476476
"00001.chunk".to_string(),
477477
"00001.primary".to_string(),
@@ -510,8 +510,8 @@ mod tests {
510510
let unpacked_files = list_files(&unpack_dir);
511511
let unpacked_immutable_files = list_files(&unpack_dir.join(IMMUTABLE_DIR));
512512

513-
assert_equivalent(vec![IMMUTABLE_DIR.to_string()], unpacked_files);
514-
assert_equivalent(
513+
assert_equivalent!(vec![IMMUTABLE_DIR.to_string()], unpacked_files);
514+
assert_equivalent!(
515515
vec![
516516
"00002.chunk".to_string(),
517517
"00002.primary".to_string(),

mithril-aggregator/src/tools/file_archiver/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ mod tests {
400400
.expect_err("FileArchiver::archive should fail if the db is empty.");
401401
let remaining_files: Vec<String> = list_remaining_files(&test_dir);
402402

403-
assert_equivalent(
403+
assert_equivalent!(
404404
vec!["other-process.file".to_string(), "archive.tar.gz".to_string()],
405405
remaining_files,
406406
);

mithril-common/src/test/assert/iters_equivalent.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,19 @@ where
1010
a == b
1111
}
1212

13-
/// Assert that two iterators are equivalent
14-
pub fn assert_equivalent<T, I1, I2>(a: I1, b: I2)
15-
where
16-
T: PartialEq + Ord + std::fmt::Debug,
17-
I1: IntoIterator<Item = T> + Clone,
18-
I2: IntoIterator<Item = T> + Clone,
19-
{
20-
let a = as_sorted_vec(a);
21-
let b = as_sorted_vec(b);
22-
assert_eq!(a, b);
23-
}
24-
2513
/// Assert that two iterators are equivalent
2614
#[macro_export]
27-
macro_rules! assert_equivalent_macro {
28-
( $expected:expr, $actual:expr ) => {{
29-
let expected = $crate::test::as_sorted_vec($expected);
30-
let actual = $crate::test::as_sorted_vec($actual);
31-
assert_eq!(expected, actual);
15+
macro_rules! assert_equivalent {
16+
($expected:expr, $actual:expr $(,)?) => {{
17+
let expected = $expected;
18+
let actual = $actual;
19+
assert_eq!(
20+
$crate::test::as_sorted_vec(expected),
21+
$crate::test::as_sorted_vec(actual)
22+
);
3223
}};
3324
}
34-
pub use assert_equivalent_macro;
25+
pub use assert_equivalent;
3526

3627
/// Create a sorted clone of an iterable.
3728
pub fn as_sorted_vec<T: Ord, I: IntoIterator<Item = T> + Clone>(iter: I) -> Vec<T> {
@@ -59,13 +50,13 @@ mod tests {
5950
assert!(equivalent_to(vec![1, 2, 3], HashSet::from([3, 2, 1])));
6051
assert!(equivalent_to(&vec![1, 2, 3], &HashSet::from([3, 2, 1])));
6152

62-
assert_equivalent(vec![1, 2, 3], vec![3, 2, 1]);
63-
assert_equivalent(vec![1, 2, 3], vec![2, 1, 3]);
53+
assert_equivalent!(vec![1, 2, 3], vec![3, 2, 1]);
54+
assert_equivalent!(vec![1, 2, 3], vec![2, 1, 3]);
6455

65-
assert_equivalent([1, 2, 3], vec![3, 2, 1]);
66-
assert_equivalent(&[1, 2, 3], &vec![3, 2, 1]);
67-
assert_equivalent([1, 2, 3], HashSet::from([3, 2, 1]));
68-
assert_equivalent(vec![1, 2, 3], HashSet::from([3, 2, 1]));
69-
assert_equivalent(&vec![1, 2, 3], &HashSet::from([3, 2, 1]));
56+
assert_equivalent!([1, 2, 3], vec![3, 2, 1]);
57+
assert_equivalent!(&[1, 2, 3], &vec![3, 2, 1]);
58+
assert_equivalent!([1, 2, 3], HashSet::from([3, 2, 1]));
59+
assert_equivalent!(vec![1, 2, 3], HashSet::from([3, 2, 1]));
60+
assert_equivalent!(&vec![1, 2, 3], &HashSet::from([3, 2, 1]));
7061
}
7162
}

0 commit comments

Comments
 (0)