xref: /csrg-svn/contrib/sort/TEST/stests (revision 62246)
1*62246Sbostic#	@(#)stests	8.1 (Berkeley) 06/06/93
260915Sbostic
360915Sbostic#Latest version.  My sort passes all tests because I wrote it.
460915Sbostic#We differ only on 25E and 25H.
560915Sbostic#(I found at least one bug in constructing test 25, and was driven
660915Sbostic#to rewrite field parsing to clarify it.)
760915Sbostic#
860915Sbostic#In 25E, -k2.3,2.1b, the fields are not necessarily out of order.
960915Sbostic#Even if they were, it would be legal (11752-3), although certainly
1060915Sbostic#justification for warning.
1160915Sbostic#
1260915Sbostic#On 25H, your answer is as defensible as mine.  (Our suggestion
1360915Sbostic#*1 backs mine.)
1460915Sbostic
1560915Sbostic
1660915Sbostic# Tests for the Unix sort utility
1760915Sbostic# Test Posix features except for locale.
1860915Sbostic# Test some nonstandard features if present.
1960915Sbostic
2060915Sbostic# Other tests should be made for files too big to fit in memory.
2160915Sbostic
2260915Sbostic
2360915Sbostic# Initialize switches for nonstandard features.
2460915Sbostic# Use parenthesized settings for supported features.
2560915Sbostic
2660915Sbostico=:	# officially obsolescent features: +1 -2, misplaced -o (o=)
2760915Sbosticg=:	# -g numeric sort including e-format numbers (g=)
2860915SbosticM=:	# -M sort by month names (M=)
2960915Sbostics=:	# -s stable, do not compare raw bytes on equal keys (s=)
3060915Sbosticy=	# -y user-specified memory size (y=-y10000)
3160915Sbostic
3260915Sbostic# Detect what features are supported, assuming bad options cause
3360915Sbostic# errors.  Set switches accordingly.
3460915Sbostic
3560915Sbosticecho obsolescent and nonstandard features recognized, if any:
3660915Sbosticif sort +0 </dev/null 2>/dev/null; then o=
3760915Sbostic				echo '	+1 -2'; fi
3860915Sbosticif sort /dev/null -o xx 2>/dev/null; then o=
3960915Sbostic				echo '	displaced -o'; fi
4060915Sbosticif sort -g </dev/null 2>/dev/null; then g=
4160915Sbostic				echo '	-g g-format numbers'; fi
4260915Sbosticif sort -M </dev/null 2>/dev/null; then M=
4360915Sbostic				echo '	-M months'; fi
4460915Sbosticif sort -s </dev/null 2>/dev/null; then s=
4560915Sbostic				echo '	-s stable'; fi
4660915Sbosticif sort -y10000 </dev/null 2>/dev/null; then y=-y10000
4760915Sbostic				echo '	-y space'; fi
4860915Sbosticif sort -z10000 </dev/null 2>/dev/null; then
4960915Sbostic				echo '	-z size (not exercised)'; fi
5060915Sbosticif sort -T. </dev/null 2>/dev/null; then
5160915Sbostic				echo '	-T tempdir (not exercised)'; fi
5260915Sbostic
5360915Sbostic
5460915Sbosticexport TEST	# major sequence number of test
5560915Sbostic
5660915Sbostictrap "rm -f in in1 out xx -k xsort linecount fields; exit" 0 1 2 13 15
5760915Sbostic
5860915Sbostic# xsort testno options
5960915Sbostic# Sort file "in" with specified options.
6060915Sbostic# Compare with file "out" if that is supplied,
6160915Sbostic# otherwise make plausibility checks on output
6260915Sbostic
6360915Sbostic#	"sum" must be dumb; insensitive to the
6460915Sbostic#	order of lines within a file.
6560915Sbostic#	System V sum is suitable; sum -5 is the v10 equivalent.
6660915Sbostic
6760936SbosticPATH=.:$PATH
6860936Sbosticexport PATH
6960915Sbosticcat <<'!' >xsort; chmod +x xsort
7060915Sbostic
7160915Sbostic	X=$1; shift
7260915Sbostic
7360915Sbostic	if sort "$@" in >xx  &&  sort -c "$@" xx
7460915Sbostic	then
7560915Sbostic		if test -f out
7660915Sbostic		then
7760915Sbostic			cmp xx out >/dev/null && exit 0
7860915Sbostic			echo $TEST$X comparison failed
7960915Sbostic		else
8061472Sbostic			test "`cksum -o2 <in`" = "`cksum -o2 <xx`" && exit 0
8160915Sbostic			echo $TEST$X checksum failed
8260915Sbostic		fi
8360915Sbostic	else
8460915Sbostic		echo $TEST$X failed
8560915Sbostic	fi
8660915Sbostic	exit 1
8760915Sbostic!
8860915Sbostic
8960915Sbostic# linecount testno file count
9060915Sbostic# declares the given "testno" to be in error if number of
9160915Sbostic# lines in "file" differs from "count"
9260915Sbostic
9360915Sbosticcat <<'!' >linecount; chmod +x linecount
9460915Sbosticawk 'END{ if(NR!='$3') print "'$TEST$1' failed" }' $2
9560915Sbostic!
9660915Sbostic
9760915Sbosticrm -f out
9860915Sbostic
9960915Sbostic#---------------------------------------------------------------
10060915SbosticTEST=01; echo $TEST	# -c status, checksum
10160915Sbostic			# obsolescent features go together
10260915Sbosticcat <<! >in
10360915Sbosticb
10460915Sbostica
10560915Sbostic!
10660915Sbosticrm -f out -o
10760915Sbostic
10860915Sbosticsort -c in 2>/dev/null && echo ${TEST}A failed
10960915Sbostic
11060915Sbosticxsort B || '"cksum"' is probably unsuitable - see comments
11160915Sbostic
11260915Sbostic$o sort +0 in -o in || echo ${TEST}c failed
11360915Sbostic
11460915Sbostic#---------------------------------------------------------------
11560915SbosticTEST=02; echo $TEST	# output from -c
11660915Sbosticcat <<! >in
11760915Sbosticx
11860915Sbosticy
11960915Sbostic!
12060915Sbostic
12160915Sbosticsort -cr in >out 2>xx && echo ${TEST}A failed
12260915Sbostictest -s out && echo ${TEST}B failed
12360915Sbostictest -s xx && echo option -c is noisy "(probably legal)"
12460915Sbostictest -s xx || echo option -c is quiet "(legal, not classical)"
12560915Sbostic
12660915Sbostic#---------------------------------------------------------------
12760915SbosticTEST=03; echo $TEST	# -n
12860915Sbosticcat <<! >in
12960915Sbostic-99.0
13060915Sbostic-99.1
13160915Sbostic-.0002
13260915Sbostic-10
13360915Sbostic2
13460915Sbostic0010.000000000000000000000000000000000001
13560915Sbostic10
13660915Sbostic3x
13760915Sbosticx
13860915Sbostic!
13960915Sbosticcat <<! >out
14060915Sbostic-99.1
14160915Sbostic-99.0
14260915Sbostic-10
14360915Sbostic-.0002
14460915Sbosticx
14560915Sbostic2
14660915Sbostic3x
14760915Sbostic10
14860915Sbostic0010.000000000000000000000000000000000001
14960915Sbostic!
15060915Sbostic
15160915Sbosticxsort "" -n
15260915Sbostic
15360915Sbostic#---------------------------------------------------------------
15460915SbosticTEST=04; echo $TEST	# -b without fields, piping, -c status return
15560915Sbosticcat <<! >in
15660915Sbostic  b
15760915Sbostic a
15860915Sbostic!
15960915Sbosticcp in out
16060915Sbostic
16160915Sbosticxsort A -b
16260915Sbostic
16360915Sbosticcat in | sort | cat >xx
16460915Sbosticcmp xx out >/dev/null || echo ${TEST}B failed
16560915Sbostic
16660915Sbosticsort in | sort -cr 2>/dev/null && echo ${TEST}C failed
16760915Sbostic
16860915Sbostic#---------------------------------------------------------------
16960915SbosticTEST=05; echo $TEST	# fields, reverse fields, -c status return
17060915Sbosticcat <<! >in
17160915Sbosticb b p
17260915Sbostica b q
17360915Sbosticx a
17460915Sbostic!
17560915Sbosticcat <<! >out
17660915Sbosticx a
17760915Sbostica b q
17860915Sbosticb b p
17960915Sbostic!
18060915Sbostic
18160915Sbostic$o xsort A +1 -2
18260915Sbostic
18360915Sbostic$o xsort B +1 -2 +2r
18460915Sbostic
18560915Sbosticxsort C -k 2,2
18660915Sbostic
18760915Sbosticxsort D -k 2,2 -k 3r
18860915Sbostic
18960915Sbosticxsort E -k 2,2.0
19060915Sbostic
19160915Sbosticxsort F -k 2,2 -k 1,1 -k 3
19260915Sbostic
19360915Sbosticsort -c -k 2 in 2>/dev/null && ${TEST}G failed
19460915Sbostic
19560915Sbostic#---------------------------------------------------------------
19660915SbosticTEST=06; echo $TEST	# -t
19760915Sbosticcat <<! >in
19860915Sbostica:
19960915Sbostica!
20060915Sbostic!
20160915Sbosticcp in out
20260915Sbostic
20360915Sbostic$o xsort A -t : -r +0
20460915Sbostic
20560915Sbostic$o xsort B -t : +0 -1
20660915Sbostic
20760915Sbosticxsort C -t : -r -k 1
20860915Sbostic
20960915Sbosticxsort D -t : -k 1,1
21060915Sbostic
21160915Sbostic#---------------------------------------------------------------
21260915SbosticTEST=07; echo $TEST	# -t, character positions in fields
21360915Sbostic	# -t: as 1 arg is not strictly conforming, but classical
21460915Sbosticcat <<! >in
21560915Sbostic: ab
21660915Sbostic:bac
21760915Sbostic!
21860915Sbosticcat <<! >out
21960915Sbostic:bac
22060915Sbostic: ab
22160915Sbostic!
22260915Sbostic
22360915Sbostic$o xsort A -b -t: +1.1
22460915Sbostic
22560915Sbostic$o xsort B -t: +1.1r
22660915Sbostic
22760915Sbosticxsort C -b -t: -k 2.2
22860915Sbostic
22960915Sbosticxsort D -t: -k 2.2r
23060915Sbostic
23160915Sbostic#---------------------------------------------------------------
23260915SbosticTEST=08; echo $TEST	# space and tab as -t characters
23360915Sbosticcat <<! >in
23460915Sbostic b c
23560915Sbostic b	c
23660915Sbostic	b c
23760915Sbostic!
23860915Sbosticcp in out
23960915Sbostic
24060915Sbosticxsort A -t ' ' -k2,2
24160915Sbostic
24260915Sbosticxsort B -t ' ' -k2.1,2.0
24360915Sbostic
24460915Sbosticcat <<! >out
24560915Sbostic b c
24660915Sbostic	b c
24760915Sbostic b	c
24860915Sbostic!
24960915Sbostic
25060915Sbosticxsort C -t '	' -k2,2
25160915Sbostic
25260915Sbosticxsort D -t '	' -k2.1,2.0
25360915Sbostic
25460915Sbosticcat <<! >out
25560915Sbostic b	c
25660915Sbostic	b c
25760915Sbostic b c
25860915Sbostic!
25960915Sbostic
26060915Sbosticxsort E -k2
26160915Sbostic
26260915Sbosticcat <<! >out
26360915Sbostic	b c
26460915Sbostic b	c
26560915Sbostic b c
26660915Sbostic!
26760915Sbostic
26860915Sbosticxsort F -k2b
26960915Sbostic
27060915Sbostic#---------------------------------------------------------------
27160915SbosticTEST=09; echo $TEST	# alphabetic as -t character
27260915Sbosticcat <<! >in
27360915SbosticzXa
27460915SbosticyXa
27560915SbosticzXb
27660915Sbostic!
27760915Sbosticcp in out
27860915Sbostic
27960915Sbosticxsort "" -tX -k2 -k1r,1
28060915Sbostic
28160915Sbostic#---------------------------------------------------------------
28260915SbosticTEST=10; echo $TEST	# -m
28360915Sbosticcat <<! >in
28460915Sbostica
28560915Sbosticab
28660915Sbosticab
28760915Sbosticbc
28860915Sbosticca
28960915Sbostic!
29060915Sbosticcat <<! >in1
29160915SbosticZ
29260915Sbostica
29360915Sbosticaa
29460915Sbosticac
29560915Sbosticc
29660915Sbostic!
29760915Sbosticcat <<! >out
29860915SbosticZ
29960915Sbostica
30060915Sbostica
30160915Sbosticaa
30260915Sbosticab
30360915Sbosticab
30460915Sbosticac
30560915Sbosticbc
30660915Sbosticc
30760915Sbosticca
30860915Sbostic!
30960915Sbostic
31060915Sbosticsort -m in in1 >xx
31160915Sbosticcmp xx out >/dev/null || echo $TEST failed
31260915Sbostic
31360915Sbostic#---------------------------------------------------------------
31460915SbosticTEST=11; echo $TEST	# multiple files, -o overwites input, -m, -mu
31560915Sbosticcat <<! >in
31660915Sbostica
31760915Sbosticb
31860915Sbosticc
31960915Sbosticd
32060915Sbostic!
32160915Sbostic
32260915Sbosticsort -o xx     in in in in in in in in in in in in in in in in in
32360915Sbosticlinecount A xx 68
32460915Sbosticsort -o in -mu in in in in in in in in in in in in in in in in in
32560915Sbosticlinecount B in 4
32660915Sbosticsort -o in -m  in in in in in in in in in in in in in in in in in
32760915Sbostic
32860915Sbosticcmp in xx >/dev/null || echo ${TEST}C failed
32960915Sbostic
33060915Sbostic#---------------------------------------------------------------
33160915SbosticTEST=12; echo $TEST	# does -mu pick the first among equals?
33260915Sbosticcat <<! >in
33360915Sbostic3B
33460915Sbostic3b
33560915Sbostic3B2
33660915Sbostic~3B2
33760915Sbostic4.1
33860915Sbostic41
33960915Sbostic5
34060915Sbostic5.
34160915Sbostic!
34260915Sbosticcat <<! >out
34360915Sbostic3B
34460915Sbostic3B2
34560915Sbostic4.1
34660915Sbostic5
34760915Sbostic!
34860915Sbostic
34960915Sbosticxsort A -mudf || echo "(other behavior is legal, not classical)"
35060915Sbostic
35160915Sbosticxsort B -mudf -k1 || echo "(other behavior is legal, not classical)"
35260915Sbostic
35360915Sbostic#---------------------------------------------------------------
35460915SbosticTEST=13; echo $TEST	# long records (>8000 bytes, keys >16000), -r
35560915Sbosticawk '
35660915SbosticBEGIN {	x="x"
35760915Sbostic	for(i=1; i<=12; i++) x = x x
35860915Sbostic	for(i=15; i<=25; i++) print x i
35960915Sbostic}' >in
36060915Sbosticawk '
36160915SbosticBEGIN {	x="x"
36260915Sbostic	for(i=1; i<=12; i++) x = x x
36360915Sbostic	for(i=25; i>=15; i--) print x i
36460915Sbostic}' >out
36560915Sbostic
36660915Sbosticxsort A -r
36760915Sbostic
36860915Sbosticxsort B -k 1,1r -k 1
36960915Sbostic
37060915Sbostic#---------------------------------------------------------------
37160915SbosticTEST=14; echo $TEST "(3 long parts)"
37260915Sbosticawk 'BEGIN { for(i=0; i<100000; i++) print rand() }' | grep -v e >in
37360915Sbosticrm -f out
37460915Sbostic
37560915Sbosticxsort A; echo $TEST "(part A done)"
37660915Sbostic
37760915Sbosticxsort B -n; echo $TEST "(part B done)"
37860915Sbostic
37960915Sbostic# next test is unclean: xx is a hidden side-effect of xsort
38060915Sbostic
38160915Sbosticawk '
38260915Sbostic	$0 < x { print "test '${TEST}C' failed"; exit }
38360915Sbostic	$0 "" != x { print >"out"; x = $0 }
38460915Sbostic' xx
38560915Sbostic
38660915Sbosticxsort C -n -u
38760915Sbostic
38860915Sbostic#---------------------------------------------------------------
38960915SbosticTEST=15; echo $TEST "(long)"	# force intermediate files if possible
39060915Sbosticawk 'BEGIN { for(i=0; i<20000; i++) print rand() }' >in
39160915Sbosticrm -f out
39260915Sbostic
39360915Sbosticxsort A -r $y
39460915Sbostic
39560915Sbosticsort -r in | awk '$0 "x" != x { print ; x = $0 "x" }' >out
39660915Sbostic
39760915Sbosticxsort B -u -r $y
39860915Sbostic
39960915Sbostic#---------------------------------------------------------------
40060915SbosticTEST=16; echo $TEST	# -nr, -nm, file name -
40160915Sbosticawk 'BEGIN { for(i=-100; i<=100; i+=2) printf "%.10d\n", i }' >in
40260915Sbostic
40360915Sbosticawk 'BEGIN { for(i=-99; i<=100; i+=2) print i }' | sort -nr in - >xx
40460915Sbosticawk '$0+0 != 101-NR { print "'${TEST}A' failed"; exit }' xx
40560915Sbostic
40660915Sbosticawk 'BEGIN { for(i=-99; i<=100; i+=2) print i }' | sort -mn in - >xx
40760915Sbosticawk '$0+0 != -101+NR { print "'${TEST}B' failed"; exit }' xx
40860915Sbostic
40960915Sbostic#---------------------------------------------------------------
41060915SbosticTEST=17; echo $TEST	# -d, fields without end, modifier override
41160915Sbosticcat <<! >in
41260915Sbostica-B
41360915Sbostica+b
41460915Sbostica b
41560915SbosticA+b
41660915Sbostica	b
41760915Sbostic!
41860915Sbosticcat <<! >out
41960915Sbostica	b
42060915Sbostica b
42160915SbosticA+b
42260915Sbostica-B
42360915Sbostica+b
42460915Sbostic!
42560915Sbostic
42660915Sbostic$o xsort A -df +0 +0d
42760915Sbostic
42860915Sbosticxsort B -df -k 1 -k 1d
42960915Sbostic
43060915Sbostic#---------------------------------------------------------------
43160915SbosticTEST=18; echo $TEST	# -u on key only
43260915Sbosticcat <<! >in
43360915Sbostic12	y
43460915Sbostic13	z
43560915Sbostic12	x
43660915Sbostic!
43760915Sbosticcat <<! >out
43860915Sbostic12	x
43960915Sbostic12	y
44060915Sbostic13	z
44160915Sbostic!
44260915Sbostic
44360915Sbostic$o xsort A +0 -1
44460915Sbostic
44560915Sbosticxsort B -k 1,1
44660915Sbostic
44760915Sbosticsort -u -k 1,1 in >xx
44860915Sbosticlinecount C xx 2
44960915Sbostic
45060915Sbostic#---------------------------------------------------------------
45160915SbosticTEST=19; echo $TEST	# -i, -d, -f
45260915Sbosticcat <<! >xx.c
45360915Sbosticrun(i,j){ for( ; i<=j; i++) printf("%.3o %c\n",i,i); }
45460915Sbosticmain(){	run(0, 011);		/* 012=='\n' */
45560915Sbostic	run(013, 0377); }
45660915Sbostic!
45760915Sbosticcc xx.c
45860915Sbostica.out >in
45960915Sbosticcat <<! >xx.c
46060915Sbosticrun(i,j){ for( ; i<=j; i++) printf("%.3o %c\n",i,i); }
46160915Sbosticmain(){ run(0, 011);
46260915Sbostic	run(013, ' '-1);
46360915Sbostic	run(0177, 0377);
46460915Sbostic	run(' ', 0176); }
46560915Sbostic!
46660915Sbosticcc xx.c
46760915Sbostica.out >out
46860915Sbostic
46960915Sbosticxsort A -i -k 2
47060915Sbostic
47160915Sbosticcat <<! >xx.c
47260915Sbosticrun(i,j){ for( ; i<=j; i++) printf("%.3o %c\n",i,i); }
47360915Sbosticmain(){	run(0, 010);		/* 011=='\t', 012=='\n' */
47460915Sbostic	run(013, ' '-1);
47560915Sbostic	run(' '+1, '0'-1);
47660915Sbostic	run('9'+1, 'A'-1);
47760915Sbostic	run('Z'+1, 'a'-1);
47860915Sbostic	run('z'+1, 0377);
47960915Sbostic	run('\t', '\t');
48060915Sbostic	run(' ', ' ');
48160915Sbostic	run('0', '9');
48260915Sbostic	run('A', 'Z');
48360915Sbostic	run('a', 'z'); }
48460915Sbostic!
48560915Sbosticcc xx.c
48660915Sbostica.out >out
48760915Sbostic
48860915Sbosticxsort B -d -k 2
48960915Sbostic
49060915Sbosticcat <<! >xx.c
49160915Sbosticrun(i,j){ for( ; i<=j; i++) printf("%.3o %c\n",i,i); }
49260915Sbosticmain(){	int i;
49360915Sbostic	run(0, 011);
49460915Sbostic	run(013, 'A'-1);
49560915Sbostic	for(i='A'; i<='Z'; i++)
49660915Sbostic		printf("%.3o %c\n%.3o %c\n",i,i,i+040,i+040);
49760915Sbostic	run('Z'+1, 'a'-1);
49860915Sbostic	run('z'+1, 0377); }
49960915Sbostic!
50060915Sbosticcc xx.c
50160915Sbostica.out >out
50260915Sbosticrm xx.c
50360915Sbostic
50460915Sbosticxsort C -f -k 2
50560915Sbostic
50660915Sbostic#---------------------------------------------------------------
50760915SbosticTEST=20; echo $TEST	# -d, -f, -b applies only to fields
50860915Sbosticcat <<! >in
50960915Sbostic b
51060915Sbostic'C
51160915Sbostica
51260915Sbostic!
51360915Sbosticcp in out
51460915Sbostic
51560915Sbosticxsort A -d
51660915Sbostic
51760915Sbosticxsort B -f
51860915Sbostic
51960915Sbosticcat <<! >out
52060915Sbostic b
52160915Sbostica
52260915Sbostic'C
52360915Sbostic!
52460915Sbostic
52560915Sbosticxsort C -dfb
52660915Sbostic
52760915Sbostic#---------------------------------------------------------------
52860915SbosticTEST=21; echo $TEST	# behavior of null bytes
52960915Sbosticcat <<'!' >xx.c
53060915Sbosticmain() { printf("%cb\n%ca\n",0,0); }
53160915Sbostic!
53260915Sbosticcc xx.c
53360915Sbostica.out >in
53460915Sbosticsort in >xx
53560915Sbosticcmp in xx >/dev/null && echo ${TEST}A failed
53660915Sbostictest "`wc -c <in`" = "`wc -c <xx`" || echo ${TEST}B failed
53760915Sbosticrm xx.c a.out
53860915Sbostic
53960915Sbostic#---------------------------------------------------------------
54060915SbosticTEST=22; echo $TEST	# field limits
54160915Sbosticcat <<! >in
54260915Sbostica	2
54360915Sbostica	1
54460915Sbosticb	2
54560915Sbosticb	1
54660915Sbostic!
54760915Sbosticcat <<! >out
54860915Sbosticb	1
54960915Sbosticb	2
55060915Sbostica	1
55160915Sbostica	2
55260915Sbostic!
55360915Sbostic
55460915Sbosticxsort "" -r -k1,1 -k2n
55560915Sbostic
55660915Sbostic#---------------------------------------------------------------
55760915SbosticTEST=23; echo $TEST	# empty file
55860915Sbostic
55960915Sbosticsort -o xx </dev/null
56060915Sbosticcmp xx /dev/null 2>/dev/null || echo ${TEST}A failed
56160915Sbostic
56260915Sbosticsort -c </dev/null || echo ${TEST}B failed
56360915Sbostic
56460915Sbosticsort -cu </dev/null || echo ${TEST}C failed
56560915Sbostic
56660915Sbostic#---------------------------------------------------------------
56760915SbosticTEST=24; echo $TEST	# many fields
56860915Sbosticcat <<! >in
56960915Sbostic0:2:3:4:5:6:7:8:9
57060915Sbostic1:1:3:4:5:6:7:8:9
57160915Sbostic1:2:2:4:5:6:7:8:9
57260915Sbostic1:2:3:3:5:6:7:8:9
57360915Sbostic1:2:3:4:4:6:7:8:9
57460915Sbostic1:2:3:4:5:5:7:8:9
57560915Sbostic1:2:3:4:5:6:6:8:9
57660915Sbostic1:2:3:4:5:6:7:7:9
57760915Sbostic1:2:3:4:5:6:7:8:8
57860915Sbostic!
57960915Sbosticcat <<! >out
58060915Sbostic1:2:3:4:5:6:7:8:8
58160915Sbostic1:2:3:4:5:6:7:7:9
58260915Sbostic1:2:3:4:5:6:6:8:9
58360915Sbostic1:2:3:4:5:5:7:8:9
58460915Sbostic1:2:3:4:4:6:7:8:9
58560915Sbostic1:2:3:3:5:6:7:8:9
58660915Sbostic1:2:2:4:5:6:7:8:9
58760915Sbostic1:1:3:4:5:6:7:8:9
58860915Sbostic0:2:3:4:5:6:7:8:9
58960915Sbostic!
59060915Sbostic
59160915Sbosticxsort "" -t: -k9 -k8 -k7 -k6 -k5 -k4 -k3 -k2 -k1
59260915Sbostic
59360915Sbostic#---------------------------------------------------------------
59460915SbosticTEST=25; echo $TEST	# variously specified alpha fields
59560915Sbostic			# numbers give the correct orderings
59660915Sbosticcat <<! >in
59760915Sbostic01:04:19:01:16:01:21:01 a
59860915Sbostic02:03:13:15:13:19:15:02  a
59960915Sbostic03:02:07:09:07:13:09:03   a
60060915Sbostic04:01:01:03:01:07:03:04    a
60160915Sbostic05:08:20:16:17:02:20:05 aa
60260915Sbostic06:07:14:18:14:20:14:06  aa
60360915Sbostic07:06:08:10:08:14:08:07   aa
60460915Sbostic08:05:02:04:02:08:02:08    aa
60560915Sbostic09:16:22:02:22:04:24:13 b
60660915Sbostic10:15:16:20:19:22:18:14  b
60760915Sbostic11:14:10:12:10:16:12:15   b
60860915Sbostic12:13:04:06:04:10:06:16    b
60960915Sbostic13:24:24:22:24:06:22:21 bb
61060915Sbostic14:23:18:24:21:24:16:22  bb
61160915Sbostic15:22:12:14:12:18:10:23   bb
61260915Sbostic16:21:06:08:06:12:04:24    bb
61360915Sbostic17:12:21:21:18:03:19:09 ab
61460915Sbostic18:11:15:19:15:21:13:10  ab
61560915Sbostic19:10:09:11:09:15:07:11   ab
61660915Sbostic20:09:03:05:03:09:01:12    ab
61760915Sbostic21:20:23:17:23:05:23:17 ba
61860915Sbostic22:19:17:23:20:23:17:18  ba
61960915Sbostic23:18:11:13:11:17:11:19   ba
62060915Sbostic24:17:05:07:05:11:05:20    ba
62160915Sbostic!
62260915Sbosticsort -k2b -k2 in >xx &&
62360915Sbostic	sort -c -t: -k2n xx 2>/dev/null || echo ${TEST}A failed
62460915Sbosticsort -k2,2.1b -k2 in >xx &&
62560915Sbostic	sort -c -t: -k3n xx 2>/dev/null || echo ${TEST}B failed
62660915Sbosticsort -k2.3 -k2 in >xx &&
62760915Sbostic	sort -c -t: -k4n xx 2>/dev/null || echo ${TEST}C failed
62860915Sbosticsort -k2b,2.3 -k2 in >xx &&
62960915Sbostic	sort -c -t: -k5n xx 2>/dev/null || echo ${TEST}D failed
63060915Sbosticsort -k2.3,2.1b -k2 in >xx &&
63160915Sbostic	sort -c -t: -k6n xx 2>/dev/null || echo ${TEST}E failed
63260915Sbosticsort -k2,2.1b -k2r in >xx &&
63360915Sbostic	sort -c -t: -k7n xx 2>/dev/null || echo ${TEST}F failed
63460915Sbosticsort -b -k2,2 -k2 in >xx &&
63560915Sbostic	sort -c -t: -k8n xx 2>/dev/null || echo ${TEST}G failed
63660915Sbosticsort -b -k2,2b -k2 in >xx &&			# perhaps same as G
63760915Sbostic	sort -c -t: -k3n xx 2>/dev/null || echo ${TEST}H failed\
63860915Sbostic "(standard is not clear on this)"
63960915Sbostic
64060915Sbostic#---------------------------------------------------------------
64160915SbosticTEST=26; echo $TEST	# empty fields, out of bounds fields
64260915Sbosticcat <<! >in
64360915Sbostic0 5
64460915Sbostic1 4
64560915Sbostic2 3
64660915Sbostic3 2
64760915Sbostic4 1
64860915Sbostic5 0
64960915Sbostic!
65060915Sbosticcp in out
65160915Sbostic
65260915Sbosticxsort "" -k2.2,2.1 -k2.3,2.4
65360915Sbostic
65460915Sbostic#---------------------------------------------------------------
65560915SbosticTEST=27; echo $TEST	# displaced -o
65660915Sbosticrm -f out
65760915Sbostic
65860915Sbostic$o sort /dev/null -o out || $o echo ${TEST}B failed
65960915Sbostic$o test -f out || $o echo ${TEST}C failed
66060915Sbostic
66160915Sbostic#---------------------------------------------------------------
66260915SbosticTEST=28; echo $TEST	# apparently nonmonotone field specs
66360915Sbosticcat <<! >in
66460915Sbosticaaaa c
66560915Sbosticx a
66660915Sbostic0 b
66760915Sbostic!
66860915Sbosticcp in out
66960915Sbostic
67060915Sbostic$o xsort A +1 -0.3 +1.4 -1.5
67160915Sbostic
67260915Sbosticxsort B -k2,1.3 -k2.5,2.5
67360915Sbostic
67460915Sbostic#---------------------------------------------------------------
67560915SbosticTEST=29; echo $TEST	# determination of end of option list
67660915Sbosticcat >-k <<!
67760915Sbosticx
67860915Sbostic!
67960915Sbosticrm -f out -c
68060915Sbostic
68160915Sbosticsort -- -k </dev/null >xx || echo ${TEST}A argument failed
68260915Sbosticcmp xx -k || echo ${TEST}A comparison failed
68360915Sbostic
68460915Sbosticsort - -c </dev/null 2>/dev/null && echo ${TEST}B failed
68560915Sbostic
68660915Sbostic#---------------------------------------------------------------
68760915SbosticTEST=30; echo $TEST	# missing newline
68860915Sbosticawk 'BEGIN{ printf "%s", "x"}' | sort >xx
68960915Sbosticwc -c <xx | awk '$1!=2{ print "'${TEST}' failed" }'
69060915Sbostic
69160915Sbostic#---------------------------------------------------------------
69260915SbosticTEST=31; echo $TEST	# -M, multiple fields
69360915Sbosticcat <<! >in
69460915Sbosticjan 10 1900
69560915SbosticFeb 26 1900
69660915Sbosticfeb 25 1900
69760915SbosticJanuary xx 1900
69860915SbosticAugust 11 1900
69960915Sbosticjan 15 1990
70060915Sbosticfeb 22 1990
70160915Sbosticmar 15 1990
70260915Sbosticapr 1 1990
70360915Sbosticmay 45 1990
70460915Sbosticjun 14 1990
70560915Sbosticjul 4 1990
70660915Sbosticaug 1~ 1990
70760915Sbosticaug 11 1990
70860915Sbosticsep 1 1990
70960915Sbosticoct 12 1990
71060915Sbosticnov 24 1990
71160915Sbosticdec 25 1990
71260915Sbosticnever 3 1990
71360915Sbostic Dec 25 1990
71460915Sbostic!
71560915Sbosticcat <<! >out
71660915SbosticJanuary xx 1900
71760915Sbosticjan 10 1900
71860915Sbosticfeb 25 1900
71960915SbosticFeb 26 1900
72060915SbosticAugust 11 1900
72160915Sbosticnever 3 1990
72260915Sbosticjan 15 1990
72360915Sbosticfeb 22 1990
72460915Sbosticmar 15 1990
72560915Sbosticapr 1 1990
72660915Sbosticmay 45 1990
72760915Sbosticjun 14 1990
72860915Sbosticjul 4 1990
72960915Sbosticaug 1~ 1990
73060915Sbosticaug 11 1990
73160915Sbosticsep 1 1990
73260915Sbosticoct 12 1990
73360915Sbosticnov 24 1990
73460915Sbostic Dec 25 1990
73560915Sbosticdec 25 1990
73660915Sbostic!
73760915Sbostic
73860915Sbostic$M xsort "" -k3n -k1M -k2n
73960915Sbostic
74060915Sbostic#---------------------------------------------------------------
74160915SbosticTEST=32; echo $TEST	# -M case insensitivity, -r
74260915Sbosticcat <<! >in
74360915Sbosticx
74460915Sbosticjune
74560915Sbosticjanuary
74660915Sbosticdecember
74760915Sbostic!
74860915Sbosticcat <<! >out
74960915Sbosticdecember
75060915Sbosticjune
75160915Sbosticjanuary
75260915Sbosticx
75360915Sbostic!
75460915Sbostic
75560915Sbostic$M xsort "" -Mr
75660915Sbostic
75760915Sbostic#---------------------------------------------------------------
75860915SbosticTEST=33; echo $TEST	# -g
75960915Sbosticcat <<! >in
76060915Sbostic2
76160915Sbostic1
76260915Sbostic10
76360915Sbostic.2
76460915Sbostic1e
76560915Sbostic1E1
76660915Sbostic1e.
76760915Sbostic!
76860915Sbosticcat <<! >out
76960915Sbostic.2
77060915Sbostic1
77160915Sbostic1e
77260915Sbostic1e.
77360915Sbostic2
77460915Sbostic10
77560915Sbostic1E1
77660915Sbostic!
77760915Sbostic
77860915Sbostic$g xsort "" -g
77960915Sbostic
78060915Sbostic#---------------------------------------------------------------
78160915SbosticTEST=34; echo $TEST	# -g wide operands
78260915Sbosticcat <<! >in
78360915Sbostic.99999999999999999999
78460915Sbostic099999999999999999999e-21
78560915Sbostic099999999999999999999e-19
78660915Sbostic.1e1
78760915Sbostic!
78860915Sbosticcat <<! >out
78960915Sbostic099999999999999999999e-21
79060915Sbostic.99999999999999999999
79160915Sbostic.1e1
79260915Sbostic099999999999999999999e-19
79360915Sbostic!
79460915Sbostic
79560915Sbostic$g xsort A -g
79660915Sbostic
79760915Sbosticcat <<! >out
79860915Sbostic.1e1
79960915Sbostic.99999999999999999999
80060915Sbostic099999999999999999999e-19
80160915Sbostic099999999999999999999e-21
80260915Sbostic!
80360915Sbostic
80460915Sbosticxsort B -n
80560915Sbostic
80660915Sbostic#---------------------------------------------------------------
80760915SbosticTEST=35; echo $TEST	#-g, -u with different fp reps
80860915Sbosticcat <<! >in
80960915Sbostic+0
81060915Sbostic-0
81160915Sbostic0.10
81260915Sbostic+.1
81360915Sbostic-.1
81460915Sbostic-100e-3
81560915Sbosticx
81660915Sbostic!
81760915Sbosticcat <<! >out
81860915Sbostic-.1
81960915Sbostic-100e-3
82060915Sbostic+0
82160915Sbostic-0
82260915Sbosticx
82360915Sbostic+.1
82460915Sbostic0.10
82560915Sbostic!
82660915Sbostic
82760915Sbostic$g xsort A -g
82860915Sbostic
82960915Sbostic$g sort -gu in >xx && $g sort -c -gu xx || echo ${TEST}B failed
83060915Sbostic$g linecount C xx 3
83160915Sbostic
83260915Sbostic#---------------------------------------------------------------
83360915SbosticTEST=36; echo $TEST	# -s
83460915Sbosticcat <<! >in
83560915Sbostica 2
83660915Sbosticb 1
83760915Sbosticc 2
83860915Sbostica 1
83960915Sbosticb 2
84060915Sbosticc 1
84160915Sbostic!
84260915Sbosticcat <<! >out
84360915Sbostica 2
84460915Sbostica 1
84560915Sbosticb 1
84660915Sbosticb 2
84760915Sbosticc 2
84860915Sbosticc 1
84960915Sbostic!
85060915Sbostic
85160915Sbostic$s xsort "" -s -k1,1
85260915Sbostic
85360915Sbostic#---------------------------------------------------------------
85460915SbosticTEST=37; echo $TEST	# -s, multiple files
85560915Sbosticcat <<! >in
85660915Sbostica 2
85760915Sbosticc 2
85860915Sbostic!
85960915Sbosticcat <<! >in1
86060915Sbostica 1
86160915Sbosticb 1
86260915Sbosticc 1
86360915Sbostic!
86460915Sbosticcat <<! >out
86560915Sbosticc 2
86660915Sbosticb 1
86760915Sbostica 2
86860915Sbostic!
86960915Sbostic
87060915Sbostic$s sort -smru -k1,1 in in in1 in1 >xx
87160915Sbostic$s cmp xx out >/dev/null || echo $TEST failed
87260915Sbostic
87360915Sbostic#---------------------------------------------------------------
87460915SbosticTEST=38; echo $TEST	# -s
87560915Sbostic$s awk '
87660915Sbostic	BEGIN {
87760915Sbostic		for(i=1; i<50; i++)
87860915Sbostic			for(j=1; j<=i; j++) {
87960915Sbostic				print i, 2 >"in"
88060915Sbostic				print i, 1 >"in1"
88160915Sbostic			}
88260915Sbostic	}'
88360915Sbostic
88460915Sbostic$s sort -m -s -k1,1n in in1 >out
88560915Sbostic
88660915Sbostic$s awk '
88760915Sbostic	func stop()	{ print "'$TEST' failed"; exit }
88860915Sbostic	$1!=last1 	{ if(count!=last1 || $2!=2) stop();
88960915Sbostic			  count = 0}
89060915Sbostic	$1==last1 && $2!=last2 { if(count!=last1 || $2!=1) stop();
89160915Sbostic				 count = 0 }
89260915Sbostic			{ count++; last1 = $1; last2 = $2 }
89360915Sbostic	' out
894