blob: 294530988f7afcc364fb1343f98c9e7d7a84923d [file] [log] [blame]
Rob Landley16890752005-09-02 00:41:53 +00001#!/bin/sh
2
3# SUSv3 compliant sort tests.
4# Copyright 2005 by Rob Landley <rob@landley.net>
5# Licensed under GPL v2, see file LICENSE for details.
6
7if [ ${#COMMAND} -eq 0 ]; then COMMAND=sort; fi
8. testing.sh
9
Rob Landley16890752005-09-02 00:41:53 +000010# The basic tests. These should work even with the small busybox.
11
12testing "sort" "input" "a\nb\nc\n" "c\na\nb\n" ""
13testing "sort #2" "input" "010\n1\n3\n" "3\n1\n010\n" ""
14testing "sort stdin" "" "a\nb\nc\n" "" "b\na\nc\n"
15testing "sort numeric" "-n input" "1\n3\n010\n" "3\n1\n010\n" ""
16testing "sort reverse" "-r input" "wook\nwalrus\npoint\npabst\naargh\n" \
17 "point\nwook\npabst\naargh\nwalrus\n" ""
18
19# These tests require the full option set.
20
Rob Landley48c61572005-11-07 08:50:53 +000021optional FEATURE_SORT_BIG
Rob Landley16890752005-09-02 00:41:53 +000022# Longish chunk of data re-used by the next few tests
23
24data="42 1 3 woot
2542 1 010 zoology
26egg 1 2 papyrus
277 3 42 soup
28999 3 0 algebra
29"
30
31# Sorting with keys
32
33testing "sort one key" "-k4,4 input" \
34"999 3 0 algebra
35egg 1 2 papyrus
367 3 42 soup
3742 1 3 woot
3842 1 010 zoology
39" "$data" ""
40
41testing "sort key range with numeric option" "-k2,3n input" \
42"42 1 010 zoology
4342 1 3 woot
44egg 1 2 papyrus
457 3 42 soup
46999 3 0 algebra
47" "$data" ""
48
Rob Landley48c61572005-11-07 08:50:53 +000049# Busybox is definitely doing this one wrong just now. FIXME
Rob Landley16890752005-09-02 00:41:53 +000050
51testing "sort key range with numeric option and global reverse" \
52"-k2,3n -r input" \
53"egg 1 2 papyrus
5442 1 3 woot
5542 1 010 zoology
56999 3 0 algebra
577 3 42 soup
58" "$data" ""
59
60#
61
62testing "sort key range with multiple options" "-k2,3rn input" \
63"7 3 42 soup
64999 3 0 algebra
6542 1 010 zoology
6642 1 3 woot
67egg 1 2 papyrus
68" "$data" ""
69
70exit $FAILCOUNT