[BACK]Return to t_sort.sh CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / tests / util

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/tests/util/Attic/t_sort.sh between version 1.3 and 1.4

version 1.3, 2010/06/12 13:15:54 version 1.4, 2010/07/18 22:58:14
Line 25 
Line 25 
 # POSSIBILITY OF SUCH DAMAGE.  # POSSIBILITY OF SUCH DAMAGE.
 #  #
   
 # the implementation of "sort" to test  
 : ${TEST_SORT:="sort"}  
   
   
 atf_test_case basic  atf_test_case basic
 basic_head()  basic_head()
 {  {
         atf_set "descr" "basic functionality test"          atf_set "descr" "Basic functionality test"
         atf_set "use.fs" "true"          atf_set "use.fs" "true"
 }  }
   
 basic_body()  basic_body()
 {  {
         echo 'z b m f' > in          cat >in <<EOF
         echo 'y c o e' >> in  z b m f
         echo 'x a n h' >> in  y c o e
         echo 'x a n g' >> in  x a n h
   x a n g
         echo "----- test: sort -----"  EOF
         $TEST_SORT in > out || atf_fail "program failed"  
         if [ "$(tr < out -d ' \n')" != "xangxanhycoezbmf" ]; then          cat >expout <<EOF
             atf_fail "output is wrong"  x a n g
         fi  x a n h
   y c o e
         echo "----- test: sort -r -----"  z b m f
         $TEST_SORT -r in > out || atf_fail "program failed"  EOF
         if [ "$(tr < out -d ' \n')" != "zbmfycoexanhxang" ]; then  
             atf_fail "output is wrong"          atf_check -s exit:0 -o file:expout sort in
         fi  }
   
         echo "----- test: sort -k2.1 -----"  atf_test_case rflag
         $TEST_SORT -k2.1 in > out || atf_fail "program failed"  rflag_head()
         if [ "$(tr < out -d ' \n')" != "xangxanhzbmfycoe" ]; then  {
             atf_fail "output is wrong"          atf_set "descr" "Tests the -r flag"
         fi          atf_set "use.fs" "true"
   }
         echo "----- test: sort -k2.1,2.0 -----"  
         $TEST_SORT -k2.1,2.0 in > out || atf_fail "program failed"  rflag_body()
         if [ "$(tr < out -d ' \n')" != "xanhxangzbmfycoe" ]; then  {
             atf_fail "output is wrong"          cat >in <<EOF
         fi  z b m f
   y c o e
         rm -f in  x a n h
   x a n g
         echo '1' > in  EOF
         echo '123' >> in  
         echo '2' >> in          cat >expout <<EOF
   z b m f
         echo "----- test: sort -n -----"  y c o e
         $TEST_SORT -n in > out || atf_fail "program failed"  x a n h
         if [ "$(tr < out '\n' ' ')" != "1 2 123 " ]; then  x a n g
             atf_fail "output is wrong"  EOF
         fi  
           atf_check -s exit:0 -o file:expout sort -r in
         echo "----- test: sort -rn -----"  }
         $TEST_SORT -rn in > out || atf_fail "program failed"  
         if [ "$(tr < out '\n' ' ')" != "123 2 1 " ]; then  atf_test_case kflag_one_field
             atf_fail "output is wrong"  kflag_one_field_head()
         fi  {
           atf_set "descr" "Tests the -k flag with one field"
         rm -f in          atf_set "use.fs" "true"
   }
         echo 'a' > in  
         echo 'aa' >> in  kflag_one_field_body()
         echo 'aaa' >> in  {
         echo 'aa' >> in          cat >in <<EOF
   z b m f
         echo "----- test: sort -u -----"  y c o e
         $TEST_SORT -u in > out || atf_fail "program failed"  x a n h
         if [ "$(tr < out '\n' ' ')" != "a aa aaa " ]; then  x a n g
             atf_fail "output is wrong"  EOF
         fi  
           cat >expout <<EOF
         echo "----- test: sort -ru -----"  x a n g
         $TEST_SORT -ru in > out || atf_fail "program failed"  x a n h
         if [ "$(tr < out '\n' ' ')" != "aaa aa a " ]; then  z b m f
             atf_fail "output is wrong"  y c o e
         fi  EOF
   
         rm -f in          atf_check -s exit:0 -o file:expout sort -k2.1 in
 }  }
   
 atf_test_case plusopts  atf_test_case kflag_two_fields
 plusopts_head()  kflag_two_fields_head()
 {  {
         atf_set "descr" "Checks translations of +n [-n] options"          atf_set "descr" "Tests the -k flag with two fields"
         atf_set "use.fs" "true"          atf_set "use.fs" "true"
 }  }
 plusopts_body()  
 {  kflag_two_fields_body()
         # +1 should become -k2.1  {
         # +1 -2 should become -k2.1,2.0          cat >in <<EOF
         echo 'z b m f' > in  z b m f
         echo 'y c o e' >> in  y c o e
         echo 'x a n h' >> in  x a n h
         echo 'x a n g' >> in  x a n g
         echo "----- test: sort +1 in -----"  EOF
         $TEST_SORT +1 in > out || atf_fail "program failed"  
         if [ "$(tr < out -d ' \n')" != "xangxanhzbmfycoe" ]; then          cat >expout <<EOF
             atf_fail "output is wrong"  x a n h
         fi  x a n g
         echo "----- test: sort +1 -2 in -----"  z b m f
         $TEST_SORT +1 -2 in > out || atf_fail "program failed"  y c o e
         if [ "$(tr < out -d ' \n')" != "xanhxangzbmfycoe" ]; then  EOF
             atf_fail "output is wrong"          atf_check -s exit:0 -o file:expout sort -k2.1,2.0 in
         fi  }
         rm -f in  
   atf_test_case nflag
         # old wrong behavior: sort: -k1.1: No such file or directory  nflag_head()
         echo "----- test: sort -- +0 -----"  {
         echo 'good contents' > ./+0          atf_set "descr" "Tests the -n flag"
         $TEST_SORT -- +0 > out || atf_fail "program failed"          atf_set "use.fs" "true"
         diff -Nru -- ./+0 out || atf_fail "output is wrong"  }
         rm -f ./+0  
   nflag_body()
         # old wrong behavior: sort: -k1.1: No such file or directory  {
         echo "----- test: sort in +0 -----"          cat >in <<EOF
         echo 'good contents' > ./+0  1
         echo 'more contents' > in  123
         cat ./+0 in > good  2
         $TEST_SORT in +0 > out || atf_fail "program failed"  EOF
         diff -Nru -- good out || atf_fail "output is wrong"  
         rm -f ./+0 in good          cat >expout <<EOF
   1
         # old behavior: success  2
         # intermediate wrong behavior: sort: +0: No such file or directory  123
         echo "----- test: sort -T /tmp +0 in -----"  EOF
         echo 'good contents' > in  
         $TEST_SORT -T /tmp +0 in > out || atf_fail "program failed"          atf_check -s exit:0 -o file:expout sort -n in
         diff -Nru -- in out || atf_fail "output is wrong"  }
         rm -f 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  nflag_rflag_body()
         echo "----- test: sort -R + in -----"  {
           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 'z b m f'
             echo 'y c o e'              echo 'y c o e'
             echo 'x a n h'              echo 'x a n h'
             echo 'x a n g'              echo 'x a n g'
         ) | tr '\n' '+' > in          ) | 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  
   
         # old behavior: sort: ftmp: mkstemp("-k1.1"): No such file or directory          atf_check -s exit:0 -o inline:'x a n g+x a n h+z b m f+y c o e+' \
         echo "----- test: yes | sed 200000q | sort -T + -----"              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 ./+          mkdir ./+
         yes | sed 200000q | $TEST_SORT -T + > /dev/null \          yes | sed 200000q | sort -T + >/dev/null || atf_fail "program failed"
             || atf_fail "program failed"  
         rm -rf ./+  
 }  }
   
 atf_init_test_cases()  atf_init_test_cases()
 {  {
         atf_add_test_case basic          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
 }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

CVSweb <webmaster@jp.NetBSD.org>