~maxgyver83/emailbook-hare

40a61388882aa30022c32ac5f1f87c70487d0c55 — Max Schillinger 6 months ago 2eec656
Add system tests
A run-tests.sh => run-tests.sh +9 -0
@@ 0,0 1,9 @@
#!/bin/sh
projectdir="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
source "$projectdir/test/utils.sh"

for file in "$projectdir/test/"*.sh; do
    test -x "$file" || continue # skip utils.sh
    printf "\n${bold}test/$(basename $file)${reset}\n"
    sh "$file"
done

A test/add.sh => test/add.sh +15 -0
@@ 0,0 1,15 @@
#!/bin/sh
projectdir="$(cd -P -- "$(dirname -- "$(dirname -- "$0")")" && pwd -P)"
source "$projectdir/test/utils.sh"

template="$projectdir/test/book-expected.txt"
book="/tmp/book-add.txt"
cp "$template" "$book"
# add Juan
"$projectdir/emailbook-hare" "$book" --add 'Juan Pérez <juan@example.org>'
# skip "John Doe" because it's the same as John Doe (first entry)
"$projectdir/emailbook-hare" "$book" --add '"John Doe" <john.doe@example.com>'

grep -q Juan $book && ! grep -q '"John Doe"' $book \
    && success \
    || failure && exit 1

A test/book-expected.txt => test/book-expected.txt +8 -0
@@ 0,0 1,8 @@
John Doe <john.doe@example.com>
Erika Mustermann <e.mustermann@example.com>
<max.m@example.com>
<mario.r@example.com>
张三 <zhang.san@example.com>
Maria Rossi <maria.r@example.com>
Max Müller <max.m@example.com>
<zhang.san@example.com>

A test/parse.sh => test/parse.sh +13 -0
@@ 0,0 1,13 @@
#!/bin/sh
projectdir="$(cd -P -- "$(dirname -- "$(dirname -- "$0")")" && pwd -P)"
source "$projectdir/test/utils.sh"

book=/tmp/book.txt
rm $book 2> /dev/null
cat "$projectdir/test/sample1" \
    | "$projectdir/emailbook-hare" "$book" --parse --all
cat "$projectdir/test/sample2" \
    | "$projectdir/emailbook-hare" "$book" --parse --all
diff -s "$book" "$projectdir/test/book-expected.txt" \
    && success \
    || failure && exit 1

A test/query-expected.txt => test/query-expected.txt +2 -0
@@ 0,0 1,2 @@
<mario.r@example.com>
Maria Rossi <maria.r@example.com>

A test/query.sh => test/query.sh +9 -0
@@ 0,0 1,9 @@
#!/bin/sh
projectdir="$(cd -P -- "$(dirname -- "$(dirname -- "$0")")" && pwd -P)"
source "$projectdir/test/utils.sh"

book="$projectdir/test/book-expected.txt"
"$projectdir/emailbook-hare" "$book" --search 'mari' > /tmp/emailbook-query
diff -s /tmp/emailbook-query "$projectdir/test/query-expected.txt" \
    && success \
    || failure && exit 1

A test/sample1 => test/sample1 +10 -0
@@ 0,0 1,10 @@
Subject: Test e-mail 1
From: John Doe <john.doe@example.com>
To: Erika Mustermann
 <e.mustermann@example.com>,
 <max.m@example.com>,
 mario.r@example.com
Cc: =?UTF-8?B?5byg5LiJ?= <zhang.san@example.com>,
 Maria Rossi <maria.r@example.com>

Content

A test/sample2 => test/sample2 +8 -0
@@ 0,0 1,8 @@
Subject: Test e-mail 2
From: John Doe <john.doe@example.com>
To: "Erika Mustermann"<e.mustermann@example.com>,
 =?ISO-8859-1?Q?Max M=FCller?= <max.m@example.com>,
 <mario.r@example.com>
Cc: zhang.san@example.com, Maria Rossi <maria.r@example.com>

Content

A test/utils.sh => test/utils.sh +8 -0
@@ 0,0 1,8 @@
#!/bin/sh
bold="\033[1m"
red="\033[31m"
green="\033[32m"
reset="\033[0m"

success() { printf "\n${green}TEST SUCCESSFUL${reset}\n"; }
failure() { printf "\n${red}TEST FAILED${reset}\n"; }