The common approach is to remove (as shown by @RomanPrrekhrest) or replace those things with something that is the same for both files.
For instance, here you could replace both [BEFORE_TEST] and [AFTER_TEST] with [*_TEST], or you could replace some Sep 8 18:10:03 timestamps with <timestamp> or Mmm dd HH:MM:SS or *** ** **:**:**.
massage() {
sed -Ee '
s/\[[[:alnum:]_]+_TEST\]/[*_TEST]/g
s/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ 0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/*** ** **:**:**/g
' -- "$@"
}
diff -w -u -- <(massage test1) <(massage test2)
(here also using -w as there are also differences in whitespace between your two files)
Which gives:
$ diff -wu <(massage test1) <(massage test2)
--- /proc/self/fd/11 2024-09-12 06:13:08.008529281 +0100
+++ /proc/self/fd/18 2024-09-12 06:13:08.008529281 +0100
@@ -1,2 +1,2 @@
-[*_TEST] WARN: message1
+[*_TEST] PASS: message1
[*_TEST] NOTICE: message
With some sed implementations, you can replace the [[:alnum:]_] with \w and in some (rarer) [0-9] with \d (or switch to perl -pe which recognises both).
As a cherry on the cake, you could also do (assuming GNU stat and GNU diff):
massaged_label() {
stat -c $'--label=massaged_%n\t%y' -- "$@"
}
diff -w -u "$(massaged_label test1)" "$(massaged_label test2)" \
-- <(massage test1) <(massage test2)
Which gives:
--- massaged_test1 2024-09-12 06:12:55.376015083 +0100
+++ massaged_test2 2024-09-12 06:13:03.495702763 +0100
@@ -1,2 +1,2 @@
-[*_TEST] WARN: message1
+[*_TEST] PASS: message1
[*_TEST] NOTICE: message
Where the header indicates which files are being diffed along with their last modification time and that they've been massaged.
In any case, that output cannot be used as input to patch (or only on the massaged versions of the files).
NOTICE, then a trailing space aftermessageintest1, but respectively two space characters and no trailing space intest2. Is this just clumsiness of the question? Or is this a real thing and you want solutions that ignore such differences as well?