]>
Commit | Line | Data |
---|---|---|
d9f9b87d DM |
1 | #!/bin/bash |
2 | # | |
3 | # pacsorttest - a test suite for pacsort | |
4 | # | |
d3726bbd | 5 | # Copyright (c) 2013 by Pacman Development Team <pacman-dev@archlinux.org> |
d9f9b87d DM |
6 | # Copyright (c) 2011 by Dan McGee <dan@archlinux.org> |
7 | # | |
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. | |
12 | # | |
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. | |
17 | # | |
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/>. | |
20 | ||
21 | # default binary if one was not specified as $1 | |
22 | bin='pacsort' | |
23 | # holds counts of tests | |
d3726bbd AG |
24 | total=23 |
25 | run=0 | |
d9f9b87d DM |
26 | failure=0 |
27 | ||
28 | # args: | |
29 | # runtest input expected test_description optional_opts | |
30 | runtest() { | |
31 | # run the test | |
d3726bbd AG |
32 | ((run++)) |
33 | out=$(diff -u <(printf "$1" | $bin $4) <(printf "$2")) | |
34 | if [[ $? -eq 0 ]]; then | |
35 | echo "ok $run - $3" | |
36 | else | |
d9f9b87d | 37 | ((failure++)) |
d3726bbd AG |
38 | echo "not ok $run - $3" |
39 | while read line; do | |
40 | echo " # $line" | |
41 | done <<<"$out" | |
d9f9b87d | 42 | fi |
d9f9b87d DM |
43 | } |
44 | ||
45 | # use first arg as our binary if specified | |
46 | [[ -n "$1" ]] && bin="$1" | |
47 | ||
48 | if ! type -p "$bin"; then | |
d3726bbd | 49 | echo "Bail out! pacsort binary ($bin) could not be located" |
d9f9b87d DM |
50 | exit 1 |
51 | fi | |
52 | ||
cc13f475 | 53 | echo "Running pacsort tests..." |
d9f9b87d | 54 | |
d3726bbd AG |
55 | echo "1..$total" |
56 | ||
d9f9b87d DM |
57 | # BEGIN TESTS |
58 | ||
59 | in="1\n2\n3\n4\n" | |
60 | runtest $in $in "already ordered" | |
61 | ||
62 | in="4\n2\n3\n1\n" | |
63 | ex="1\n2\n3\n4\n" | |
64 | runtest $in $ex "easy reordering" | |
65 | ||
66 | in="1\n2\n3\n4" | |
67 | ex="1\n2\n3\n4\n" | |
68 | runtest $in $ex "add trailing newline" | |
69 | ||
70 | in="1\n2\n4\n3" | |
71 | ex="1\n2\n3\n4\n" | |
72 | runtest $in $ex "add trailing newline" | |
73 | ||
74 | in="1.0-1\n1.0\n1.0-2\n1.0\n" | |
75 | runtest $in $in "stable sort" | |
76 | ||
a64a713f DR |
77 | in="firefox-18.0-2-x86_64.pkg.tar.xz\nfirefox-18.0.1-1-x86_64.pkg.tar.xz\n" |
78 | runtest $in $in "filename sort" "--files" | |
79 | ||
80 | in="firefox-18.0-2\nfirefox-18.0.1-1-x86_64.pkg.tar.xz\n" | |
81 | runtest $in $in "filename sort with invalid filename" "--files" | |
82 | ||
83 | in="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 maybe with leading paths" "--files" | |
85 | ||
86 | in="/path1/firefox-18.0-2-x86_64.pkg.tar.xz\n/path2/firefox-18.0.1-1-x86_64.pkg.tar.xz\n" | |
87 | runtest $in $in "filename sort with different leading paths" "--files" | |
88 | ||
89 | 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" | |
90 | runtest $in $in "filename sort with uneven leading path components" "--files" | |
91 | ||
92 | in="firefox-18.0-2-i686.pkg.tar.xz\nfirefox-18.0.1-1-x86_64.pkg.tar.gz\n" | |
93 | runtest $in $in "filename sort with different extensions" "--files" | |
94 | ||
d9f9b87d DM |
95 | # generate some long input/expected for the next few tests |
96 | declare normal reverse names_normal names_reverse | |
97 | for ((i=1; i<600; i++)); do | |
98 | normal="${normal}${i}\n" | |
99 | reverse="${reverse}$((600 - ${i}))\n" | |
100 | fields="${fields}colA bogus$((600 - ${i})) ${i}\n" | |
101 | fields_reverse="${fields_reverse}colA bogus${i} $((600 - ${i}))\n" | |
102 | separator="${separator}colA|bogus$((600 - ${i}))|${i}\n" | |
103 | separator_reverse="${separator_reverse}colA|bogus${i}|$((600 - ${i}))\n" | |
104 | done | |
105 | ||
106 | runtest $normal $normal "really long input" | |
107 | runtest $reverse $normal "really long input" | |
108 | runtest $reverse $reverse "really long input, reversed" "-r" | |
109 | runtest $normal $reverse "really long input, reversed" "-r" | |
110 | ||
111 | runtest "$fields" "$fields" "really long input, sort key" "-k3" | |
112 | runtest "$fields_reverse" "$fields" "really long input, sort key" "-k3" | |
113 | runtest "$fields_reverse" "$fields_reverse" "really long input, sort key, reversed" "-k 3 -r" | |
114 | runtest "$fields" "$fields_reverse" "really long input, sort key, reversed" "-k 3 -r" | |
115 | ||
116 | runtest "$separator" "$separator" "really long input, sort key, separator" "-k3 -t|" | |
117 | runtest "$separator_reverse" "$separator" "really long input, sort key, separator" "-k3 -t|" | |
118 | runtest "$separator_reverse" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r" | |
119 | runtest "$separator" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r" | |
120 | ||
121 | #END TESTS | |
122 | ||
d9f9b87d | 123 | if [[ $failure -eq 0 ]]; then |
d3726bbd | 124 | echo "# All $run tests successful" |
d9f9b87d DM |
125 | exit 0 |
126 | fi | |
127 | ||
d3726bbd | 128 | echo "# $failure of $run tests failed" |
d9f9b87d | 129 | exit 1 |