3 # pacsorttest - a test suite for pacsort
5 # Copyright (c) 2011 by Dan McGee <dan@archlinux.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # default binary if one was not specified as $1
22 # holds counts of tests
27 # runtest input expected test_description optional_opts
30 diff -u <(printf "$1" |
$bin $4) <(printf "$2")
31 if [[ $?
-ne 0 ]]; then
38 # use first arg as our binary if specified
39 [[ -n "$1" ]] && bin
="$1"
41 if ! type -p "$bin"; then
42 echo "pacsort binary ($bin) could not be located"
47 echo "Running pacsort tests..."
52 runtest
$in $in "already ordered"
56 runtest
$in $ex "easy reordering"
60 runtest
$in $ex "add trailing newline"
64 runtest
$in $ex "add trailing newline"
66 in="1.0-1\n1.0\n1.0-2\n1.0\n"
67 runtest
$in $in "stable sort"
69 # generate some long input/expected for the next few tests
70 declare normal reverse names_normal names_reverse
71 for ((i
=1; i
<600; i
++)); do
72 normal
="${normal}${i}\n"
73 reverse
="${reverse}$((600 - ${i}))\n"
74 fields
="${fields}colA bogus$((600 - ${i})) ${i}\n"
75 fields_reverse
="${fields_reverse}colA bogus${i} $((600 - ${i}))\n"
76 separator
="${separator}colA|bogus$((600 - ${i}))|${i}\n"
77 separator_reverse
="${separator_reverse}colA|bogus${i}|$((600 - ${i}))\n"
80 runtest
$normal $normal "really long input"
81 runtest
$reverse $normal "really long input"
82 runtest
$reverse $reverse "really long input, reversed" "-r"
83 runtest
$normal $reverse "really long input, reversed" "-r"
85 runtest
"$fields" "$fields" "really long input, sort key" "-k3"
86 runtest
"$fields_reverse" "$fields" "really long input, sort key" "-k3"
87 runtest
"$fields_reverse" "$fields_reverse" "really long input, sort key, reversed" "-k 3 -r"
88 runtest
"$fields" "$fields_reverse" "really long input, sort key, reversed" "-k 3 -r"
90 runtest
"$separator" "$separator" "really long input, sort key, separator" "-k3 -t|"
91 runtest
"$separator_reverse" "$separator" "really long input, sort key, separator" "-k3 -t|"
92 runtest
"$separator_reverse" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r"
93 runtest
"$separator" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r"
97 if [[ $failure -eq 0 ]]; then
98 echo "All $total tests successful"
103 echo "$failure of $total tests failed"