]> git.notmuchmail.org Git - notmuch/blob - test/dump-restore
test: update dump-restore roundtripping test for batch-tag format
[notmuch] / test / dump-restore
1 #!/usr/bin/env bash
2 test_description="\"notmuch dump\" and \"notmuch restore\""
3 . ./test-lib.sh
4
5 add_email_corpus
6
7 test_expect_success 'Dumping all tags' \
8   'generate_message &&
9   notmuch new &&
10   notmuch dump > dump.expected'
11
12 # The use of from:cworth is rather arbitrary: it matches some of the
13 # email corpus' messages, but not all of them.
14
15 test_expect_success 'Dumping all tags II' \
16   'notmuch tag +ABC +DEF -- from:cworth &&
17   notmuch dump > dump-ABC_DEF.expected &&
18   ! cmp dump.expected dump-ABC_DEF.expected'
19
20 test_expect_success 'Clearing all tags' \
21   'sed -e "s/(\([^(]*\))$/()/" < dump.expected > clear.expected &&
22   notmuch restore --input=clear.expected &&
23   notmuch dump > clear.actual &&
24   test_cmp clear.expected clear.actual'
25
26 test_expect_success 'Accumulate original tags' \
27   'notmuch tag +ABC +DEF -- from:cworth &&
28   notmuch restore --accumulate < dump.expected &&
29   notmuch dump > dump.actual &&
30   test_cmp dump-ABC_DEF.expected dump.actual'
31
32 test_expect_success 'Restoring original tags' \
33   'notmuch restore --input=dump.expected &&
34   notmuch dump > dump.actual &&
35   test_cmp dump.expected dump.actual'
36
37 test_expect_success 'Restore with nothing to do' \
38   'notmuch restore < dump.expected &&
39   notmuch dump > dump.actual &&
40   test_cmp dump.expected dump.actual'
41
42 test_expect_success 'Accumulate with existing tags' \
43   'notmuch restore --accumulate --input=dump.expected &&
44   notmuch dump > dump.actual &&
45   test_cmp dump.expected dump.actual'
46
47 test_expect_success 'Accumulate with no tags' \
48   'notmuch restore --accumulate < clear.expected &&
49   notmuch dump > dump.actual &&
50   test_cmp dump.expected dump.actual'
51
52 test_expect_success 'Accumulate with new tags' \
53   'notmuch restore --input=dump.expected &&
54   notmuch restore --accumulate --input=dump-ABC_DEF.expected &&
55   notmuch dump >  OUTPUT.$test_count &&
56   notmuch restore --input=dump.expected &&
57   test_cmp dump-ABC_DEF.expected OUTPUT.$test_count'
58
59 # notmuch restore currently only considers the first argument.
60 test_expect_success 'Invalid restore invocation' \
61   'test_must_fail notmuch restore --input=dump.expected another_one'
62
63 test_begin_subtest "dump --output=outfile"
64 notmuch dump --output=dump-outfile.actual
65 test_expect_equal_file dump.expected dump-outfile.actual
66
67 test_begin_subtest "dump --output=outfile --"
68 notmuch dump --output=dump-1-arg-dash.actual --
69 test_expect_equal_file dump.expected dump-1-arg-dash.actual
70
71 # Note, we assume all messages from cworth have a message-id
72 # containing cworth.org
73
74 grep 'cworth[.]org' dump.expected > dump-cworth.expected
75
76 test_begin_subtest "dump -- from:cworth"
77 notmuch dump -- from:cworth > dump-dash-cworth.actual
78 test_expect_equal_file dump-cworth.expected dump-dash-cworth.actual
79
80 test_begin_subtest "dump --output=outfile from:cworth"
81 notmuch dump --output=dump-outfile-cworth.actual from:cworth
82 test_expect_equal_file dump-cworth.expected dump-outfile-cworth.actual
83
84 test_begin_subtest "dump --output=outfile -- from:cworth"
85 notmuch dump --output=dump-outfile-dash-inbox.actual -- from:cworth
86 test_expect_equal_file dump-cworth.expected dump-outfile-dash-inbox.actual
87
88 test_begin_subtest "Check for a safe set of message-ids"
89 notmuch search --output=messages from:cworth | sed s/^id:// > EXPECTED
90 notmuch search --output=messages from:cworth | sed s/^id:// |\
91         $TEST_DIRECTORY/hex-xcode --direction=encode > OUTPUT
92 test_expect_equal_file OUTPUT EXPECTED
93
94 test_begin_subtest "format=batch-tag, dump sanity check."
95 notmuch dump --format=sup from:cworth | cut -f1 -d' ' | \
96     sort > EXPECTED.$test_count
97 notmuch dump --format=batch-tag from:cworth | sed 's/^.*-- id://' | \
98     sort > OUTPUT.$test_count
99 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
100
101 test_begin_subtest 'roundtripping random message-ids and tags'
102
103     ${TEST_DIRECTORY}/random-corpus --config-path=${NOTMUCH_CONFIG} \
104                         --num-messages=100
105
106      notmuch dump --format=batch-tag| \
107          sort > EXPECTED.$test_count
108
109      notmuch tag +this_tag_is_very_unlikely_to_be_random '*'
110
111      notmuch restore --format=batch-tag < EXPECTED.$test_count
112
113      notmuch dump --format=batch-tag| \
114          sort > OUTPUT.$test_count
115
116 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
117
118 test_done
119
120 # Note the database is "poisoned" for sup format at this point.