3 # pacsorttest - a test suite for pacsort
5 # Copyright (c) 2013 by Pacman Development Team <pacman-dev@archlinux.org>
6 # Copyright (c) 2011 by Dan McGee <dan@archlinux.org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # default binary if one was not specified as $1
22 bin
=${1:-${PMTEST_UTIL_DIR}pacsort}
23 # holds counts of tests
28 if ! type -p "$bin"; then
29 echo "Bail out! pacsort binary ($bin) could not be located"
34 # runtest input expected test_description optional_opts
38 out
=$(diff -u <(printf "$1" | $bin $4) <(printf "$2"))
39 if [[ $?
-eq 0 ]]; then
43 echo "not ok $run - $3"
50 echo "Running pacsort tests..."
57 runtest
$in $in "already ordered"
61 runtest
$in $ex "easy reordering"
65 runtest
$in $ex "add trailing newline"
69 runtest
$in $ex "add trailing newline"
71 in="1.0-1\n1.0\n1.0-2\n1.0\n"
72 runtest
$in $in "stable sort"
74 in="firefox-18.0-2-x86_64.pkg.tar.xz\nfirefox-18.0.1-1-x86_64.pkg.tar.xz\n"
75 runtest
$in $in "filename sort" "--files"
77 in="firefox-18.0-2\nfirefox-18.0.1-1-x86_64.pkg.tar.xz\n"
78 runtest
$in $in "filename sort with invalid filename" "--files"
80 in="firefox-18.0-2-x86_64.pkg.tar.xz\n/path2/firefox-18.0.1-1-x86_64.pkg.tar.xz\n"
81 runtest
$in $in "filename sort maybe with leading paths" "--files"
83 in="/path1/firefox-18.0-2-x86_64.pkg.tar.xz\n/path2/firefox-18.0.1-1-x86_64.pkg.tar.xz\n"
84 runtest
$in $in "filename sort with different leading paths" "--files"
86 in="/path2/firefox-18.0-2-x86_64.pkg.tar.xz\n/path1/path2/firefox-18.0.1-1-x86_64.pkg.tar.xz\n"
87 runtest
$in $in "filename sort with uneven leading path components" "--files"
89 in="firefox-18.0-2-i686.pkg.tar.xz\nfirefox-18.0.1-1-x86_64.pkg.tar.gz\n"
90 runtest
$in $in "filename sort with different extensions" "--files"
92 # generate some long input/expected for the next few tests
93 declare normal reverse names_normal names_reverse
94 for ((i
=1; i
<600; i
++)); do
95 normal
="${normal}${i}\n"
96 reverse
="${reverse}$((600 - ${i}))\n"
97 fields
="${fields}colA bogus$((600 - ${i})) ${i}\n"
98 fields_reverse
="${fields_reverse}colA bogus${i} $((600 - ${i}))\n"
99 separator
="${separator}colA|bogus$((600 - ${i}))|${i}\n"
100 separator_reverse
="${separator_reverse}colA|bogus${i}|$((600 - ${i}))\n"
103 runtest
$normal $normal "really long input"
104 runtest
$reverse $normal "really long input"
105 runtest
$reverse $reverse "really long input, reversed" "-r"
106 runtest
$normal $reverse "really long input, reversed" "-r"
108 runtest
"$fields" "$fields" "really long input, sort key" "-k3"
109 runtest
"$fields_reverse" "$fields" "really long input, sort key" "-k3"
110 runtest
"$fields_reverse" "$fields_reverse" "really long input, sort key, reversed" "-k 3 -r"
111 runtest
"$fields" "$fields_reverse" "really long input, sort key, reversed" "-k 3 -r"
113 runtest
"$separator" "$separator" "really long input, sort key, separator" "-k3 -t|"
114 runtest
"$separator_reverse" "$separator" "really long input, sort key, separator" "-k3 -t|"
115 runtest
"$separator_reverse" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r"
116 runtest
"$separator" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r"
120 if [[ $failure -eq 0 ]]; then
121 echo "# All $run tests successful"
125 echo "# $failure of $run tests failed"