testsort.sh revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1996-2011 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# Glenn Fowler <gsf@research.att.com> #
# Phong Vo <kpv@research.att.com> #
# Doug McIlroy <doug@research.bell-labs.com> #
# #
########################################################################
# Tests for the Unix sort utility
# Test Posix features except for locale.
# Test some nonstandard features if present.
LC_ALL=C
case $# in
0) set $SORT ;;
esac
# Some intermediate file tests require ~100 fds,
# and some systems have low ~64 fds defaults.
# Other tests may be needed for files too big to fit in memory;
# see TEST=15 below
SORT=$1
shift
SORT_ARGS="$@"
'}
IFS=":"
set $path
for dir
"") continue ;;
esac
*/*) ;;
*/*) ;;
esac
fi
;;
esac
*/*) ;;
esac
*/*) ;;
then AB='abc
pdq
xyz'
BA='xyz
pdq
abc'
;;
break
;;
esac
;;
esac
done
;;
esac
fi
;;
esac
done
esac
echo " $SORT $SORT_ARGS"
echo
# All work done in local temp dir.
then cd $TMP
else echo "mkdir $TMP FAILED"
exit 1
fi
# Initialize switches for nonstandard features.
# Use parenthesized settings for supported features.
o=: # officially obsolescent features: +1 -2
O=: # really obsolescent features: displaced -o (o=)
g=: # -g numeric sort including e-format numbers (g=)
k=: # -Rr -k.p.l fixed records and fields
M=: # -M sort by month names (M=)
s=: # -s stable, do not compare raw bytes on equal keys (s=)
S=: # -S unstable, compare raw bytes on equal keys (S=)
x=: # -x method, alternate sort method (x=)
X=: # -Xtest, -Xread ensures read over memory map
y= # -y user-specified memory size (y=-y4096)
# Detect what features are supported, assuming bad options cause
# errors. Set switches accordingly.
echo ' +1 -2'; fi
echo ' displaced -o'; fi
echo ' -g g-format numbers'; fi
echo ' -Rr -k.p:l fixed length records'; fi
echo ' -M months'; fi
echo ' -s stable'; fi
echo ' -S unstable'; fi
echo ' -x method'; fi
echo ' -Xread ensures read instead of memory map'; fi
echo ' -y space'; fi
echo ' -z recsize (not exercised)'; fi
echo ' -T tempdir (not exercised)'; fi
# xsort testno options
# Sort file "in" with specified options.
# Compare with file "out" if that is supplied,
# otherwise make plausibility checks on output
case \$1 in
-) F=-; shift ;;
*) F=in ;;
esac
X=\$1; shift
then
if test -f out
then
else
fi
else
fi
exit 1
!
# ysort options
# called to check diagnostics
esac
!
# linecount testno file count
# declares the given "testno" to be in error if number of
# lines in "file" differs from "count"
!
# instability by default for the standard
case $S in
esac
# check behavior in questionable cases
echo
echo "behavior in questionable cases (other than message and exit)"
rm -f nosuchfile
if test ! -f unwritablefile
then echo x >unwritablefile
fi
do ./ysort $i
done
$g ./ysort -n -g
$M ./ysort -n -M
./ysort -d -i
./ysort -n -i
./ysort -t. -t:
do ./ysort $i
done
$g false && ./ysort -g
$s false && ./ysort -s
$z false && ./ysort -z
case "$y" in
"") ./ysort -y
esac
A b
a bc
a Bd
B
!
A b
B
a bc
a Bd
!
A b
B
a Bd
a bc
!
then
opt="-k1,1 -f -k2,2 :"
then echo " $opt -f applies to fields 1 and 2"
then echo " $opt -f applies to field 2 only"
then echo " $opt -f ineffectual"
then echo " $opt exit status zero, but no output"
else echo " $opt inexplicable"
fi
fi
# generate large data here to smooth the test feedback
echo
echo "generating large data files for tests that follow (long)"
$AWK 'BEGIN {
x = "xxxxxxxxxx"
x = x x x x x x x x
echo
# check for and loop on alternate methods
case $x in
*) set '' ;;
esac
while :
do case $# in
0) break ;;
esac
METHOD=$1
shift
continue
;;
'') echo
;;
echo
echo "testing the $METHOD method"
echo
;;
esac
#---------------------------------------------------------------
# obsolescent features go together
b
a
!
#---------------------------------------------------------------
x
y
!
#---------------------------------------------------------------
-99.0
-99.1
-.0002
-10
2
2.0x
2.0.1
0010.000000000000000000000000000000000001
10
3x
x
!
-99.1
-99.0
-10
-.0002
x
2
2.0.1
2.0x
3x
10
0010.000000000000000000000000000000000001
!
./xsort "" -n
#---------------------------------------------------------------
b
a
!
./xsort A -b
#---------------------------------------------------------------
b b p
a b q
x a
!
x a
a b q
b b p
!
#---------------------------------------------------------------
a:
a!
!
$o ./xsort A -t : -r +0
./xsort C -t : -r -k 1
#---------------------------------------------------------------
# -t: as 1 arg is not strictly conforming, but classical
: ab
:bac
!
:bac
: ab
!
$o ./xsort A -b -t: +1.1
$o ./xsort B -t: +1.1r
./xsort C -b -t: -k 2.2
./xsort D -t: -k 2.2r
#---------------------------------------------------------------
b c
b c
b c
!
b c
b c
b c
!
b c
b c
b c
!
b c
b c
b c
!
#---------------------------------------------------------------
!
#---------------------------------------------------------------
a
!
Z
a
c
!
Z
a
a
c
!
#---------------------------------------------------------------
a
b
c
d
!
#---------------------------------------------------------------
3B
3b
3B2
~3B2
4.1
41
5
5.
!
3B
3B2
4.1
5
!
#---------------------------------------------------------------
$AWK '
BEGIN { x="x"
for(i=1; i<=12; i++) x = x x
for(i=15; i<=25; i++) print x i
$AWK '
BEGIN { x="x"
for(i=1; i<=12; i++) x = x x
for(i=25; i>=15; i--) print x i
./xsort A -r
#---------------------------------------------------------------
./xsort A
./xsort B -n
# next test is unclean: xx is a hidden side-effect of xsort
$AWK '
"X" $0 != "X" x { print >"out"; x = $0 }
' xx
./xsort C -n -u
#---------------------------------------------------------------
# option -y4096 ($y) should force a multi-stage internal merge
# option -Xread ($X) should force read over mmap
case "$y" in
esac
./xsort A -r $y
./xsort E -u -r $y
#---------------------------------------------------------------
#---------------------------------------------------------------
a-B
a+b
a b
A+b
a b
!
a b
a b
A+b
a-B
a+b
!
#---------------------------------------------------------------
12 y
13 z
12 x
!
12 x
12 y
13 z
!
#---------------------------------------------------------------
#include <stdio.h>
return 0; }
!
#include <stdio.h>
return 0; }
!
./xsort A -i -k 2
#include <stdio.h>
return 0; }
!
./xsort B -d -k 2
#include <stdio.h>
for(i='A'; i<='Z'; i++)
return 0; }
!
./xsort C -f -k 2
#---------------------------------------------------------------
b
'C
a
!
cp in out
./xsort A -d
./xsort B -f
cat >out <<!
b
a
'C
!
#---------------------------------------------------------------
#include <stdio.h>
!
#---------------------------------------------------------------
a 2
a 1
b 2
b 1
!
b 1
b 2
a 1
a 2
!
#---------------------------------------------------------------
#---------------------------------------------------------------
0:2:3:4:5:6:7:8:9
1:1:3:4:5:6:7:8:9
1:2:2:4:5:6:7:8:9
1:2:3:3:5:6:7:8:9
1:2:3:4:4:6:7:8:9
1:2:3:4:5:5:7:8:9
1:2:3:4:5:6:6:8:9
1:2:3:4:5:6:7:7:9
1:2:3:4:5:6:7:8:8
!
1:2:3:4:5:6:7:8:8
1:2:3:4:5:6:7:7:9
1:2:3:4:5:6:6:8:9
1:2:3:4:5:5:7:8:9
1:2:3:4:4:6:7:8:9
1:2:3:3:5:6:7:8:9
1:2:2:4:5:6:7:8:9
1:1:3:4:5:6:7:8:9
0:2:3:4:5:6:7:8:9
!
#---------------------------------------------------------------
# numbers give the correct orderings
01:04:19:01:16:01:21:01 a
02:03:13:15:13:19:15:02 a
03:02:07:09:07:13:09:03 a
04:01:01:03:01:07:03:04 a
09:16:22:02:22:04:24:13 b
10:15:16:20:19:22:18:14 b
11:14:10:12:10:16:12:15 b
12:13:04:06:04:10:06:16 b
!
"(standard is not clear on this)"
#---------------------------------------------------------------
0 5
1 4
2 3
3 2
4 1
5 0
!
#---------------------------------------------------------------
#---------------------------------------------------------------
aaaa c
x a
0 b
!
#---------------------------------------------------------------
cat >-k <<!
x
!
!
>-
>-o
>in1
#---------------------------------------------------------------
echo x >out
#---------------------------------------------------------------
!
!
#---------------------------------------------------------------
x
!
x
!
#---------------------------------------------------------------
2
1
10
1e-1
.2
1e
1E1
1e.
3e+308
3e307
1e-308
1e-307
!
1e-308
1e-307
1e-1
.2
1
1e
1e.
2
10
1E1
3e307
3e+308
!
$g ./xsort "" -g
#---------------------------------------------------------------
.99999999999999999999
099999999999999999999e-21
099999999999999999999e-19
.1e1
!
099999999999999999999e-21
.99999999999999999999
.1e1
099999999999999999999e-19
!
$g ./xsort A -g
.1e1
.99999999999999999999
099999999999999999999e-19
099999999999999999999e-21
!
./xsort B -n
#---------------------------------------------------------------
+0
-0
0
0.10
+.1
-.1
-100e-3x
x
!
-.1
-100e-3x
+0
-0
0
x
+.1
0.10
!
$g ./xsort A -g
#---------------------------------------------------------------
a 2
b 1
c 2
a 1
b 2
c 1
!
a 2
a 1
b 1
b 2
c 2
c 1
!
#---------------------------------------------------------------
a 2
c 2
!
a 1
b 1
c 1
!
a 2
b 1
c 2
!
c 1
b 1
a 1
!
#---------------------------------------------------------------
$s $AWK '
BEGIN {
for(i=1; i<50; i++)
for(j=1; j<=i; j++) {
print i, 2 >"in"
print i, 1 >"in1"
}
$s $AWK '
$1!=last1 { if(count!=last1 || $2!=2) stop();
count = 0}
$1==last1 && $2!=last2 { if(count!=last1 || $2!=1) stop();
count = 0 }
{ count++; last1 = $1; last2 = $2 }
' out
#---------------------------------------------------------------
!
#---------------------------------------------------------------
1.2
1.10
!
!
#---------------------------------------------------------------
echo bdpoweonwekjbkgizohoeioilasho > in
echo hozopoonbkkjoieigishwewebdlao > out
( echo; echo ) >> in
!
echo ' aza zaz mzm mam
' > in
echo ' zaz mam mzm aza
' > out
echo ' zaz mzm mam aza
' > out
echo ' mzm aza zaz mam
' > out
done