blob: 1db7870d4b94e61037883f33dcff74fc92915a3e [file] [log] [blame]
Rob Landley39218932006-06-15 20:50:38 +00001#!/bin/bash
Rob Landley16890752005-09-02 00:41:53 +00002
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
Rob Landley16890752005-09-02 00:41:53 +00007. testing.sh
8
Rob Landley16890752005-09-02 00:41:53 +00009# The basic tests. These should work even with the small busybox.
10
Rob Landley4bb1b042006-03-16 15:20:45 +000011testing "sort" "sort input" "a\nb\nc\n" "c\na\nb\n" ""
12testing "sort #2" "sort input" "010\n1\n3\n" "3\n1\n010\n" ""
13testing "sort stdin" "sort" "a\nb\nc\n" "" "b\na\nc\n"
14testing "sort numeric" "sort -n input" "1\n3\n010\n" "3\n1\n010\n" ""
15testing "sort reverse" "sort -r input" "wook\nwalrus\npoint\npabst\naargh\n" \
Rob Landley16890752005-09-02 00:41:53 +000016 "point\nwook\npabst\naargh\nwalrus\n" ""
17
18# These tests require the full option set.
19
Rob Landley48c61572005-11-07 08:50:53 +000020optional FEATURE_SORT_BIG
Rob Landley16890752005-09-02 00:41:53 +000021# Longish chunk of data re-used by the next few tests
22
23data="42 1 3 woot
2442 1 010 zoology
25egg 1 2 papyrus
267 3 42 soup
27999 3 0 algebra
28"
29
30# Sorting with keys
31
Rob Landley4bb1b042006-03-16 15:20:45 +000032testing "sort one key" "sort -k4,4 input" \
Rob Landley16890752005-09-02 00:41:53 +000033"999 3 0 algebra
34egg 1 2 papyrus
357 3 42 soup
3642 1 3 woot
3742 1 010 zoology
38" "$data" ""
39
Rob Landley4bb1b042006-03-16 15:20:45 +000040testing "sort key range with numeric option" "sort -k2,3n input" \
Rob Landley16890752005-09-02 00:41:53 +000041"42 1 010 zoology
4242 1 3 woot
43egg 1 2 papyrus
447 3 42 soup
45999 3 0 algebra
46" "$data" ""
47
Rob Landley48c61572005-11-07 08:50:53 +000048# Busybox is definitely doing this one wrong just now. FIXME
Rob Landley16890752005-09-02 00:41:53 +000049
50testing "sort key range with numeric option and global reverse" \
Rob Landley4bb1b042006-03-16 15:20:45 +000051"sort -k2,3n -r input" \
Rob Landley16890752005-09-02 00:41:53 +000052"egg 1 2 papyrus
5342 1 3 woot
5442 1 010 zoology
55999 3 0 algebra
567 3 42 soup
57" "$data" ""
58
Denis Vlasenko9213a9e2006-09-17 16:28:10 +000059#
Rob Landley16890752005-09-02 00:41:53 +000060
Rob Landley4bb1b042006-03-16 15:20:45 +000061testing "sort key range with multiple options" "sort -k2,3rn input" \
Rob Landley16890752005-09-02 00:41:53 +000062"7 3 42 soup
63999 3 0 algebra
6442 1 010 zoology
6542 1 3 woot
66egg 1 2 papyrus
67" "$data" ""
68
Denis Vlasenko54cf5112007-02-17 18:11:45 +000069testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\
70d 2
71b 2
72c 3
73" "\
74c 3
75b 2
76d 2
77" ""
78
Denis Vlasenko8336f082007-01-07 00:21:41 +000079testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\
80/a/2
81/b/1
82" "\
83/a/2
84/b/1
85" ""
86
87testing "sort with non-default leading delim 2" "sort -n -k3 -t/ input" "\
88/b/1
89/a/2
90" "\
91/b/1
92/a/2
93" ""
94
95testing "sort with non-default leading delim 3" "sort -n -k3 -t/ input" "\
96//a/2
97//b/1
98" "\
99//a/2
100//b/1
101" ""
102
103testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\
104a c
105" "\
106a c
107b c
108" ""
109
Rob Landley39218932006-06-15 20:50:38 +0000110testing "sort key doesn't strip leading blanks, disables fallback global sort" \
Denis Vlasenko9213a9e2006-09-17 16:28:10 +0000111"sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n"
Rob Landley39218932006-06-15 20:50:38 +0000112
Rob Landley16890752005-09-02 00:41:53 +0000113exit $FAILCOUNT