]> git.notmuchmail.org Git - notmuch/blob - test/T260-thread-order.sh
Merge tag 'debian/0.18.1-2'
[notmuch] / test / T260-thread-order.sh
1 #!/usr/bin/env bash
2 test_description="threading when messages received out of order"
3 . ./test-lib.sh
4
5 # Generate all single-root four message thread structures.  We'll use
6 # this for multiple tests below.
7 THREADS=$(python ${TEST_DIRECTORY}/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 test_subtest_known_broken
34 # Here we do the same thing as the previous test, but each message
35 # references all of its parents.  Since every message references the
36 # root of the thread, each thread should always be fully joined.  This
37 # is currently broken because of the bug detailed in
38 # id:8738h7kv2q.fsf@qmul.ac.uk.
39 rm ${MAIL_DIR}/*
40 notmuch new > /dev/null
41 output=""
42 expected=""
43 for ((n = 0; n < 4; n++)); do
44     # Deliver the n'th message of every thread
45     thread=0
46     while read -a parents; do
47         references=""
48         parent=${parents[$n]}
49         while [[ $parent != None ]]; do
50             references="<m$parent@t$thread> $references"
51             parent=${parents[$parent]}
52         done
53
54         generate_message \
55             [id]=m$n@t$thread [references]="'$references'" \
56             [subject]=p$thread [from]=m$n
57         thread=$((thread + 1))
58     done <<< "$THREADS"
59     notmuch new > /dev/null
60
61     output="$output
62 $(notmuch search --sort=newest-first '*' | notmuch_search_sanitize)"
63
64     # Construct expected output
65     template="thread:XXX   2001-01-05 [$((n+1))/$((n+1))]"
66     for ((m = n; m > 0; m--)); do
67         template="$template m$m,"
68     done
69     expected="$expected
70 $(for ((i = 0; i < $nthreads; i++)); do
71         echo "$template m0; p$i (inbox unread)"
72     done)"
73 done
74 test_expect_equal "$output" "$expected"
75
76 test_done