Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/util Refactor this test program: make test cases more ...
details: https://anonhg.NetBSD.org/src/rev/67a75af52380
branches: trunk
changeset: 756468:67a75af52380
user: jmmv <jmmv%NetBSD.org@localhost>
date: Sun Jul 18 22:58:14 2010 +0000
description:
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.
diffstat:
tests/util/t_sort.sh | 419 ++++++++++++++++++++++++++++++++++++--------------
1 files changed, 302 insertions(+), 117 deletions(-)
diffs (truncated from 473 to 300 lines):
diff -r cd311bd14d14 -r 67a75af52380 tests/util/t_sort.sh
--- a/tests/util/t_sort.sh Sun Jul 18 22:30:55 2010 +0000
+++ b/tests/util/t_sort.sh Sun Jul 18 22:58:14 2010 +0000
@@ -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
+ 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
- echo "----- test: sort -----"
- $TEST_SORT in > out || atf_fail "program failed"
- if [ "$(tr < out -d ' \n')" != "xangxanhycoezbmf" ]; then
- atf_fail "output is wrong"
- fi
+ 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
- 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
+ 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"
+}
- 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
+kflag_one_field_body()
+{
+ cat >in <<EOF
+z b m f
+y c o e
+x a n h
+x a n g
+EOF
- 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
+ cat >expout <<EOF
+x a n g
+x a n h
+z b m f
+y c o e
+EOF
- rm -f in
+ atf_check -s exit:0 -o file:expout sort -k2.1 in
+}
- echo '1' > in
- echo '123' >> in
- echo '2' >> 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
- 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
+ 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
+}
- 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
+atf_test_case nflag
+nflag_head()
+{
+ atf_set "descr" "Tests the -n flag"
+ atf_set "use.fs" "true"
+}
- echo 'a' > in
- echo 'aa' >> in
- echo 'aaa' >> in
- echo 'aa' >> in
+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
+}
- 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
+atf_test_case nflag_rflag
+nflag_rflag_head()
+{
+ atf_set "descr" "Tests the -n and -r flag combination"
+ atf_set "use.fs" "true"
+}
- 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
+nflag_rflag_body()
+{
+ cat >in <<EOF
+1
+123
+2
+EOF
- rm -f in
+ cat >expout <<EOF
+123
+2
+1
+EOF
+
+ atf_check -s exit:0 -o file:expout sort -rn in
}
-atf_test_case plusopts
-plusopts_head()
+atf_test_case uflag
+uflag_head()
+{
+ atf_set "descr" "Tests the -u flag"
+ atf_set "use.fs" "true"
+}
+
+uflag_body()
{
- atf_set "descr" "Checks translations of +n [-n] options"
+ 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"
}
-plusopts_body()
+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
+
Home |
Main Index |
Thread Index |
Old Index