Signed-off-by: Andrew Gregory <[email protected]>
---

It would be nice if somebody more familiar with bash than I am could double
check the way I handle printing the diff output on failures in pacsorttest.sh

 test/scripts/human_to_size_test.sh | 24 +++++++++++++++---------
 test/scripts/parseopts_test.sh     | 25 ++++++++++++++-----------
 test/util/pacsorttest.sh           | 28 +++++++++++++++++-----------
 test/util/vercmptest.sh            | 27 ++++++++++++---------------
 4 files changed, 58 insertions(+), 46 deletions(-)

diff --git a/test/scripts/human_to_size_test.sh 
b/test/scripts/human_to_size_test.sh
index dbf1997..678fa87 100755
--- a/test/scripts/human_to_size_test.sh
+++ b/test/scripts/human_to_size_test.sh
@@ -1,14 +1,16 @@
 #!/bin/bash
 
+declare -i testcount=0 fail=0 pass=0 total=15
+
 # source the library function
 if [[ -z $1 || ! -f $1 ]]; then
-  printf "error: path to human_to_size library not provided or does not 
exist\n"
+  printf "Bail out! path to human_to_size library not provided or does not 
exist\n"
   exit 1
 fi
 . "$1"
 
 if ! type -t human_to_size >/dev/null; then
-  printf 'human_to_size function not found\n'
+  printf 'Bail out! human_to_size function not found\n'
   exit 1
 fi
 
@@ -20,27 +22,31 @@ parse_hts() {
   result=$(human_to_size "$1")
   if [[ $result = "$expected" ]]; then
     (( ++pass ))
+    printf "ok %d - %s\n" "$testcount" "$input"
   else
     (( ++fail ))
-    printf '[TEST %3s]: FAIL\n' "$testcount"
-    printf '      input: %s\n' "$input"
-    printf '     output: %s\n' "$result"
-    printf '   expected: %s\n' "$expected"
+    printf "not ok %d - %s\n" "$testcount" "$input"
+    printf '# [TEST %3s]: FAIL\n' "$testcount"
+    printf '#      input: %s\n' "$input"
+    printf '#     output: %s\n' "$result"
+    printf '#   expected: %s\n' "$expected"
   fi
 }
 
 summarize() {
   if (( !fail )); then
-    printf 'All %s tests successful\n\n' "$testcount"
+    printf '# All %s tests successful\n\n' "$testcount"
     exit 0
   else
-    printf '%s of %s tests failed\n\n' "$fail" "$testcount"
+    printf '# %s of %s tests failed\n\n' "$fail" "$testcount"
     exit 1
   fi
 }
 trap 'summarize' EXIT
 
-printf 'Beginning human_to_size tests\n'
+printf '# Beginning human_to_size tests\n'
+
+echo "1..$total"
 
 # parse_hts <input> <expected output>
 
diff --git a/test/scripts/parseopts_test.sh b/test/scripts/parseopts_test.sh
index b7e5d08..8df1908 100755
--- a/test/scripts/parseopts_test.sh
+++ b/test/scripts/parseopts_test.sh
@@ -1,16 +1,16 @@
 #!/bin/bash
 
-declare -i testcount=0 pass=0 fail=0
+declare -i testcount=0 pass=0 fail=0 total=25
 
 # source the library function
 if [[ -z $1 || ! -f $1 ]]; then
-  printf "error: path to parseopts library not provided or does not exist\n"
+  printf "Bail out! path to parseopts library not provided or does not exist\n"
   exit 1
 fi
 . "$1"
 
 if ! type -t parseopts >/dev/null; then
-  printf 'parseopts function not found\n'
+  printf 'Bail out! parseopts function not found\n'
   exit 1
 fi
 
@@ -36,28 +36,31 @@ test_result() {
 
   if [[ $result = "$*" ]] && (( tokencount == $# )); then
     (( ++pass ))
+    printf 'ok %d - %s\n' "$testcount" "$input"
   else
-    printf '[TEST %3s]: FAIL\n' "$testcount"
-    printf '      input: %s\n' "$input"
-    printf '     output: %s (%s tokens)\n' "$*" "$#"
-    printf '   expected: %s (%s tokens)\n' "$result" "$tokencount"
-    echo
+    printf 'not ok %d - %s\n' "$testcount" "$input"
+    printf '# [TEST %3s]: FAIL\n' "$testcount"
+    printf '#      input: %s\n' "$input"
+    printf '#     output: %s (%s tokens)\n' "$*" "$#"
+    printf '#   expected: %s (%s tokens)\n' "$result" "$tokencount"
     (( ++fail ))
   fi
 }
 
 summarize() {
   if (( !fail )); then
-    printf 'All %s tests successful\n\n' "$testcount"
+    printf '# All %s tests successful\n\n' "$testcount"
     exit 0
   else
-    printf '%s of %s tests failed\n\n' "$fail" "$testcount"
+    printf '# %s of %s tests failed\n\n' "$fail" "$testcount"
     exit 1
   fi
 }
 trap 'summarize' EXIT
 
-printf 'Beginning parseopts tests\n'
+printf '# Beginning parseopts tests\n'
+
+echo "1..$total"
 
 # usage: parse <expected result> <token count> test-params...
 # a failed parse will match only the end of options marker '--'
diff --git a/test/util/pacsorttest.sh b/test/util/pacsorttest.sh
index 9cbf619..0abddc2 100755
--- a/test/util/pacsorttest.sh
+++ b/test/util/pacsorttest.sh
@@ -2,6 +2,7 @@
 #
 # pacsorttest - a test suite for pacsort
 #
+#   Copyright (c) 2013 by Pacman Development Team <[email protected]>
 #   Copyright (c) 2011 by Dan McGee <[email protected]>
 #
 #   This program is free software; you can redistribute it and/or modify
@@ -20,32 +21,39 @@
 # default binary if one was not specified as $1
 bin='pacsort'
 # holds counts of tests
-total=0
+total=23
+run=0
 failure=0
 
 # args:
 # runtest input expected test_description optional_opts
 runtest() {
        # run the test
-       diff -u <(printf "$1" | $bin $4) <(printf "$2")
-       if [[ $? -ne 0 ]]; then
-               echo "FAILURE: $3"
+       ((run++))
+       out=$(diff -u <(printf "$1" | $bin $4) <(printf "$2"))
+       if [[ $? -eq 0 ]]; then
+               echo "ok $run - $3"
+       else
                ((failure++))
+               echo "not ok $run - $3"
+               while read line; do
+                       echo "    # $line"
+               done <<<"$out"
        fi
-       ((total++))
 }
 
 # use first arg as our binary if specified
 [[ -n "$1" ]] && bin="$1"
 
 if ! type -p "$bin"; then
-       echo "pacsort binary ($bin) could not be located"
-       echo
+       echo "Bail out! pacsort binary ($bin) could not be located"
        exit 1
 fi
 
 echo "Running pacsort tests..."
 
+echo "1..$total"
+
 # BEGIN TESTS
 
 in="1\n2\n3\n4\n"
@@ -113,11 +121,9 @@ runtest "$separator" "$separator_reverse" "really long 
input, sort key, separato
 #END TESTS
 
 if [[ $failure -eq 0 ]]; then
-       echo "All $total tests successful"
-       echo
+       echo "# All $run tests successful"
        exit 0
 fi
 
-echo "$failure of $total tests failed"
-echo
+echo "# $failure of $run tests failed"
 exit 1
diff --git a/test/util/vercmptest.sh b/test/util/vercmptest.sh
index 04b841f..9297cdc 100755
--- a/test/util/vercmptest.sh
+++ b/test/util/vercmptest.sh
@@ -20,22 +20,20 @@
 # default binary if one was not specified as $1
 bin='vercmp'
 # holds counts of tests
-total=0
+total=92
+run=0
 failure=0
 
 # args:
 # pass ver1 ver2 ret expected
 pass() {
-       #echo "test: ver1: $1 ver2: $2 ret: $3 expected: $4"
-       #echo "  --> pass"
-       echo -n
+       echo "ok $run - ver1: $1 ver2: $2 ret: $3"
 }
 
 # args:
 # fail ver1 ver2 ret expected
 fail() {
-       echo "test: ver1: $1 ver2: $2 ret: $3 expected: $4"
-       echo "  ==> FAILURE"
+       echo "not ok $run - test: ver1: $1 ver2: $2 ret: $3 expected: $4"
        ((failure++))
 }
 
@@ -43,12 +41,13 @@ fail() {
 # runtest ver1 ver2 expected
 runtest() {
        # run the test
+       ((run++))
        ret=$($bin $1 $2)
        func='pass'
        [[ -n $ret && $ret -eq $3 ]] || func='fail'
        $func $1 $2 $ret $3
-       ((total++))
        # and run its mirror case just to be sure
+       ((run++))
        reverse=0
        [[ $3 -eq 1 ]] && reverse=-1
        [[ $3 -eq -1 ]] && reverse=1
@@ -56,19 +55,19 @@ runtest() {
        func='pass'
        [[ -n $ret && $ret -eq $reverse ]] || func='fail'
        $func $2 $1 $ret $reverse
-       ((total++))
 }
 
 # use first arg as our binary if specified
 [[ -n "$1" ]] && bin="$1"
 
 if ! type -p "$bin"; then
-       echo "vercmp binary ($bin) could not be located"
-       echo
+       echo "Bail out! vercmp binary ($bin) could not be located"
        exit 1
 fi
 
-echo "Running vercmp tests..."
+echo "# Running vercmp tests..."
+
+echo "1..$total"
 
 # BEGIN TESTS
 
@@ -147,11 +146,9 @@ runtest 1:1.1    1.1   1
 #END TESTS
 
 if [[ $failure -eq 0 ]]; then
-       echo "All $total tests successful"
-       echo
+       echo "# All $run tests successful"
        exit 0
 fi
 
-echo "$failure of $total tests failed"
-echo
+echo "# $failure of $run tests failed"
 exit 1
-- 
1.8.3.4


Reply via email to