#!/usr/bin/env bash
test_description='various settings for "notmuch search --output="'
-. ./test-lib.sh || exit 1
+. $(dirname "$0")/test-lib.sh || exit 1
add_email_corpus
thread:THREADID
thread:THREADID
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=threads --format=json"
notmuch search --format=json --output=threads '*' | sed -e s/\".*\"/\"THREADID\"/ >OUTPUT
id:1258471718-6781-2-git-send-email-dottedmag@dottedmag.net
id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=messages --duplicate=1"
notmuch search --output=messages --duplicate=1 '*' >OUTPUT
# reuse same EXPECTED as above
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=messages --duplicate=2"
notmuch search --output=messages --duplicate=2 '*' >OUTPUT
cat <<EOF >EXPECTED
id:20091117232137.GA7669@griffis1.net
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=messages --duplicate=3"
notmuch search --output=messages --duplicate=3 '*' >OUTPUT
cat <<EOF >EXPECTED
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=messages --format=json"
notmuch search --format=json --output=messages '*' >OUTPUT
"1258471718-6781-2-git-send-email-dottedmag@dottedmag.net",
"1258471718-6781-1-git-send-email-dottedmag@dottedmag.net"]
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=messages --format=json --duplicate=1"
notmuch search --output=messages --format=json --duplicate=1 '*' >OUTPUT
# reuse same EXPECTED as above
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=messages --format=json --duplicate=2"
notmuch search --output=messages --format=json --duplicate=2 '*' >OUTPUT
cat <<EOF >EXPECTED
["20091117232137.GA7669@griffis1.net"]
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=messages --format=json --duplicate=3"
notmuch search --output=messages --format=json --duplicate=3 '*' >OUTPUT
cat <<EOF >EXPECTED
[]
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=files"
notmuch search --output=files '*' | notmuch_search_files_sanitize | sort >OUTPUT
MAIL_DIR/foo/new/10:2,
MAIL_DIR/new/04:2,
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
dup1=$(notmuch search --output=files id:20091117232137.GA7669@griffis1.net | head -n 1 | sed -e "s,$MAIL_DIR,MAIL_DIR,")
dup2=$(notmuch search --output=files id:20091117232137.GA7669@griffis1.net | tail -n 1 | sed -e "s,$MAIL_DIR,MAIL_DIR,")
MAIL_DIR/02:2,
MAIL_DIR/01:2,
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=files --format=json"
notmuch search --format=json --output=files '*' | notmuch_search_files_sanitize \
"MAIL_DIR/02:2,",
"MAIL_DIR/01:2,"]
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=files --format=json --duplicate=2"
notmuch search --format=json --output=files --duplicate=2 '*' | notmuch_search_files_sanitize >OUTPUT
cat <<EOF >EXPECTED
["$dup2"]
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=tags"
notmuch search --output=tags '*' >OUTPUT
signed
unread
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "--output=tags --format=json"
notmuch search --format=json --output=tags '*' >OUTPUT
"signed",
"unread"]
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "sanitize output for quoted-printable line-breaks in author and subject"
add_message "[subject]='two =?ISO-8859-1?Q?line=0A_subject?=
cat <<EOF >EXPECTED
thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; two line subject headers (inbox unread)
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "search for non-existent message prints nothing"
notmuch search "no-message-matches-this" > OUTPUT
echo -n >EXPECTED
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "search --format=json for non-existent message prints proper empty json"
notmuch search --format=json "no-message-matches-this" > OUTPUT
echo "[]" >EXPECTED
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
test_done