3 # Quick-n-dirty script to ease running the IMAP tests in various configurations.
4 # Also generates coverage reports (requires Rust nightly).
5 # TODO redo in more standard fashion under `make check`.
8 # export MH_TEST_IMAP_LOG_LEVEL=trace
9 # export MH_TEST_NOCLEANUP=1
10 # export MH_TEST_STUNNEL_DEBUG=7
11 # export MH_TEST_STUNNEL_OUTPUT=/dev/stderr
12 # export MH_TEST_VERBOSE=1
13 # export RUST_BACKTRACE=1
14 # abs_srcdir=$HOME/work/nmh
15 # abs_builddir=$abs_srcdir/.o/clang13
16 # LLVM_PROFDATA=llvm-profdata13
20 # PANDA_IMAPD=/usr/local/libexec/imapd
22 # gandi_user='example@example.com'
24 #gmail_user='example@example.com'
25 #gmail_oauth=/path/to/oauth-gmail
32 if ! [[ -n $cf ]]; then
33 print
-u2 "usage imaptest CONFIGURATION ACTION"
47 if ! eval "[[ -n \$$v ]]"; then
48 print
-u2 "$v must be set in $cf"
53 testdir
=$abs_builddir/test
/testdir
55 export CARGO_TARGET_DIR
=$abs_builddir/target
57 # Coverage documentation
58 # https://doc.rust-lang.org/beta/unstable-book/compiler-flags/source-based-code-coverage.html
59 # https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
60 # https://llvm.org/docs/CommandGuide/llvm-profdata.html
61 # https://llvm.org/docs/CommandGuide/llvm-cov.html
63 # https://github.com/rust-lang/rust/issues/79121 Tracking Issue for LLVM InstrProf code coverage
64 # https://github.com/rust-lang/rust/issues/85902 Add a cargo option to generate coverage reports using -Z instrument-coverage
65 # https://github.com/rust-lang/rust/issues/79649 Add support for branch coverage in source-based coverage
68 typeset profile_dir
=$2
69 typeset profdata
=$abs_builddir/covdata
/$profile.profdata
70 find $abs_builddir/covdata
/$profile_dir -name '*.profraw' | $nop xargs $LLVM_PROFDATA merge
--sparse \
72 $nop $LLVM_COV show
-Xdemangler=$HOME/.cargo
/bin
/rustfilt
'--ignore-filename-regex=/tests/' '--ignore-filename-regex=/tests\.rs' '--ignore-filename-regex=\.cargo' --format=html \
73 -o $abs_builddir/covdata
/html
/$profile --instr-profile=$profdata \
74 ${=${(j: --object :)test_objects}}
78 setopt LOCAL_OPTIONS NULL_GLOB
79 typeset litter
=($testdir/*.actual
)
80 (( $#litter > 0 )) || return 0
81 print
-u2 "$1 littered $litter"
87 typeset
-a actions profiles
88 while [[ $# -gt 0 ]]; do
98 if [[ $word = -cover-report ]]; then
101 $nop rm -rf $abs_builddir/covdata
104 export RUSTFLAGS
="-Zinstrument-coverage $RUSTFLAGS"
108 # We test implicit TLS with Gmail and explicit with Gandi; any reason to test both ways both places?
109 set -- cargot
test live
/panda live
/dovecot live
/cyrus live
/gandi-starttls live
/gmail
"$@"
127 print
-u2 "get outta here $word"
133 if ! $report_only; then
134 for action
in $actions; do
137 (cd $abs_builddir && $nop $MAKE $MAKE_JOBS all cargo
)
141 $nop env LLVM_PROFILE_FILE
="$abs_builddir/covdata/cargot/%m-%p.profraw" cargo t
-- --test-threads=1
146 test
/imap
/test-astring
148 test
/imap
/test-bad-fetch-body
149 test
/imap
/test-folder-create-disallowed
150 # Downloads all mail from your test account; better be sure you want that!
151 # test/imap/test-gmail-all
153 test
/imap
/test-inc-missing-msg
154 test
/imap
/test-inc-missing-msg-case-2
155 # Handled specially below.
156 # test/imap/test-live
159 test
/imap
/test-quirks-gmail
160 # TODO fix the bitrot
161 # test/imap/test-refile
164 test
/imap
/test-server-drops
165 test
/imap
/test-uidvalidity
166 test
/imap
/test-xoauth
168 (cd $abs_builddir && for test in $tests; do
169 $nop env PANDA_IMAPD
=$PANDA_IMAPD MH_COVERAGE_PROFILE
=test $MAKE check TESTS
=$test
175 (cd $abs_builddir && $nop env PANDA_IMAPD
=$PANDA_IMAPD MH_COVERAGE_PROFILE
=test $MAKE check TESTS
=$action)
180 (cd $abs_builddir && $nop env PANDA_IMAPD
=$PANDA_IMAPD MH_COVERAGE_PROFILE
=live
/panda MH_IMAP_TEST_SERVER
=panda \
181 $MAKE check TESTS
=test
/imap
/test-live
)
186 (cd $abs_builddir && $nop env MH_COVERAGE_PROFILE
=live
/dovecot MH_IMAP_TEST_SERVER
=127.0.0.1 MH_IMAP_TEST_PORT
=1043 \
187 MH_IMAP_TEST_USER
=test MH_IMAP_TEST_PASSWORD
=testpw MH_IMAP_TEST_EMAIL_ADDRESS
=test MH_IMAP_TEST_TLS
=no \
188 MH_IMAP_SERVER_DRAFT_BORN_UNSEEN
=' ' MH_IMAP_SERVER_EATS_TRAILING_EOL
=' ' \
189 $MAKE check TESTS
=test
/imap
/test-live
)
194 (cd $abs_builddir && $nop env MH_COVERAGE_PROFILE
=live
/cyrus MH_IMAP_TEST_SERVER
=127.0.0.1 MH_IMAP_TEST_PORT
=143 MH_IMAP_TEST_USER
=test \
195 MH_IMAP_TEST_PASSWORD
=test MH_IMAP_TEST_EMAIL_ADDRESS
=test MH_IMAP_TEST_TLS
=no MH_IMAP_TEST_MAILBOX_ROOT
=test
/ \
196 MH_IMAP_SERVER_DRAFT_BORN_UNSEEN
='U' \
197 $MAKE check TESTS
=test
/imap
/test-live
)
201 # Looks like Gandi use Dovecot
203 (cd $abs_builddir && $nop env MH_COVERAGE_PROFILE
=live
/gandi MH_IMAP_TEST_SERVER
=mail.gandi.net MH_IMAP_TEST_PORT
=imaps \
204 MH_IMAP_TEST_USER
=$gandi_user MH_IMAP_TEST_PASSWORD
=$gandi_pw MH_IMAP_TEST_EMAIL_ADDRESS
=$gandi_user \
205 MH_IMAP_TEST_TLS
=implicit MH_IMAP_TEST_MAILBOX_ROOT
=test
/ \
206 MH_IMAP_SERVER_DRAFT_BORN_UNSEEN
=' ' \
207 $MAKE check TESTS
=test
/imap
/test-live
)
212 (cd $abs_builddir && $nop env MH_COVERAGE_PROFILE
=live
/gandi-starttls MH_IMAP_TEST_SERVER
=mail.gandi.net MH_IMAP_TEST_PORT
=imap \
213 MH_IMAP_TEST_USER
=$gandi_user MH_IMAP_TEST_PASSWORD
=$gandi_pw MH_IMAP_TEST_EMAIL_ADDRESS
=$gandi_user \
214 MH_IMAP_TEST_TLS
=explicit MH_IMAP_TEST_MAILBOX_ROOT
=test
/ \
215 MH_IMAP_SERVER_DRAFT_BORN_UNSEEN
=' ' \
216 $MAKE check TESTS
=test
/imap
/test-live
)
221 (cd $abs_builddir && $nop env MH_COVERAGE_PROFILE
=live
/gmail MH_IMAP_TEST_SERVER
=gmail MH_IMAP_TEST_PORT
=imaps MH_IMAP_TEST_USER
=$gmail_user \
222 MH_IMAP_TEST_OAUTH_FILE
=$gmail_oauth MH_IMAP_TEST_EMAIL_ADDRESS
=$gmail_user MH_IMAP_TEST_MAILBOX_ROOT
=test
/ \
223 MH_IMAP_SERVER_DRAFT_BORN_UNSEEN
='U' \
224 $MAKE check TESTS
=test
/imap
/test-live
)
232 $nop rm -rf $abs_builddir/target
241 $abs_builddir/target
/debug
/imap-folder-manager
242 $
($nop env LLVM_PROFILE_FILE
="$abs_builddir/covdata/cargot/%m-%p.profraw" cargo t
--tests --no-run --message-format=json
2>/dev
/null \
243 | $nop perl
-MJSON::PP
-lne 'eval { $item = decode_json($_) }; if ($@) { @all=(); die($@) } $fns = $item->{profile}->{test} && $item->{filenames}; $fns && push(@all, @$fns); END { print join("\n", @all) }')
245 print
-l $test_objects
248 (( ${profiles[(i)live/*]} <= ${#profiles} )) && report-coverage live live
249 for profile
in $profiles; do
250 report-coverage
$profile $profile
252 $nop chmod -R a
+rX
$abs_builddir/covdata
/html