aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-03-30 15:46:47 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-03-30 15:46:47 +0200
commit2c1ecbe4a678963e6b1619e1703748ec116a8fcd (patch)
tree0d6fc42fc00b95f052f450b69e65afc6492b63f7
parentd73a3a748aaaf1a6da2b35815b909571bc38d290 (diff)
downloadmblaze-2c1ecbe4a678963e6b1619e1703748ec116a8fcd.tar.gz
t: beginnings of a test suite
-rw-r--r--Makefile3
-rwxr-xr-xt/1000-mmime.t17
-rwxr-xr-xt/2000-mpick.t68
-rw-r--r--t/lib.sh24
4 files changed, 112 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 1ab619f..9522d9b 100644
--- a/Makefile
+++ b/Makefile
@@ -34,6 +34,9 @@ README: man/mblaze.7
clean: FRC
-rm -f $(ALL) *.o
+check: FRC all
+ PATH=$$(pwd):$$PATH prove -v
+
install: FRC all
mkdir -p $(DESTDIR)$(BINDIR) \
$(DESTDIR)$(MANDIR)/man1 \
diff --git a/t/1000-mmime.t b/t/1000-mmime.t
new file mode 100755
index 0000000..a8be968
--- /dev/null
+++ b/t/1000-mmime.t
@@ -0,0 +1,17 @@
+#!/bin/sh -e
+cd ${0%/*}
+. ./lib.sh
+plan 4
+
+cat <<EOF >tmp
+References: <aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@a> <bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb@b> <ccccccccccccccccccccccccccccccc@c>
+
+Body
+EOF
+
+# https://github.com/chneukirchen/mblaze/issues/20
+
+check 'mime -r runs' 'mmime -r <tmp >tmp2'
+check 'no overlong lines' '[ $(wc -L <tmp2) -lt 80 ]'
+check 'no QP when unecessary' ! grep -qF "=?" tmp2
+check 'no further mime necessary' 'mmime -c <tmp2'
diff --git a/t/2000-mpick.t b/t/2000-mpick.t
new file mode 100755
index 0000000..ec5aaec
--- /dev/null
+++ b/t/2000-mpick.t
@@ -0,0 +1,68 @@
+#!/bin/sh -e
+cd ${0%/*}
+. ./lib.sh
+plan 11
+
+rm -rf test.dir
+mkdir test.dir
+(
+cd test.dir
+
+mkdir -p inbox/cur
+touch "inbox/cur/1:2,S"
+touch "inbox/cur/2:2,ST"
+touch "inbox/cur/3:2,SRT"
+touch "inbox/cur/4:2,SRFT"
+touch "inbox/cur/5:2,T"
+touch "inbox/cur/6:2,SRF"
+touch "inbox/cur/7:2,SR"
+touch "inbox/cur/8:2,SF"
+touch "inbox/cur/9:2,"
+
+check_same 'flag trashed' 'mlist inbox | mpick :T' 'mlist -T inbox'
+check_same 'flag not trashed' 'mlist inbox | mpick -t "!trashed"' 'mlist -t inbox'
+check_same 'flag seen' 'mlist inbox | mpick :S' 'mlist -S inbox'
+check_same 'flag not seen' 'mlist inbox | mpick -t !seen' 'mlist -s inbox'
+check_same 'flag seen and trashed' 'mlist inbox | mpick :S :T' 'mlist -ST inbox'
+check_same 'flag seen and not trashed' 'mlist inbox | mpick -t "seen && !trashed"' 'mlist -St inbox'
+# check_same 'flag replied' 'mlist inbox | mpick :R' 'mlist -R inbox'
+check_same 'flag forwarded' 'mlist inbox | mpick :F' 'mlist -F inbox'
+
+
+cat <<! | mmime >"inbox/cur/1:2,S"
+From: Peter Example <peter@example.org>
+Subject: Hey whats up?
+Date: Thu, 30 Mar 2017 15:41:17 +0200
+Message-Id: <EOH1EP40II.28EN1IMPMSUVS@example.org>
+
+Greetings
+!
+
+cat <<! | mmime >"inbox/cur/9:2,"
+From: Peter Example <peter@example.org>
+Subject: wow nice subject
+Date: Thu, 30 Mar 2017 15:42:00 +0200
+Message-Id: <EOH1EWLI6M.3AIXSIEV1VFBQ@example.org>
+
+shit happens
+!
+
+cat <<! | mmime >"inbox/cur/5:2,T"
+From: Obvious spam <script@kiddy.com>
+Subject: look at this awesome pdf
+Date: Thu, 30 Mar 2017 15:42:05 +0200
+Message-Id: <EOH1F3NUOY.2KBVMHSBFATNY@example.org>
+
+Check my resume!
+
+Greetings
+
+#application/pdf ../../mshow
+!
+
+check 'search subject' 'mlist inbox | mpick /wow | grep -q inbox/cur/9:2,'
+check 'search addr' 'mlist inbox | mpick peter@example.org | wc -l | grep -qx 2'
+check 'search name' 'mlist inbox | mpick "Peter Example" | wc -l | grep -qx 2'
+check 'search spam' 'mlist inbox | mpick -t "trashed && subject =~ \"pdf\"" | wc -l | grep -qx 1'
+
+)
diff --git a/t/lib.sh b/t/lib.sh
new file mode 100644
index 0000000..81c2dd1
--- /dev/null
+++ b/t/lib.sh
@@ -0,0 +1,24 @@
+plan() {
+ printf '1..%d\n' "$1"
+}
+
+check() {
+ msg=$1
+ shift
+ if eval "$@" 2>/dev/null 1>&2; then
+ printf 'ok - %s\n' "$msg"
+ else
+ printf 'not ok - %s\n' "$msg"
+ false
+ fi
+ true
+}
+
+check_same() {
+ msg=$1
+ shift
+ eval "$1" 2>/dev/null 1>&2 >out1 || true
+ eval "$2" 2>/dev/null 1>&2 >out2 || true
+ diff -u out1 out2 || true
+ check "$msg" cmp out1 out2
+}