busybox/testsuite/sort.tests
Rob Landley 48c6157eb9 Fix the test suite so that individual *.tests files can be run ala
COMMAND=sort ./sort.tests
So we can compare against non-busybox versions, and possibly our testsuite
will be useful to somebody like the Linux Test Project someday.

Redid testing.sh to add new command, "optional", to skip tests that require
certain features.  (use: `optional FEATURE_SORT_BIG`, or `optional ""` to
stop skipping.)  Note that optional is a NOP if the environment variable
"OPTIONFLAGS" is blank, so although we're marking up the tests with busybox
specific knowledge, it doesn't interfere with running the tests without
busybox.

Moved setting the "OPTIONFLAGS" environment variable to runtest.  Philosophy:
busybox-specific stuff belongs in runtest; both testing.sh and the tests
themselves should be as busybox-agnostic as possible.

Moved detecting that a command isn't in busybox at all (hence skipping the
entire command.tests file) to runtests.  Rationale: optional can't currently
test for more than one feature at a time, so if we clear anything with
optional "" we might perform tests we don't want to.

Marked up busybox.tests to know which tests need CAT enabled.  Fixed up other
tests to be happy with new notation.

I suspect egrep should be appended to grep.  It's a sub-feature, really...
2005-11-07 08:50:53 +00:00

71 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# SUSv3 compliant sort tests.
# Copyright 2005 by Rob Landley <rob@landley.net>
# Licensed under GPL v2, see file LICENSE for details.
if [ ${#COMMAND} -eq 0 ]; then COMMAND=sort; fi
. testing.sh
# The basic tests. These should work even with the small busybox.
testing "sort" "input" "a\nb\nc\n" "c\na\nb\n" ""
testing "sort #2" "input" "010\n1\n3\n" "3\n1\n010\n" ""
testing "sort stdin" "" "a\nb\nc\n" "" "b\na\nc\n"
testing "sort numeric" "-n input" "1\n3\n010\n" "3\n1\n010\n" ""
testing "sort reverse" "-r input" "wook\nwalrus\npoint\npabst\naargh\n" \
"point\nwook\npabst\naargh\nwalrus\n" ""
# These tests require the full option set.
optional FEATURE_SORT_BIG
# 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
testing "sort one key" "-k4,4 input" \
"999 3 0 algebra
egg 1 2 papyrus
7 3 42 soup
42 1 3 woot
42 1 010 zoology
" "$data" ""
testing "sort key range with numeric option" "-k2,3n input" \
"42 1 010 zoology
42 1 3 woot
egg 1 2 papyrus
7 3 42 soup
999 3 0 algebra
" "$data" ""
# Busybox is definitely doing this one wrong just now. FIXME
testing "sort key range with numeric option and global reverse" \
"-k2,3n -r input" \
"egg 1 2 papyrus
42 1 3 woot
42 1 010 zoology
999 3 0 algebra
7 3 42 soup
" "$data" ""
#
testing "sort key range with multiple options" "-k2,3rn input" \
"7 3 42 soup
999 3 0 algebra
42 1 010 zoology
42 1 3 woot
egg 1 2 papyrus
" "$data" ""
exit $FAILCOUNT