Fix flaky blame-jump-message test

This test fails occasionally[1] because the order of events and the
number of events varies across runs.

We should always call draw_status exactly 3 times:

                        [*git*][fifo]
                        [*git*]
    Commit subject etc. [*git*]

Let's check it this way.
This seems to work; this time I took the time to run it a couple
hundred times and in Cirrus CI.

[1] https://builds.sr.ht/~mawww/job/1151239
This commit is contained in:
Johannes Altmanninger 2024-02-18 01:16:53 +01:00 committed by Maxime Coste
parent 5f0729f155
commit f786fceb73
2 changed files with 25 additions and 10 deletions

View File

@ -136,6 +136,13 @@ fail_ifn() {
fi fi
} }
assert_eq() {
if [ ! "$1" = "$2" ]; then
fail_ifn
printf "${indent} ${red}- %s\n${indent} ${green}+ %s${none}\n" "$1" "$2"
fi
}
show_diff() { show_diff() {
diff -u $1 $2 | while IFS='' read -r line; do diff -u $1 $2 | while IFS='' read -r line; do
first_character=$(printf '%s\n' "$line" | cut -b 1) first_character=$(printf '%s\n' "$line" | cut -b 1)
@ -183,6 +190,13 @@ ui_out() {
skip_count=$(( skip_count - 1 )) skip_count=$(( skip_count - 1 ))
done done
;; ;;
-until-grep)
shift
while
read -r event <&4
! printf %s "$event" | grep "$@"
do :; done
;;
-within-next) -within-next)
shift shift
candidate_count=$1 candidate_count=$1
@ -208,10 +222,7 @@ ui_out() {
;; ;;
*) *)
read -r event <&4 read -r event <&4
if [ ! "$1" = "$event" ]; then assert_eq "$1" "$event"
fail_ifn
printf "${indent} ${red}- %s\n${indent} ${green}+ %s${none}\n" "$1" "$event"
fi
;; ;;
esac esac
shift shift

View File

@ -1,10 +1,14 @@
ui_out -ignore 7 for _ in fifo-opened fifo-closed blame-info
ui_out -ignore 4 do
actual_draw_status=$(ui_out -until-grep draw_status)
done
ui_out -ignore 3 expected_subject=$(cat <<'EOF'
subject=$(cat <<'EOF'
2017-07-14 A U Thor "Don't break on single quotes or unbalanced {" 2017-07-14 A U Thor "Don't break on single quotes or unbalanced {"
EOF EOF
) )
json_quoted_subject=\"$(printf '%s' "$subject" | sed 's/"/\\"/g')\" expected_subject_json=\"$(printf '%s' "$expected_subject" | sed 's/"/\\"/g')\"
ui_out -within-next 3 '{ "jsonrpc": "2.0", "method": "draw_status", "params": [[{ "face": { "fg": "black", "bg": "yellow", "underline": "default", "attributes": [] }, "contents": '"$json_quoted_subject"' }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "*git* 13:2 " }, { "face": { "fg": "black", "bg": "yellow", "underline": "default", "attributes": [] }, "contents": "[scratch]" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " - client0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "underline": "default", "attributes": [] }] }' expected_draw_status='{ "jsonrpc": "2.0", "method": "draw_status", "params": [[{ "face": { "fg": "black", "bg": "yellow", "underline": "default", "attributes": [] }, "contents": '"$expected_subject_json"' }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "*git* 13:2 " }, { "face": { "fg": "black", "bg": "yellow", "underline": "default", "attributes": [] }, "contents": "[scratch]" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " - client0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "underline": "default", "attributes": [] }] }'
assert_eq "$actual_draw_status" "$expected_draw_status"
ui_out -ignore 2