Move important information up in -Si output
[pacman-ng.git] / test / util / pacsorttest.sh
blob9d52d69457d6c5613e4616836584e623e00dfde7
1 #!/bin/bash
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
21 bin='pacsort'
22 # holds counts of tests
23 total=0
24 failure=0
26 # args:
27 # runtest input expected test_description optional_opts
28 runtest() {
29 # run the test
30 diff -u <(printf "$1" | $bin $4) <(printf "$2")
31 if [[ $? -ne 0 ]]; then
32 echo "FAILURE: $3"
33 ((failure++))
35 ((total++))
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"
43 echo
44 exit 1
47 echo "Running pacsort tests..."
49 # BEGIN TESTS
51 in="1\n2\n3\n4\n"
52 runtest $in $in "already ordered"
54 in="4\n2\n3\n1\n"
55 ex="1\n2\n3\n4\n"
56 runtest $in $ex "easy reordering"
58 in="1\n2\n3\n4"
59 ex="1\n2\n3\n4\n"
60 runtest $in $ex "add trailing newline"
62 in="1\n2\n4\n3"
63 ex="1\n2\n3\n4\n"
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"
78 done
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"
95 #END TESTS
97 if [[ $failure -eq 0 ]]; then
98 echo "All $total tests successful"
99 echo
100 exit 0
103 echo "$failure of $total tests failed"
104 echo
105 exit 1