]> git.notmuchmail.org Git - notmuch/blob - test/T260-thread-order.sh
Import notmuch_0.27.orig.tar.gz
[notmuch] / test / T260-thread-order.sh
1 #!/usr/bin/env bash
2 test_description="threading when messages received out of order"
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 # Generate all single-root four message thread structures.  We'll use
6 # this for multiple tests below.
7 THREADS=$($NOTMUCH_PYTHON ${NOTMUCH_SRCDIR}/test/gen-threads.py 4)
8 nthreads=$(wc -l <<< "$THREADS")
9
10 test_begin_subtest "Messages with one parent get linked in all delivery orders"
11 # In the first variant, this delivers messages that reference only
12 # their immediate parent.  Hence, we should only expect threads to be
13 # fully joined at the end.
14 for ((n = 0; n < 4; n++)); do
15     # Deliver the n'th message of every thread
16     thread=0
17     while read -a parents; do
18         parent=${parents[$n]}
19         generate_message \
20             [id]=m$n@t$thread [in-reply-to]="\<m$parent@t$thread\>" \
21             [subject]=p$thread [from]=m$n
22         thread=$((thread + 1))
23     done <<< "$THREADS"
24     notmuch new > /dev/null
25 done
26 output=$(notmuch search --sort=newest-first '*' | notmuch_search_sanitize)
27 expected=$(for ((i = 0; i < $nthreads; i++)); do
28         echo "thread:XXX   2001-01-05 [4/4] m3, m2, m1, m0; p$i (inbox unread)"
29     done)
30 test_expect_equal "$output" "$expected"
31
32 test_begin_subtest "Messages with all parents get linked in all delivery orders"
33 # Here we do the same thing as the previous test, but each message
34 # references all of its parents.  Since every message references the
35 # root of the thread, each thread should always be fully joined.  This
36 # is currently broken because of the bug detailed in
37 # id:8738h7kv2q.fsf@qmul.ac.uk.
38 rm ${MAIL_DIR}/*
39 notmuch new > /dev/null
40 output=""
41 expected=""
42 for ((n = 0; n < 4; n++)); do
43     # Deliver the n'th message of every thread
44     thread=0
45     while read -a parents; do
46         references=""
47         parent=${parents[$n]}
48         while [[ ${parent:-None} != None ]]; do
49             references="<m$parent@t$thread> $references"
50             pp=$parent
51             parent=${parents[$parent]}
52             # Avoid looping over broken input (if ever)
53             parents[$pp]="None"
54         done
55
56         generate_message \
57             [id]=m$n@t$thread [references]="'$references'" \
58             [subject]=p$thread [from]=m$n
59         thread=$((thread + 1))
60     done <<< "$THREADS"
61     notmuch new > /dev/null
62
63     output="$output
64 $(notmuch search --sort=newest-first '*' | notmuch_search_sanitize)"
65
66     # Construct expected output
67     template="thread:XXX   2001-01-05 [$((n+1))/$((n+1))]"
68     for ((m = n; m > 0; m--)); do
69         template="$template m$m,"
70     done
71     expected="$expected
72 $(for ((i = 0; i < $nthreads; i++)); do
73         echo "$template m0; p$i (inbox unread)"
74     done)"
75 done
76 test_expect_equal "$output" "$expected"
77
78 test_done