]> git.notmuchmail.org Git - notmuch/blob - test/dump-restore
notmuch-restore: implement --accumulate option
[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 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 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 'Restore with nothing to do, II' \
43   'notmuch restore --accumulate dump.expected &&
44   notmuch dump > dump.actual &&
45   test_cmp dump.expected dump.actual'
46
47 test_expect_success 'Restore with nothing to do, III' \
48   'notmuch restore --accumulate < clear.expected &&
49   notmuch dump > dump.actual &&
50   test_cmp dump.expected dump.actual'
51
52 # notmuch restore currently only considers the first argument.
53 test_subtest_known_broken
54 test_expect_success 'Invalid restore invocation' \
55   'test_must_fail notmuch restore dump.expected another_one'
56
57 test_begin_subtest "dump outfile"
58 notmuch dump dump-outfile.actual
59 test_expect_equal_file dump.expected dump-outfile.actual
60
61 test_begin_subtest "dump outfile # deprecated"
62 test_expect_equal "Warning: the output file argument of dump is deprecated."\
63   "$(notmuch dump /dev/null 2>&1)"
64
65 test_begin_subtest "dump outfile --"
66 notmuch dump dump-1-arg-dash.actual --
67 test_expect_equal_file dump.expected dump-1-arg-dash.actual
68
69 # Note, we assume all messages from cworth have a message-id
70 # containing cworth.org
71
72 grep 'cworth[.]org' dump.expected > dump-cworth.expected
73
74 test_begin_subtest "dump -- from:cworth"
75 notmuch dump -- from:cworth > dump-dash-cworth.actual
76 test_expect_equal_file dump-cworth.expected dump-dash-cworth.actual
77
78 test_begin_subtest "dump outfile from:cworth"
79 notmuch dump dump-outfile-cworth.actual from:cworth
80 test_expect_equal_file dump-cworth.expected dump-outfile-cworth.actual
81
82 test_begin_subtest "dump outfile -- from:cworth"
83 notmuch dump dump-outfile-dash-inbox.actual -- from:cworth
84 test_expect_equal_file dump-cworth.expected dump-outfile-dash-inbox.actual
85
86 test_done