Tests: Replace modification time in diff with "TIMESTAMP" placeholder

This commit is contained in:
Tanmay Patil
2024-04-14 13:43:30 +05:30
parent 0a77fe12b9
commit 900e1c3a68
4 changed files with 24 additions and 12 deletions
+4 -4
View File
@@ -749,8 +749,8 @@ mod tests {
);
let expected_full = [
"*** target/context-diff/foo\t",
"--- target/context-diff/bar\t",
"*** target/context-diff/foo\tTIMESTAMP",
"--- target/context-diff/bar\tTIMESTAMP",
"***************",
"*** 1,3 ****",
" a",
@@ -777,8 +777,8 @@ mod tests {
);
let expected_brief = [
"*** target/context-diff/foo\t",
"--- target/context-diff/bar\t",
"*** target/context-diff/foo\tTIMESTAMP",
"--- target/context-diff/bar\tTIMESTAMP",
"",
]
.join("\n");
+13 -1
View File
@@ -1,3 +1,15 @@
// asserts equality of the actual diff and expected diff
// considering datetime varitations
//
// It replaces the modification time in the actual diff
// with placeholer "TIMESTAMP" and then asserts the equality
//
// For eg.
// let brief = "*** fruits_old.txt\t2024-03-24 23:43:05.189597645 +0530\n
// --- fruits_new.txt\t2024-03-24 23:35:08.922581904 +0530\n";
//
// replaced = "*** fruits_old.txt\tTIMESTAMP\n
// --- fruits_new.txt\tTIMESTAMP\n";
#[macro_export]
macro_rules! assert_diff_eq {
($actual:expr, $expected:expr) => {{
@@ -6,7 +18,7 @@ macro_rules! assert_diff_eq {
let diff = str::from_utf8(&$actual).unwrap();
let re = Regex::new(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [+-]\d{4}").unwrap();
let actual = re.replace_all(diff, "");
let actual = re.replace_all(diff, "TIMESTAMP");
assert_eq!(actual, $expected);
}};
+4 -4
View File
@@ -903,8 +903,8 @@ mod tests {
);
let expected_full = [
"--- target/context-diff/foo\t",
"+++ target/context-diff/bar\t",
"--- target/context-diff/foo\tTIMESTAMP",
"+++ target/context-diff/bar\tTIMESTAMP",
"@@ -1,3 +1,3 @@",
" a",
"-b",
@@ -927,8 +927,8 @@ mod tests {
);
let expected_brief = [
"--- target/context-diff/foo\t",
"+++ target/context-diff/bar\t",
"--- target/context-diff/foo\tTIMESTAMP",
"+++ target/context-diff/bar\tTIMESTAMP",
"",
]
.join("\n");
+3 -3
View File
@@ -185,7 +185,7 @@ fn read_from_stdin() -> Result<(), Box<dyn std::error::Error>> {
assert_diff_eq!(
output,
format!(
"--- {}\t\n+++ -\t\n@@ -1 +1 @@\n-foo\n+bar\n",
"--- {}\tTIMESTAMP\n+++ -\tTIMESTAMP\n@@ -1 +1 @@\n-foo\n+bar\n",
file1.path().to_string_lossy()
)
);
@@ -201,7 +201,7 @@ fn read_from_stdin() -> Result<(), Box<dyn std::error::Error>> {
assert_diff_eq!(
output,
format!(
"--- -\t\n+++ {}\t\n@@ -1 +1 @@\n-foo\n+bar\n",
"--- -\tTIMESTAMP\n+++ {}\tTIMESTAMP\n@@ -1 +1 @@\n-foo\n+bar\n",
file2.path().to_string_lossy()
)
);
@@ -226,7 +226,7 @@ fn read_from_stdin() -> Result<(), Box<dyn std::error::Error>> {
assert_diff_eq!(
output,
format!(
"--- {}\t\n+++ /dev/stdin\t\n@@ -1 +1 @@\n-foo\n+bar\n",
"--- {}\tTIMESTAMP\n+++ /dev/stdin\tTIMESTAMP\n@@ -1 +1 @@\n-foo\n+bar\n",
file1.path().to_string_lossy()
)
);