Remove building with NOCRYPTO option
[minix.git] / tests / usr.bin / sort / t_sort.sh
bloba36457cb41eca41bdf6f393d6c84fa2b7ad67903
1 # $NetBSD: t_sort.sh,v 1.1 2012/03/17 16:33:15 jruoho Exp $
3 # Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc.
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
28 atf_test_case basic
29 basic_head()
31 atf_set "descr" "Basic functionality test"
33 basic_body()
35 cat >in <<EOF
36 z b m f
37 y c o e
38 x a n h
39 x a n g
40 EOF
42 cat >expout <<EOF
43 x a n g
44 x a n h
45 y c o e
46 z b m f
47 EOF
49 atf_check -o file:expout sort in
52 atf_test_case empty_file
53 empty_file_head()
55 atf_set "descr" "Tests sorting an empty file"
57 empty_file_body()
59 touch empty
60 atf_check -o empty sort -S empty
61 atf_check sort -S -c empty
62 atf_check sort -S -c -u empty
65 atf_test_case end_of_options
66 end_of_options_head()
68 atf_set "descr" "Determination of end of option list"
70 end_of_options_body()
72 echo x >-k
73 atf_check -o file:-k -x "sort -S -- -k </dev/null"
74 atf_check -s not-exit:1 -e ignore -x "sort -S - -c </dev/null"
77 atf_test_case missing_newline
78 missing_newline_head()
80 atf_set "descr" "Tests with missing new line in input file"
82 missing_newline_body()
84 printf '%s' x >in
85 atf_check -o inline:'x\n' sort in
88 atf_test_case null_bytes
89 null_bytes_head()
91 atf_set "descr" "Tests the behavior of null bytes"
93 null_bytes_body()
95 printf '\0b\n\0a\n' >in
96 atf_check -o inline:'\0a\n\0b\n' sort -S in
99 atf_test_case long_records
100 long_records_head()
102 atf_set "descr" "Tests long lines and keys"
104 long_records_body()
106 awk 'BEGIN { x="x"
107 for(i=1; i<=12; i++) x = x x
108 for(i=15; i<=25; i++) print x i
109 }' >in
111 awk 'BEGIN { x="x"
112 for(i=1; i<=12; i++) x = x x
113 for(i=25; i>=15; i--) print x i
114 }' >out
116 atf_check -o file:out sort -r in
117 atf_check -o file:out sort -k 1,1r -k 1 in
120 atf_test_case long_file
121 long_file_head()
123 atf_set "descr" "Tests with a long file to try to force intermediate" \
124 "files"
126 long_file_body()
128 awk 'BEGIN { for(i=0; i<20000; i++) print rand() }' >in
129 sort -S -r in | awk '$0 "x" != x { print ; x = $0 "x" }' >out
130 atf_check -o file:out sort -u -r in
133 atf_test_case any_char
134 any_char_head()
136 atf_set "descr" "Tests with files containing non-printable/extended" \
137 "characters"
139 any_char_body()
141 atf_check -o file:$(atf_get_srcdir)/d_any_char_dflag_out.txt \
142 sort -d -k 2 $(atf_get_srcdir)/d_any_char_in.txt
144 atf_check -o file:$(atf_get_srcdir)/d_any_char_fflag_out.txt \
145 sort -f -k 2 $(atf_get_srcdir)/d_any_char_in.txt
147 atf_check -o file:$(atf_get_srcdir)/d_any_char_iflag_out.txt \
148 sort -i -k 2 $(atf_get_srcdir)/d_any_char_in.txt
151 atf_test_case bflag
152 bflag_head()
154 atf_set "descr" "Tests the -b flag"
156 bflag_body()
158 cat >in <<EOF
163 atf_check -o file:in sort -b in
164 atf_check -o file:in -x "sort -b <in"
165 atf_check -s exit:1 -o ignore -e ignore -x "sort in | sort -c -r"
168 atf_test_case cflag
169 cflag_head()
171 atf_set "descr" "Tests the -c flag"
173 cflag_body()
175 cat >in <<EOF
180 atf_check -s exit:1 -e ignore sort -S -c in
183 atf_test_case kflag_one_field
184 kflag_one_field_head()
186 atf_set "descr" "Tests the -k flag with one field"
188 kflag_one_field_body()
190 cat >in <<EOF
191 z b m f
192 y c o e
193 x a n h
194 x a n g
197 cat >expout <<EOF
198 x a n g
199 x a n h
200 z b m f
201 y c o e
204 atf_check -o file:expout sort -k2.1 in
207 atf_test_case kflag_two_fields
208 kflag_two_fields_head()
210 atf_set "descr" "Tests the -k flag with two fields"
212 kflag_two_fields_body()
214 cat >in <<EOF
215 z b m f
216 y c o e
217 x a n h
218 x a n g
221 cat >expout <<EOF
222 x a n h
223 x a n g
224 z b m f
225 y c o e
227 atf_check -o file:expout sort -k2.1,2.0 in
230 atf_test_case kflag_many_fields
231 kflag_many_fields_head()
233 atf_set "descr" "Tests the -k flag with many fields"
235 kflag_many_fields_body()
237 cat >in <<EOF
238 0:2:3:4:5:6:7:8:9
239 1:1:3:4:5:6:7:8:9
240 1:2:2:4:5:6:7:8:9
241 1:2:3:3:5:6:7:8:9
242 1:2:3:4:4:6:7:8:9
243 1:2:3:4:5:5:7:8:9
244 1:2:3:4:5:6:6:8:9
245 1:2:3:4:5:6:7:7:9
246 1:2:3:4:5:6:7:8:8
249 cat >out <<EOF
250 1:2:3:4:5:6:7:8:8
251 1:2:3:4:5:6:7:7:9
252 1:2:3:4:5:6:6:8:9
253 1:2:3:4:5:5:7:8:9
254 1:2:3:4:4:6:7:8:9
255 1:2:3:3:5:6:7:8:9
256 1:2:2:4:5:6:7:8:9
257 1:1:3:4:5:6:7:8:9
258 0:2:3:4:5:6:7:8:9
261 atf_check -o file:out sort -t: -k9 -k8 -k7 -k6 -k5 -k4 -k3 \
262 -k2 -k1 in
265 atf_test_case kflag_outofbounds
266 kflag_outofbounds_head()
268 atf_set "descr" "Tests the -k flag with out of bounds fields"
270 kflag_outofbounds_body()
272 cat >in <<EOF
281 atf_check -o file:in sort -k2.2,2.1 -k2.3,2.4 in
284 atf_test_case kflag_nonmonotone
285 kflag_nonmonotone_head()
287 atf_set "descr" "Tests the -k flag with apparently nonmonotone" \
288 "field specs"
290 kflag_nonmonotone_body()
292 cat >in <<EOF
293 aaaa c
298 atf_check -o file:in sort -k2,1.3 -k2.5,2.5 in
301 atf_test_case kflag_limits
302 kflag_limits_head()
304 atf_set "descr" "Tests the -k flag field limits"
306 kflag_limits_body()
308 cat >in <<EOF
315 cat >out <<EOF
322 atf_check -o file:out sort -r -k1,1 -k2n in
325 atf_test_case kflag_alpha
326 kflag_alpha_head()
328 atf_set "descr" "Tests the -k flag with various alpha fields"
330 kflag_alpha_body()
332 sort >in <<EOF
333 01:04:19:01:16:01:21:01 a
334 02:03:13:15:13:19:15:02 a
335 03:02:07:09:07:13:09:03 a
336 04:01:01:03:01:07:03:04 a
337 05:08:20:16:17:02:20:05 aa
338 06:07:14:18:14:20:14:06 aa
339 07:06:08:10:08:14:08:07 aa
340 08:05:02:04:02:08:02:08 aa
341 09:16:22:02:22:04:24:13 b
342 10:15:16:20:19:22:18:14 b
343 11:14:10:12:10:16:12:15 b
344 12:13:04:06:04:10:06:16 b
345 13:24:24:22:24:06:22:21 bb
346 14:23:18:24:21:24:16:22 bb
347 15:22:12:14:12:18:10:23 bb
348 16:21:06:08:06:12:04:24 bb
349 17:12:21:21:18:03:19:09 ab
350 18:11:15:19:15:21:13:10 ab
351 19:10:09:11:09:15:07:11 ab
352 20:09:03:05:03:09:01:12 ab
353 21:20:23:17:23:05:23:17 ba
354 22:19:17:23:20:23:17:18 ba
355 23:18:11:13:11:17:11:19 ba
356 24:17:05:07:05:11:05:20 ba
359 atf_check -x "sort -S -k2b -k2 in >xx"
360 atf_check -e ignore sort -c -t: -k2n xx
362 atf_check -x "sort -S -k2,2.1b -k2 in >xx"
363 atf_check -e ignore sort -c -t: -k3n xx
365 atf_check -x "sort -S -k2.3 -k2 in >xx"
366 atf_check -e ignore sort -c -t: -k4n xx
368 atf_check -x "sort -S -k2b,2.3 -k2 in >xx"
369 atf_check -e ignore sort -c -t: -k5n xx
371 atf_check -x "sort -S -k2.3,2.1b -k2 in >xx"
372 atf_check -e ignore sort -c -t: -k6n xx
374 atf_check -x "sort -S -k2,2.1b -k2r in >xx"
375 atf_check -e ignore sort -c -t: -k7n xx
377 atf_check -x "sort -S -b -k2,2 -k2 in >xx"
378 atf_check -e ignore sort -c -t: -k8n xx
380 # XXX This test is broken. The standard is not clear on the behavior.
381 #atf_check -x "sort -S -b -k2,2b -k2 in >xx"
382 #atf_check -e ignore sort -c -t: -k3n xx
385 atf_test_case kflag_no_end
386 kflag_no_end_head()
388 atf_set "descr" "Tests the -k flag with a field without end"
390 kflag_no_end_body()
392 cat >in <<EOF
400 cat >out <<EOF
408 atf_check -o file:out sort -df -k 1 -k 1d <in
411 atf_test_case mflag
412 mflag_head()
414 atf_set "descr" "Tests the -m flag"
416 mflag_body()
418 cat >in1 <<EOF
425 cat >in2 <<EOF
432 cat >out <<EOF
445 atf_check -o file:out sort -S -m in1 in2
448 atf_test_case mflag_uflag
449 mflag_uflag_head()
451 atf_set "descr" "Tests the -m flag together with -u"
453 mflag_uflag_body()
455 cat >in <<EOF
462 atf_check -o file:in sort -m -u in
465 atf_test_case mflag_uflag_first
466 mflag_uflag_first_head()
468 atf_set "descr" "Tests that the -m flag together with -u picks the" \
469 "first among equal"
471 mflag_uflag_first_body()
473 cat >in <<EOF
477 ~3B2
484 cat >out <<EOF
491 atf_check -o file:out sort -mudf in
492 atf_check -o file:out sort -mudf -k1 in
495 atf_test_case nflag
496 nflag_head()
498 atf_set "descr" "Tests the -n flag"
500 nflag_body()
502 cat >in <<EOF
503 -99.0
504 -99.1
505 -.0002
508 0010.000000000000000000000000000000000001
514 cat >expout <<EOF
515 -99.1
516 -99.0
518 -.0002
523 0010.000000000000000000000000000000000001
526 atf_check -o file:expout sort -n in
529 atf_test_case nflag_rflag
530 nflag_rflag_head()
532 atf_set "descr" "Tests the -n and -r flag combination"
534 nflag_rflag_body()
536 cat >in <<EOF
542 cat >expout <<EOF
548 atf_check -o file:expout sort -rn in
551 atf_test_case oflag
552 oflag_head()
554 atf_set "descr" "Tests the -o flag"
556 oflag_body()
558 cat >in <<EOF
569 atf_check sort -u -o in in
571 cat >expout <<EOF
578 atf_check -o file:expout cat in
581 atf_test_case oflag_displaced
582 oflag_displaced_head()
584 atf_set "descr" "Tests the -o flag after the file names"
586 oflag_displaced_body()
588 atf_check sort -S /dev/null -o out
589 test -f out || atf_fail "File not created"
592 atf_test_case rflag
593 rflag_head()
595 atf_set "descr" "Tests the -r flag"
597 rflag_body()
599 cat >in <<EOF
600 z b m f
601 y c o e
602 x a n h
603 x a n g
606 cat >expout <<EOF
607 z b m f
608 y c o e
609 x a n h
610 x a n g
613 atf_check -o file:expout sort -r in
616 atf_test_case sflag
617 sflag_head()
619 atf_set "descr" "Tests the -s flag"
621 sflag_body()
623 cat >in <<EOF
632 cat >out <<EOF
641 atf_check -o file:out sort -s -k1,1 in
644 atf_test_case sflag_many_files
645 sflag_many_files_head()
647 atf_set "descr" "Tests the -s flag with multiple files"
649 sflag_many_files_body()
651 cat >in1 <<EOF
656 cat >in2 <<EOF
662 cat >out <<EOF
668 atf_check -o file:out sort -smru -k1,1 in1 in1 in2 in2
671 atf_test_case tflag
672 tflag_head()
674 atf_set "descr" "Tests the -t flag"
676 tflag_body()
678 cat >in <<EOF
683 atf_check -o file:in sort -t : -r +0 in
684 atf_check -o file:in sort -t : +0 -1 in
685 atf_check -o file:in sort -t : -r -k 1 in
686 atf_check -o file:in sort -t : -k 1,1 in
689 atf_test_case tflag_alphabetic
690 tflag_alphabetic_head()
692 atf_set "descr" "Tests the -t flag with a character as the delimiter"
694 tflag_alphabetic_body()
696 cat >in <<EOF
702 atf_check -o file:in sort -tX -k2 -k1r,1 in
705 atf_test_case tflag_char_pos
706 tflag_char_pos_head()
708 atf_set "descr" "Tests the -t flag with character positions in fields"
710 tflag_char_pos_body()
712 cat >in <<EOF
713 : ab
714 :bac
717 cat >out <<EOF
718 :bac
719 : ab
722 atf_check -o file:out sort -b -t: +1.1 in
723 atf_check -o file:out sort -t: +1.1r in
724 atf_check -o file:out sort -b -t: -k 2.2 in
725 atf_check -o file:out sort -t: -k 2.2r in
728 atf_test_case tflag_whitespace
729 tflag_whitespace_head()
731 atf_set "descr" "Tests the -t flag with spaces and tabs as the" \
732 "delimiter"
734 tflag_whitespace_body()
736 cat >in <<EOF
742 atf_check -o file:in sort -t ' ' -k2,2 in
743 atf_check -o file:in sort -t ' ' -k2.1,2.0 in
745 cat >out <<EOF
751 atf_check -o file:out sort -t ' ' -k2,2 in
752 atf_check -o file:out sort -t ' ' -k2.1,2.0 in
754 cat >out <<EOF
760 atf_check -o file:out sort -S -k2 in
762 cat >out <<EOF
768 atf_check -o file:out sort -S -k2b in
771 atf_test_case uflag
772 uflag_head()
774 atf_set "descr" "Tests the -u flag"
776 uflag_body()
778 cat >in <<EOF
785 cat >expout <<EOF
791 atf_check -o file:expout sort -u in
794 atf_test_case uflag_rflag
795 uflag_rflag_head()
797 atf_set "descr" "Tests the -u and -r flag combination"
799 uflag_rflag_body()
801 cat >in <<EOF
808 cat >expout <<EOF
814 atf_check -o file:expout sort -ru in
817 atf_test_case plus_one
818 plus_one_head()
820 atf_set "descr" "Tests +- addressing: +1 should become -k2.1"
822 plus_one_body()
824 cat >in <<EOF
825 z b m f
826 y c o e
827 x a n h
828 x a n g
831 cat >expout <<EOF
832 x a n g
833 x a n h
834 z b m f
835 y c o e
838 atf_check -o file:expout sort +1 in
841 atf_test_case plus_one_minus_two
842 plus_one_minus_two_head()
844 atf_set "descr" "Tests +- addressing: +1 -2 should become -k2.1,2.0"
846 plus_one_minus_two_body()
848 cat >in <<EOF
849 z b m f
850 y c o e
851 x a n h
852 x a n g
855 cat >expout <<EOF
856 x a n h
857 x a n g
858 z b m f
859 y c o e
862 atf_check -o file:expout sort +1 -2 in
865 atf_test_case plus_zero
866 plus_zero_head()
868 atf_set "descr" "Tests +- addressing: '-- +0' raised a '-k1.1: No" \
869 "such file or directory' error"
871 plus_zero_body()
873 echo 'good contents' >./+0
875 atf_check -o file:+0 sort -- +0
878 atf_test_case plus_nonmonotone
879 plus_nonmonotone_head()
881 atf_set "descr" "Tests += addressing: apparently nonmonotone field" \
882 "specs"
884 plus_nonmonotone_body()
886 cat >in <<EOF
887 aaaa c
892 atf_check -o file:in sort +1 -0.3 +1.4 -1.5 in
895 atf_test_case plus_as_path
896 plus_as_path_head()
898 atf_set "descr" "Tests +- addressing: 'file +0' raised a '-k1.1: No" \
899 "such file or directory' error"
901 plus_as_path_body()
903 echo 'good contents' >./+0
904 echo 'more contents' >in
905 cat ./+0 in >expout
907 atf_check -o file:expout sort in +0
910 atf_test_case plus_bad_tempfile
911 plus_bad_tempfile_head()
913 atf_set "descr" "Tests +- addressing: intermediate wrong behavior" \
914 "that raised a '+0: No such file or directory' error"
916 plus_bad_tempfile_body()
918 echo 'good contents' >in
919 atf_check -o file:in sort -T /tmp +0 in
922 atf_test_case plus_rflag_invalid
923 plus_rflag_invalid_head()
925 atf_set "descr" "Tests +- addressing: invalid record delimiter"
927 plus_rflag_invalid_body()
930 echo 'z b m f'
931 echo 'y c o e'
932 echo 'x a n h'
933 echo 'x a n g'
934 ) | tr '\n' '+' >in
936 atf_check -o inline:'x a n g+x a n h+z b m f+y c o e+' \
937 sort -R + -k2 in
940 atf_test_case plus_tflag
941 plus_tflag_head()
943 atf_set "descr" "Tests +- addressing: using -T caused a 'No such file" \
944 "or directory' error"
946 plus_tflag_body()
948 mkdir ./+
949 yes | sed 200000q | sort -T + >/dev/null || atf_fail "program failed"
952 atf_test_case plus_no_end
953 plus_no_end_head()
955 atf_set "descr" "Tests +- addressing: field without end"
957 plus_no_end_body()
959 cat >in <<EOF
967 cat >out <<EOF
975 atf_check -o file:out sort -df +0 +0d in
978 atf_init_test_cases()
980 atf_add_test_case basic
981 atf_add_test_case empty_file
982 atf_add_test_case end_of_options
983 atf_add_test_case missing_newline
984 atf_add_test_case null_bytes
985 atf_add_test_case long_records
986 atf_add_test_case long_file
987 atf_add_test_case any_char
988 atf_add_test_case bflag
989 atf_add_test_case cflag
990 atf_add_test_case kflag_one_field
991 atf_add_test_case kflag_two_fields
992 atf_add_test_case kflag_many_fields
993 atf_add_test_case kflag_outofbounds
994 atf_add_test_case kflag_nonmonotone
995 atf_add_test_case kflag_limits
996 atf_add_test_case kflag_alpha
997 atf_add_test_case kflag_no_end
998 atf_add_test_case mflag
999 atf_add_test_case mflag_uflag
1000 atf_add_test_case mflag_uflag_first
1001 atf_add_test_case nflag
1002 atf_add_test_case nflag_rflag
1003 atf_add_test_case oflag
1004 atf_add_test_case oflag_displaced
1005 atf_add_test_case rflag
1006 atf_add_test_case sflag
1007 atf_add_test_case sflag_many_files
1008 atf_add_test_case tflag
1009 atf_add_test_case tflag_alphabetic
1010 atf_add_test_case tflag_char_pos
1011 atf_add_test_case tflag_whitespace
1012 atf_add_test_case uflag
1013 atf_add_test_case uflag_rflag
1014 atf_add_test_case plus_one
1015 atf_add_test_case plus_one_minus_two
1016 atf_add_test_case plus_zero
1017 atf_add_test_case plus_nonmonotone
1018 atf_add_test_case plus_as_path
1019 atf_add_test_case plus_bad_tempfile
1020 atf_add_test_case plus_rflag_invalid
1021 atf_add_test_case plus_tflag
1022 atf_add_test_case plus_no_end