2006-06-16 02:20:38 +05:30
|
|
|
#!/bin/bash
|
2005-09-02 06:11:53 +05:30
|
|
|
|
|
|
|
# SUSv3 compliant sort tests.
|
|
|
|
# Copyright 2005 by Rob Landley <rob@landley.net>
|
|
|
|
# Licensed under GPL v2, see file LICENSE for details.
|
|
|
|
|
|
|
|
. testing.sh
|
|
|
|
|
|
|
|
# The basic tests. These should work even with the small busybox.
|
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "sort" "sort input" "a\nb\nc\n" "c\na\nb\n" ""
|
|
|
|
testing "sort #2" "sort input" "010\n1\n3\n" "3\n1\n010\n" ""
|
|
|
|
testing "sort stdin" "sort" "a\nb\nc\n" "" "b\na\nc\n"
|
|
|
|
testing "sort numeric" "sort -n input" "1\n3\n010\n" "3\n1\n010\n" ""
|
|
|
|
testing "sort reverse" "sort -r input" "wook\nwalrus\npoint\npabst\naargh\n" \
|
2005-09-02 06:11:53 +05:30
|
|
|
"point\nwook\npabst\naargh\nwalrus\n" ""
|
|
|
|
|
|
|
|
# These tests require the full option set.
|
|
|
|
|
2005-11-07 14:20:53 +05:30
|
|
|
optional FEATURE_SORT_BIG
|
2005-09-02 06:11:53 +05:30
|
|
|
# Longish chunk of data re-used by the next few tests
|
|
|
|
|
|
|
|
data="42 1 3 woot
|
|
|
|
42 1 010 zoology
|
|
|
|
egg 1 2 papyrus
|
|
|
|
7 3 42 soup
|
|
|
|
999 3 0 algebra
|
|
|
|
"
|
|
|
|
|
|
|
|
# Sorting with keys
|
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "sort one key" "sort -k4,4 input" \
|
2005-09-02 06:11:53 +05:30
|
|
|
"999 3 0 algebra
|
|
|
|
egg 1 2 papyrus
|
|
|
|
7 3 42 soup
|
|
|
|
42 1 3 woot
|
|
|
|
42 1 010 zoology
|
|
|
|
" "$data" ""
|
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "sort key range with numeric option" "sort -k2,3n input" \
|
2005-09-02 06:11:53 +05:30
|
|
|
"42 1 010 zoology
|
|
|
|
42 1 3 woot
|
|
|
|
egg 1 2 papyrus
|
|
|
|
7 3 42 soup
|
|
|
|
999 3 0 algebra
|
|
|
|
" "$data" ""
|
|
|
|
|
2005-11-07 14:20:53 +05:30
|
|
|
# Busybox is definitely doing this one wrong just now. FIXME
|
2005-09-02 06:11:53 +05:30
|
|
|
|
|
|
|
testing "sort key range with numeric option and global reverse" \
|
2006-03-16 20:50:45 +05:30
|
|
|
"sort -k2,3n -r input" \
|
2005-09-02 06:11:53 +05:30
|
|
|
"egg 1 2 papyrus
|
|
|
|
42 1 3 woot
|
|
|
|
42 1 010 zoology
|
|
|
|
999 3 0 algebra
|
|
|
|
7 3 42 soup
|
|
|
|
" "$data" ""
|
|
|
|
|
|
|
|
#
|
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "sort key range with multiple options" "sort -k2,3rn input" \
|
2005-09-02 06:11:53 +05:30
|
|
|
"7 3 42 soup
|
|
|
|
999 3 0 algebra
|
|
|
|
42 1 010 zoology
|
|
|
|
42 1 3 woot
|
|
|
|
egg 1 2 papyrus
|
|
|
|
" "$data" ""
|
|
|
|
|
2006-06-16 02:20:38 +05:30
|
|
|
testing "sort key doesn't strip leading blanks, disables fallback global sort" \
|
|
|
|
"sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n"
|
|
|
|
|
|
|
|
testing "sort key edge case with -t" "sort -n -k4 -t/" \
|
|
|
|
"/usr/lib/finish-install.d/1
|
|
|
|
/usr/lib/finish-install.d/4
|
|
|
|
/usr/lib/prebaseconfig.d/2
|
|
|
|
/usr/lib/prebaseconfig.d/6
|
|
|
|
" "" "/usr/lib/finish-install.d/1
|
|
|
|
/usr/lib/prebaseconfig.d/2
|
|
|
|
/usr/lib/finish-install.d/4
|
|
|
|
/usr/lib/prebaseconfig.d/6
|
|
|
|
"
|
|
|
|
|
2005-09-02 06:11:53 +05:30
|
|
|
exit $FAILCOUNT
|