unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
8271579fbb4fe1c13cdc9d0ef652ca33ae5ea72f blob 9224 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
 
#!/usr/bin/env bash
test_description='Configuration of mail-root and database path'
. $(dirname "$0")/test-lib.sh || exit 1

test_require_external_prereq xapian-metdata

backup_config () {
    local test_name=$(basename $0 .sh)
    cp ${NOTMUCH_CONFIG} notmuch-config-backup.${test_name}
}

restore_config () {
    local test_name=$(basename $0 .sh)
    export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
    unset CONFIG_PATH
    unset DATABASE_PATH
    unset NOTMUCH_PROFILE
    unset XAPIAN_PATH
    rm -f "$HOME/mail"
    cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
}

split_config () {
    local dir
    backup_config
    dir="$TMP_DIRECTORY/database.$test_count"
    rm -rf $dir
    mkdir $dir
    notmuch config set database.path $dir
    notmuch config set database.mail_root $MAIL_DIR
    DATABASE_PATH=$dir
    XAPIAN_PATH="$dir/xapian"
}

symlink_config () {
    local dir
    backup_config
    dir="$TMP_DIRECTORY/link.$test_count"
    ln -s $MAIL_DIR $dir
    notmuch config set database.path $dir
    notmuch config set database.mail_root $MAIL_DIR
    XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
    unset DATABASE_PATH
}


home_mail_config () {
    local dir
    backup_config
    dir="${HOME}/mail"
    ln -s $MAIL_DIR $dir
    notmuch config set database.path
    notmuch config set database.mail_root
    XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
    unset DATABASE_PATH
}

xdg_config () {
    local dir
    local profile=${1:-default}

    if [[ $profile != default ]]; then
	export NOTMUCH_PROFILE=$profile
    fi

    backup_config
    DATABASE_PATH="${HOME}/.local/share/notmuch/${profile}"
    rm -rf $DATABASE_PATH
    mkdir -p $DATABASE_PATH

    config_dir="${HOME}/.config/notmuch/${profile}"
    mkdir -p ${config_dir}
    CONFIG_PATH=$config_dir/config
    mv ${NOTMUCH_CONFIG} $CONFIG_PATH
    unset NOTMUCH_CONFIG

    XAPIAN_PATH="${DATABASE_PATH}/xapian"
    notmuch --config=${CONFIG_PATH} config set database.mail_root ${TMP_DIRECTORY}/mail
    notmuch --config=${CONFIG_PATH} config set database.path
}

for config in traditional split XDG XDG+profile symlink home_mail; do
    #start each set of tests with an known set of messages
    add_email_corpus

    case $config in
	traditional)
	    backup_config
	    XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
	    ;;
	split)
	    split_config
	    mv mail/.notmuch/xapian $DATABASE_PATH
	    ;;
	XDG)
	    xdg_config
	    mv mail/.notmuch/xapian $DATABASE_PATH
	    ;;
	XDG+profile)
	    xdg_config ${RANDOM}
	    mv mail/.notmuch/xapian $DATABASE_PATH
	    ;;
	symlink)
	    symlink_config
	    ;;
	home_mail)
	    home_mail_config
	    ;;
    esac

    test_begin_subtest "count ($config)"
    output=$(notmuch count '*')
    test_expect_equal "$output" '52'

    test_begin_subtest "count+tag ($config)"
    tag="tag${RANDOM}"
    notmuch tag +$tag '*'
    output=$(notmuch count tag:$tag)
    notmuch tag -$tag '*'
    test_expect_equal "$output" '52'

    test_begin_subtest "address ($config)"
    notmuch address --deduplicate=no --sort=newest-first --output=sender --output=recipients path:foo >OUTPUT
    cat <<EOF >EXPECTED
Carl Worth <cworth@cworth.org>
notmuch@notmuchmail.org
EOF
    test_expect_equal_file EXPECTED OUTPUT

    test_begin_subtest "dump ($config)"
    notmuch dump is:attachment and is:signed | sort > OUTPUT
    cat <<EOF > EXPECTED
#notmuch-dump batch-tag:3 config,properties,tags
+attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu
+attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu
EOF
    test_expect_equal_file EXPECTED OUTPUT

    test_begin_subtest "dump + tag + restore ($config)"
    notmuch dump '*' > EXPECTED
    notmuch tag -inbox '*'
    notmuch restore < EXPECTED
    notmuch dump > OUTPUT
    test_expect_equal_file_nonempty EXPECTED OUTPUT

    test_begin_subtest "reindex ($config)"
    notmuch search --output=messages '*' > EXPECTED
    notmuch reindex '*'
    notmuch search --output=messages '*' > OUTPUT
    test_expect_equal_file_nonempty EXPECTED OUTPUT

    test_begin_subtest "use existing database ($config)"
    output=$(notmuch new)
    test_expect_equal "$output" 'No new mail.'

    test_begin_subtest "create database ($config)"
    rm -rf $DATABASE_PATH/{.notmuch,}/xapian
    notmuch new
    output=$(notmuch count '*')
    test_expect_equal "$output" '52'

    test_begin_subtest "detect new files ($config)"
    generate_message
    generate_message
    notmuch new
    output=$(notmuch count '*')
    test_expect_equal "$output" '54'

    test_begin_subtest "Show a raw message ($config)"
    add_message
    notmuch show --format=raw id:$gen_msg_id > OUTPUT
    test_expect_equal_file_nonempty $gen_msg_filename OUTPUT
    rm -f $gen_msg_filename

    test_begin_subtest "reply ($config)"
    add_message '[from]="Sender <sender@example.com>"' \
		[to]=test_suite@notmuchmail.org \
		[subject]=notmuch-reply-test \
		'[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
		'[body]="basic reply test"'
    notmuch reply id:${gen_msg_id} 2>&1 > OUTPUT
    cat <<EOF > EXPECTED
From: Notmuch Test Suite <test_suite@notmuchmail.org>
Subject: Re: notmuch-reply-test
To: Sender <sender@example.com>
In-Reply-To: <${gen_msg_id}>
References: <${gen_msg_id}>

On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
> basic reply test
EOF
    test_expect_equal_file EXPECTED OUTPUT
    test_begin_subtest "insert+search ($config)"
    generate_message \
	"[subject]=\"insert-subject\"" \
	"[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
	"[body]=\"insert-message\""
    mkdir -p "$MAIL_DIR"/{cur,new,tmp}
    notmuch insert < "$gen_msg_filename"
    cur_msg_filename=$(notmuch search --output=files "subject:insert-subject")
    test_expect_equal_file_nonempty "$cur_msg_filename" "$gen_msg_filename"

    test_begin_subtest "compact+search ($config)"
    notmuch search --output=messages '*' | sort > EXPECTED
    notmuch compact
    notmuch search --output=messages '*' | sort > OUTPUT
    test_expect_equal_file_nonempty EXPECTED OUTPUT

    test_begin_subtest "upgrade backup ($config)"
    features=$(xapian-metadata get $XAPIAN_PATH features | grep -v "^relative directory paths")
    xapian-metadata set $XAPIAN_PATH features "$features"
    output=$(notmuch new | grep Welcome)
    test_expect_equal \
	"$output" \
	"Welcome to a new version of notmuch! Your database will now be upgraded."

    test_begin_subtest "notmuch +config -database suggests notmuch new ($config)"
    mv "$XAPIAN_PATH" "${XAPIAN_PATH}.bak"
    notmuch > OUTPUT
cat <<EOF > EXPECTED
Notmuch is configured, but no database was found.
You probably want to run "notmuch new" now to create a database.

Note that the first run of "notmuch new" can take a very long time
and that the resulting database will use roughly the same amount of
storage space as the email being indexed.

EOF
    mv "${XAPIAN_PATH}.bak" "$XAPIAN_PATH"

   test_expect_equal_file EXPECTED OUTPUT

   test_begin_subtest "Set config value ($config)"
   name=${RANDOM}
   value=${RANDOM}
   notmuch config set test${test_count}.${name} ${value}
   output=$(notmuch config get test${test_count}.${name})
   notmuch config set test${test_count}.${name}
   output2=$(notmuch config get test${test_count}.${name})
   test_expect_equal "${output}+${output2}" "${value}+"

   test_begin_subtest "Set config value in database ($config)"
   name=${RANDOM}
   value=${RANDOM}
   notmuch config set --database test${test_count}.${name} ${value}
   output=$(notmuch config get test${test_count}.${name})
   notmuch config set --database test${test_count}.${name}
   output2=$(notmuch config get test${test_count}.${name})
   test_expect_equal "${output}+${output2}" "${value}+"

   test_begin_subtest "Config list ($config)"
   notmuch config list | notmuch_dir_sanitize | sed -e "s/^database.backup_dir=.*$/database.backup_dir/"  \
						    -e "s/^database.hook_dir=.*$/database.hook_dir/" \
						    -e "s/^database.path=.*$/database.path/"  \
						    -e "s,^database.mail_root=CWD/home/mail,database.mail_root=MAIL_DIR," \
						    > OUTPUT
   cat <<EOF > EXPECTED
built_with.compact=true
built_with.field_processor=true
built_with.retry_lock=true
database.autocommit=8000
database.backup_dir
database.hook_dir
database.mail_root=MAIL_DIR
database.path
maildir.synchronize_flags=true
new.ignore=
new.tags=unread;inbox
search.exclude_tags=
user.name=Notmuch Test Suite
user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
user.primary_email=test_suite@notmuchmail.org
EOF
   test_expect_equal_file EXPECTED OUTPUT

   case $config in
       XDG*)
	   test_begin_subtest "Set shadowed config value in database ($config)"
	   name=${RANDOM}
	   value=${RANDOM}
	   key=test${test_count}.${name}
	   notmuch config set --database ${key}  ${value}
	   notmuch config set ${key} shadow${value}
	   output=$(notmuch --config='' config get ${key})
	   notmuch config set --database ${key}
	   output2=$(notmuch --config='' config get ${key})
	   notmuch config set ${key}
	   test_expect_equal "${output}+${output2}" "${value}+"
	   ;;
   esac
   restore_config
   rm -rf home/.local
   rm -rf home/.config
done

test_done
debug log:

solving 8271579f ...
found 8271579f in https://yhetil.org/notmuch/20210804104236.3986362-5-david@tethera.net/
found bb3bf665 in notmuch.git.git
preparing index
index prepared:
100755 bb3bf6657214642fb6b5b311d567c06e7a28af4e	test/T055-path-config.sh

applying [1/1] https://yhetil.org/notmuch/20210804104236.3986362-5-david@tethera.net/
diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh
index bb3bf665..8271579f 100755

Checking patch test/T055-path-config.sh...
Applied patch test/T055-path-config.sh cleanly.

index at:
100755 8271579fbb4fe1c13cdc9d0ef652ca33ae5ea72f	test/T055-path-config.sh

Code repositories for project(s) associated with this inbox:

	notmuch.git.git (no URL configured)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).