Module Name: src Committed By: jmmv Date: Sun Jul 18 22:58:14 UTC 2010
Modified Files: src/tests/util: t_sort.sh Log Message: Refactor this test program: make test cases more granular, use atf_check to validate the execution of sort(1) and do not bother removing temporary files. This is in preparation to merge the tests for sort(1) that still live in regress/usr.bin/sort/stests. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/util/t_sort.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/util/t_sort.sh diff -u src/tests/util/t_sort.sh:1.3 src/tests/util/t_sort.sh:1.4 --- src/tests/util/t_sort.sh:1.3 Sat Jun 12 13:15:54 2010 +++ src/tests/util/t_sort.sh Sun Jul 18 22:58:14 2010 @@ -1,4 +1,4 @@ -# $NetBSD: t_sort.sh,v 1.3 2010/06/12 13:15:54 pooka Exp $ +# $NetBSD: t_sort.sh,v 1.4 2010/07/18 22:58:14 jmmv Exp $ # # Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. # All rights reserved. @@ -25,162 +25,347 @@ # POSSIBILITY OF SUCH DAMAGE. # -# the implementation of "sort" to test -: ${TEST_SORT:="sort"} - - atf_test_case basic basic_head() { - atf_set "descr" "basic functionality test" + atf_set "descr" "Basic functionality test" atf_set "use.fs" "true" } basic_body() { - echo 'z b m f' > in - echo 'y c o e' >> in - echo 'x a n h' >> in - echo 'x a n g' >> in - - echo "----- test: sort -----" - $TEST_SORT in > out || atf_fail "program failed" - if [ "$(tr < out -d ' \n')" != "xangxanhycoezbmf" ]; then - atf_fail "output is wrong" - fi - - echo "----- test: sort -r -----" - $TEST_SORT -r in > out || atf_fail "program failed" - if [ "$(tr < out -d ' \n')" != "zbmfycoexanhxang" ]; then - atf_fail "output is wrong" - fi - - echo "----- test: sort -k2.1 -----" - $TEST_SORT -k2.1 in > out || atf_fail "program failed" - if [ "$(tr < out -d ' \n')" != "xangxanhzbmfycoe" ]; then - atf_fail "output is wrong" - fi - - echo "----- test: sort -k2.1,2.0 -----" - $TEST_SORT -k2.1,2.0 in > out || atf_fail "program failed" - if [ "$(tr < out -d ' \n')" != "xanhxangzbmfycoe" ]; then - atf_fail "output is wrong" - fi - - rm -f in - - echo '1' > in - echo '123' >> in - echo '2' >> in - - echo "----- test: sort -n -----" - $TEST_SORT -n in > out || atf_fail "program failed" - if [ "$(tr < out '\n' ' ')" != "1 2 123 " ]; then - atf_fail "output is wrong" - fi - - echo "----- test: sort -rn -----" - $TEST_SORT -rn in > out || atf_fail "program failed" - if [ "$(tr < out '\n' ' ')" != "123 2 1 " ]; then - atf_fail "output is wrong" - fi - - rm -f in - - echo 'a' > in - echo 'aa' >> in - echo 'aaa' >> in - echo 'aa' >> in - - echo "----- test: sort -u -----" - $TEST_SORT -u in > out || atf_fail "program failed" - if [ "$(tr < out '\n' ' ')" != "a aa aaa " ]; then - atf_fail "output is wrong" - fi - - echo "----- test: sort -ru -----" - $TEST_SORT -ru in > out || atf_fail "program failed" - if [ "$(tr < out '\n' ' ')" != "aaa aa a " ]; then - atf_fail "output is wrong" - fi - - rm -f in -} - -atf_test_case plusopts -plusopts_head() -{ - atf_set "descr" "Checks translations of +n [-n] options" - atf_set "use.fs" "true" -} -plusopts_body() -{ - # +1 should become -k2.1 - # +1 -2 should become -k2.1,2.0 - echo 'z b m f' > in - echo 'y c o e' >> in - echo 'x a n h' >> in - echo 'x a n g' >> in - echo "----- test: sort +1 in -----" - $TEST_SORT +1 in > out || atf_fail "program failed" - if [ "$(tr < out -d ' \n')" != "xangxanhzbmfycoe" ]; then - atf_fail "output is wrong" - fi - echo "----- test: sort +1 -2 in -----" - $TEST_SORT +1 -2 in > out || atf_fail "program failed" - if [ "$(tr < out -d ' \n')" != "xanhxangzbmfycoe" ]; then - atf_fail "output is wrong" - fi - rm -f in - - # old wrong behavior: sort: -k1.1: No such file or directory - echo "----- test: sort -- +0 -----" - echo 'good contents' > ./+0 - $TEST_SORT -- +0 > out || atf_fail "program failed" - diff -Nru -- ./+0 out || atf_fail "output is wrong" - rm -f ./+0 - - # old wrong behavior: sort: -k1.1: No such file or directory - echo "----- test: sort in +0 -----" - echo 'good contents' > ./+0 - echo 'more contents' > in - cat ./+0 in > good - $TEST_SORT in +0 > out || atf_fail "program failed" - diff -Nru -- good out || atf_fail "output is wrong" - rm -f ./+0 in good - - # old behavior: success - # intermediate wrong behavior: sort: +0: No such file or directory - echo "----- test: sort -T /tmp +0 in -----" - echo 'good contents' > in - $TEST_SORT -T /tmp +0 in > out || atf_fail "program failed" - diff -Nru -- in out || atf_fail "output is wrong" - rm -f in + cat >in <<EOF +z b m f +y c o e +x a n h +x a n g +EOF + + cat >expout <<EOF +x a n g +x a n h +y c o e +z b m f +EOF + + atf_check -s exit:0 -o file:expout sort in +} + +atf_test_case rflag +rflag_head() +{ + atf_set "descr" "Tests the -r flag" + atf_set "use.fs" "true" +} + +rflag_body() +{ + cat >in <<EOF +z b m f +y c o e +x a n h +x a n g +EOF + + cat >expout <<EOF +z b m f +y c o e +x a n h +x a n g +EOF + + atf_check -s exit:0 -o file:expout sort -r in +} + +atf_test_case kflag_one_field +kflag_one_field_head() +{ + atf_set "descr" "Tests the -k flag with one field" + atf_set "use.fs" "true" +} + +kflag_one_field_body() +{ + cat >in <<EOF +z b m f +y c o e +x a n h +x a n g +EOF + + cat >expout <<EOF +x a n g +x a n h +z b m f +y c o e +EOF + + atf_check -s exit:0 -o file:expout sort -k2.1 in +} + +atf_test_case kflag_two_fields +kflag_two_fields_head() +{ + atf_set "descr" "Tests the -k flag with two fields" + atf_set "use.fs" "true" +} + +kflag_two_fields_body() +{ + cat >in <<EOF +z b m f +y c o e +x a n h +x a n g +EOF + + cat >expout <<EOF +x a n h +x a n g +z b m f +y c o e +EOF + atf_check -s exit:0 -o file:expout sort -k2.1,2.0 in +} + +atf_test_case nflag +nflag_head() +{ + atf_set "descr" "Tests the -n flag" + atf_set "use.fs" "true" +} + +nflag_body() +{ + cat >in <<EOF +1 +123 +2 +EOF + + cat >expout <<EOF +1 +2 +123 +EOF + + atf_check -s exit:0 -o file:expout sort -n in +} + +atf_test_case nflag_rflag +nflag_rflag_head() +{ + atf_set "descr" "Tests the -n and -r flag combination" + atf_set "use.fs" "true" +} - # old behavior: sort: invalid record delimiter -k1.1 - echo "----- test: sort -R + in -----" +nflag_rflag_body() +{ + cat >in <<EOF +1 +123 +2 +EOF + + cat >expout <<EOF +123 +2 +1 +EOF + + atf_check -s exit:0 -o file:expout sort -rn in +} + +atf_test_case uflag +uflag_head() +{ + atf_set "descr" "Tests the -u flag" + atf_set "use.fs" "true" +} + +uflag_body() +{ + cat >in <<EOF +a +aa +aaa +aa +EOF + + cat >expout <<EOF +a +aa +aaa +EOF + + atf_check -s exit:0 -o file:expout sort -u in +} + +atf_test_case uflag_rflag +uflag_rflag_head() +{ + atf_set "descr" "Tests the -u and -r flag combination" + atf_set "use.fs" "true" +} + +uflag_rflag_body() +{ + cat >in <<EOF +a +aa +aaa +aa +EOF + + cat >expout <<EOF +aaa +aa +a +EOF + + atf_check -s exit:0 -o file:expout sort -ru in +} + +atf_test_case plus_one +plus_one_head() +{ + atf_set "descr" "Tests +- addressing: +1 should become -k2.1" + atf_set "use.fs" "true" +} +plus_one_body() +{ + cat >in <<EOF +z b m f +y c o e +x a n h +x a n g +EOF + + cat >expout <<EOF +x a n g +x a n h +z b m f +y c o e +EOF + + atf_check -s exit:0 -o file:expout sort +1 in +} + +atf_test_case plus_one_minus_two +plus_one_minus_two_head() +{ + atf_set "descr" "Tests +- addressing: +1 -2 should become -k2.1,2.0" + atf_set "use.fs" "true" +} +plus_one_minus_two_body() +{ + cat >in <<EOF +z b m f +y c o e +x a n h +x a n g +EOF + + cat >expout <<EOF +x a n h +x a n g +z b m f +y c o e +EOF + + atf_check -s exit:0 -o file:expout sort +1 -2 in +} + +atf_test_case plus_zero +plus_zero_head() +{ + atf_set "descr" "Tests +- addressing: '-- +0' raised a '-k1.1: No" \ + "such file or directory' error" + atf_set "use.fs" "true" +} +plus_zero_body() +{ + echo 'good contents' >./+0 + + atf_check -s exit:0 -o file:+0 sort -- +0 +} + +atf_test_case plus_as_path +plus_as_path_head() +{ + atf_set "descr" "Tests +- addressing: 'file +0' raised a '-k1.1: No" \ + "such file or directory' error" + atf_set "use.fs" "true" +} +plus_as_path_body() +{ + echo 'good contents' >./+0 + echo 'more contents' >in + cat ./+0 in >expout + + atf_check -s exit:0 -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" + atf_set "use.fs" "true" +} +plus_bad_tempfile_body() +{ + echo 'good contents' >in + atf_check -s exit:0 -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" + atf_set "use.fs" "true" +} +plus_rflag_invalid_body() +{ ( echo 'z b m f' echo 'y c o e' echo 'x a n h' echo 'x a n g' - ) | tr '\n' '+' > in - $TEST_SORT -R + -k2 in > out || atf_fail "program failed" - if [ "$(tr < out -d ' +')" != "xangxanhzbmfycoe" ]; then - atf_fail "output is wrong" - fi - rm -f in + ) | tr '\n' '+' >in - # old behavior: sort: ftmp: mkstemp("-k1.1"): No such file or directory - echo "----- test: yes | sed 200000q | sort -T + -----" + atf_check -s exit:0 -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() +{ + atf_set "descr" "Tests +- addressing: using -T caused a 'No such file" \ + "or directory' error" + atf_set "use.fs" "true" +} +plus_tflag() +{ mkdir ./+ - yes | sed 200000q | $TEST_SORT -T + > /dev/null \ - || atf_fail "program failed" - rm -rf ./+ + yes | sed 200000q | sort -T + >/dev/null || atf_fail "program failed" } atf_init_test_cases() { atf_add_test_case basic - atf_add_test_case plusopts + atf_add_test_case rflag + atf_add_test_case kflag_one_field + atf_add_test_case kflag_two_fields + atf_add_test_case nflag + atf_add_test_case nflag_rflag + atf_add_test_case uflag + atf_add_test_case uflag_rflag + atf_add_test_case plus_one + atf_add_test_case plus_one_minus_two + atf_add_test_case plus_zero + atf_add_test_case plus_as_path + atf_add_test_case plus_bad_tempfile + atf_add_test_case plus_rflag_invalid + atf_add_test_case plus_tflag }