From ed4002ab3b709667e76471bbaa8eb62689d9df70 Mon Sep 17 00:00:00 2001 From: vv01f Date: Sat, 16 Nov 2019 22:25:41 +0100 Subject: [PATCH] impl. tests --- dhl.sh | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/dhl.sh b/dhl.sh index bed8bc0..7f272a3 100755 --- a/dhl.sh +++ b/dhl.sh @@ -38,17 +38,41 @@ iso3countrycode () { fi } +testcmp () { + if test "$#" -eq 0 ; then + echo "arguments missing."; exit 1 + fi + case $2 in + #whitelisted fn + iso3countrycode) + expected="$1" + shift + fn="$1" + shift + for a in "$@"; do + result=$("$fn" "$a") + if test "$result" = "$expected" ; then + echo "$fn passed for: $a." + else + echo "$fn failed for: $a." + fi + done + ;; + *) + echo "no test performed" + esac +} + testiso3 () { # covering data in https://doku.ccc.de/index.php?title=Attribut:Chaostreff-Country&limit=500&offset=0 - iso3countrycode "Belgien" - iso3countrycode "Deutschland" - iso3countrycode "England" - iso3countrycode "Luxembourg" - iso3countrycode "Luxemburg" - iso3countrycode "Niederlande" - iso3countrycode "Österreich" - iso3countrycode "Ungarn" - iso3countrycode "Schweiz" - iso3countrycode "Simbabwe" # should fail + testcmp "BEL" "iso3countrycode" "Belgien" + testcmp "DEU" "iso3countrycode" "Deutschland" + testcmp "GBR" "iso3countrycode" "England" + testcmp "LUX" "iso3countrycode" "Luxembourg" "Luxemburg" + testcmp "NLD" "iso3countrycode" "Niederlande" + testcmp "AUT" "iso3countrycode" "Österreich" + testcmp "HUN" "iso3countrycode" "Ungarn" + testcmp "CHE" "iso3countrycode" "Schweiz" + testcmp "" "iso3countrycode" "Simbabwe" # should fail } testiso3