diff --git a/contrib/netbsd-tests/usr.bin/sort/t_sort.sh b/contrib/netbsd-tests/usr.bin/sort/t_sort.sh index a36457cb41ec..431d23b69f96 100755 --- a/contrib/netbsd-tests/usr.bin/sort/t_sort.sh +++ b/contrib/netbsd-tests/usr.bin/sort/t_sort.sh @@ -1,1023 +1,1036 @@ # $NetBSD: t_sort.sh,v 1.1 2012/03/17 16:33:15 jruoho Exp $ # # Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # +# The -S flag in NetBSD sort enables non-stable sorting order. This flag +# doesn't exist in FreeBSD sort, and instead indicates buffer size, so all +# instances of this flag should be removed. +# +# For tests that expect exact output, but where some lines may compare +# the same, the flag -s should be added to enforce an expected sorting order. + atf_test_case basic basic_head() { atf_set "descr" "Basic functionality test" } basic_body() { cat >in <expout <-k - atf_check -o file:-k -x "sort -S -- -k in atf_check -o inline:'x\n' sort in } atf_test_case null_bytes null_bytes_head() { atf_set "descr" "Tests the behavior of null bytes" } null_bytes_body() { printf '\0b\n\0a\n' >in - atf_check -o inline:'\0a\n\0b\n' sort -S in + atf_check -o inline:'\0a\n\0b\n' sort in } atf_test_case long_records long_records_head() { atf_set "descr" "Tests long lines and keys" } long_records_body() { awk 'BEGIN { x="x" for(i=1; i<=12; i++) x = x x for(i=15; i<=25; i++) print x i }' >in awk 'BEGIN { x="x" for(i=1; i<=12; i++) x = x x for(i=25; i>=15; i--) print x i }' >out atf_check -o file:out sort -r in atf_check -o file:out sort -k 1,1r -k 1 in } atf_test_case long_file long_file_head() { atf_set "descr" "Tests with a long file to try to force intermediate" \ "files" } long_file_body() { awk 'BEGIN { for(i=0; i<20000; i++) print rand() }' >in - sort -S -r in | awk '$0 "x" != x { print ; x = $0 "x" }' >out + sort -r in | awk '$0 "x" != x { print ; x = $0 "x" }' >out atf_check -o file:out sort -u -r in } atf_test_case any_char any_char_head() { atf_set "descr" "Tests with files containing non-printable/extended" \ "characters" } any_char_body() { atf_check -o file:$(atf_get_srcdir)/d_any_char_dflag_out.txt \ sort -d -k 2 $(atf_get_srcdir)/d_any_char_in.txt atf_check -o file:$(atf_get_srcdir)/d_any_char_fflag_out.txt \ sort -f -k 2 $(atf_get_srcdir)/d_any_char_in.txt atf_check -o file:$(atf_get_srcdir)/d_any_char_iflag_out.txt \ sort -i -k 2 $(atf_get_srcdir)/d_any_char_in.txt } atf_test_case bflag bflag_head() { atf_set "descr" "Tests the -b flag" } bflag_body() { + atf_expect_fail "Behavior differs from NetBSD" cat >in <in <in <expout <in <expout <in <out <in <in <in <out <in <xx" + atf_check -x "sort -k2b -k2 in >xx" atf_check -e ignore sort -c -t: -k2n xx - atf_check -x "sort -S -k2,2.1b -k2 in >xx" + atf_check -x "sort -k2,2.1b -k2 in >xx" atf_check -e ignore sort -c -t: -k3n xx - atf_check -x "sort -S -k2.3 -k2 in >xx" + atf_check -x "sort -k2.3 -k2 in >xx" atf_check -e ignore sort -c -t: -k4n xx - atf_check -x "sort -S -k2b,2.3 -k2 in >xx" + atf_check -x "sort -k2b,2.3 -k2 in >xx" atf_check -e ignore sort -c -t: -k5n xx - atf_check -x "sort -S -k2.3,2.1b -k2 in >xx" + atf_check -x "sort -k2.3,2.1b -k2 in >xx" atf_check -e ignore sort -c -t: -k6n xx - atf_check -x "sort -S -k2,2.1b -k2r in >xx" + atf_check -x "sort -k2,2.1b -k2r in >xx" atf_check -e ignore sort -c -t: -k7n xx - atf_check -x "sort -S -b -k2,2 -k2 in >xx" + atf_check -x "sort -b -k2,2 -k2 in >xx" atf_check -e ignore sort -c -t: -k8n xx # XXX This test is broken. The standard is not clear on the behavior. #atf_check -x "sort -S -b -k2,2b -k2 in >xx" #atf_check -e ignore sort -c -t: -k3n xx } atf_test_case kflag_no_end kflag_no_end_head() { atf_set "descr" "Tests the -k flag with a field without end" } kflag_no_end_body() { cat >in <out <in1 <in2 <out <in <in <out <in <expout <in <expout <in <expout <in <expout <in <out <in1 <in2 <out <in <in <in <out <in <out <out <out <in <expout <in <expout <in <expout <in <expout <./+0 atf_check -o file:+0 sort -- +0 } atf_test_case plus_nonmonotone plus_nonmonotone_head() { atf_set "descr" "Tests += addressing: apparently nonmonotone field" \ "specs" } plus_nonmonotone_body() { cat >in <./+0 echo 'more contents' >in cat ./+0 in >expout atf_check -o file:expout sort in +0 } atf_test_case plus_bad_tempfile plus_bad_tempfile_head() { atf_set "descr" "Tests +- addressing: intermediate wrong behavior" \ "that raised a '+0: No such file or directory' error" } plus_bad_tempfile_body() { echo 'good contents' >in atf_check -o file:in sort -T /tmp +0 in } atf_test_case plus_rflag_invalid plus_rflag_invalid_head() { atf_set "descr" "Tests +- addressing: invalid record delimiter" } plus_rflag_invalid_body() { + atf_expect_fail "-R flag not available on FreeBSD" + ( echo 'z b m f' echo 'y c o e' echo 'x a n h' echo 'x a n g' ) | tr '\n' '+' >in atf_check -o inline:'x a n g+x a n h+z b m f+y c o e+' \ sort -R + -k2 in } atf_test_case plus_tflag plus_tflag_head() { atf_set "descr" "Tests +- addressing: using -T caused a 'No such file" \ "or directory' error" } plus_tflag_body() { mkdir ./+ yes | sed 200000q | sort -T + >/dev/null || atf_fail "program failed" } atf_test_case plus_no_end plus_no_end_head() { atf_set "descr" "Tests +- addressing: field without end" } plus_no_end_body() { cat >in <out <