]> git.notmuchmail.org Git - notmuch/blob - test/T020-compact.sh
test: require test_begin_subtest before test_expect_success
[notmuch] / test / T020-compact.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch compact"'
3 . ./test-lib.sh || exit 1
4
5 add_message '[subject]=One'
6 add_message '[subject]=Two'
7 add_message '[subject]=Three'
8
9 notmuch tag +tag1 \*
10 notmuch tag +tag2 subject:Two
11 notmuch tag -tag1 +tag3 subject:Three
12
13 if [ $NOTMUCH_HAVE_XAPIAN_COMPACT -eq 0 ]; then
14     test_begin_subtest "Compact unsupported: error message"
15     output=$(notmuch compact --quiet 2>&1)
16     test_expect_equal "$output" "notmuch was compiled against a xapian version lacking compaction support.
17 Compaction failed: Unsupported operation"
18
19     test_expect_code 1 "Compact unsupported: status code" "notmuch compact"
20
21     test_done
22 fi
23
24 test_begin_subtest "Running compact"
25 test_expect_success "notmuch compact --backup=${TEST_DIRECTORY}/xapian.old"
26
27 test_begin_subtest "Compact preserves database"
28 output=$(notmuch search \* | notmuch_search_sanitize)
29 test_expect_equal "$output" "\
30 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag1 unread)
31 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag2 unread)
32 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Three (inbox tag3 unread)"
33
34 test_begin_subtest "Restoring Backup"
35 test_expect_success 'rm -Rf ${MAIL_DIR}/.notmuch/xapian &&
36      mv ${TEST_DIRECTORY}/xapian.old ${MAIL_DIR}/.notmuch/xapian'
37
38 test_begin_subtest "Checking restored backup"
39 output=$(notmuch search \* | notmuch_search_sanitize)
40 test_expect_equal "$output" "\
41 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag1 unread)
42 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag2 unread)
43 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Three (inbox tag3 unread)"
44
45 test_done