From: millert Date: Mon, 12 Jun 2023 20:19:45 +0000 (+0000) Subject: Simple seq(1) regress. More tests are needed. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=fafd6c403a36917c7f5b9d673e2a068bbde9f169;p=openbsd Simple seq(1) regress. More tests are needed. --- diff --git a/regress/usr.bin/Makefile b/regress/usr.bin/Makefile index 8b8937d2795..52d71cd1647 100644 --- a/regress/usr.bin/Makefile +++ b/regress/usr.bin/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.46 2021/03/09 17:38:24 martijn Exp $ +# $OpenBSD: Makefile,v 1.47 2023/06/12 20:19:45 millert Exp $ SUBDIR+= apply SUBDIR+= basename bc @@ -12,7 +12,7 @@ SUBDIR+= m4 mail mandoc SUBDIR+= nc SUBDIR+= openssl SUBDIR+= rev -SUBDIR+= sdiff sed signify snmp sort +SUBDIR+= sdiff sed seq signify snmp sort SUBDIR+= tsort SUBDIR+= ul SUBDIR+= wc diff --git a/regress/usr.bin/seq/Makefile b/regress/usr.bin/seq/Makefile new file mode 100644 index 00000000000..a5f3c2e34bc --- /dev/null +++ b/regress/usr.bin/seq/Makefile @@ -0,0 +1,7 @@ +# $OpenBSD: Makefile,v 1.1 2023/06/12 20:19:45 millert Exp $ + +SEQ?= /usr/bin/seq + +seqtest: + sh ${.CURDIR}/$@.sh ${SEQ} $@.out + diff ${.CURDIR}/$@.expected $@.out diff --git a/regress/usr.bin/seq/seqtest.expected b/regress/usr.bin/seq/seqtest.expected new file mode 100644 index 00000000000..4178fd91511 --- /dev/null +++ b/regress/usr.bin/seq/seqtest.expected @@ -0,0 +1,62 @@ +Test 1.1: check for invalid format string +seq: invalid format string: `foo' + +Test 1.2: check for valid format string +bar1.000000 +bar2.000000 +bar3.000000 + +Test 1.3: check for invalid increment +seq: zero decrement + +Test 1.4: check for first > last +seq: needs negative decrement + +Test 1.5: check for increment mismatch +seq: needs positive increment + +Test 1.6: check for increment mismatch +seq: needs negative decrement + +Test 2.0: single argument (0) +1 +0 + +Test 2.1: single argument (1) +1 + +Test 2.2: single argument (-1) +1 +0 +-1 + +Test 2.3: two arguments (1, 1) +1 + +Test 2.3: two arguments (1, 2) +1 +2 + +Test 2.3: two arguments (1, -2) +1 +0 +-1 +-2 + +Test 3.0: check for missing element due to rounding +1 +1.1 +1.2 + +Test 3.1: check for missing element due to rounding +0 +1e-06 +2e-06 +3e-06 + +Test 3.2: check for extra element due to rounding +0.1 +1.09 + +Test 3.3: check for extra element due to rounding check +1.05e+06 diff --git a/regress/usr.bin/seq/seqtest.sh b/regress/usr.bin/seq/seqtest.sh new file mode 100755 index 00000000000..240da3e4166 --- /dev/null +++ b/regress/usr.bin/seq/seqtest.sh @@ -0,0 +1,94 @@ +#!/bin/sh +# $OpenBSD: seqtest.sh,v 1.1 2023/06/12 20:19:45 millert Exp $ +# +# Public domain, 2023, Todd C. Miller +# +# Usage: seqtest.sh [seq_bin log_file] +# +# If no log file is specified, seq.out is used. + +run_tests() +{ + SEQ=$1 + LOG=$2 + rm -f $LOG + exec >$LOG 2>&1 + + test_args; + test_simple; + test_rounding; +} + +test_args() +{ + echo 'Test 1.1: check for invalid format string' + ${SEQ} -f foo 3 + + echo + echo 'Test 1.2: check for valid format string' + ${SEQ} -f bar%f 3 + + echo + echo 'Test 1.3: check for invalid increment' + ${SEQ} 1 0 1 + + echo + echo 'Test 1.4: check for first > last' + ${SEQ} 1 .1 -1 + + echo + echo 'Test 1.5: check for increment mismatch' + ${SEQ} 0 -0.1 1 + + echo + echo 'Test 1.6: check for increment mismatch' + ${SEQ} 1 0.1 0 +} + +test_simple() +{ + echo + echo 'Test 2.0: single argument (0)' + ${SEQ} 0 + + echo + echo 'Test 2.1: single argument (1)' + ${SEQ} 1 + + echo + echo 'Test 2.2: single argument (-1)' + ${SEQ} -1 + + echo + echo 'Test 2.3: two arguments (1, 1)' + ${SEQ} 1 1 + + echo + echo 'Test 2.3: two arguments (1, 2)' + ${SEQ} 1 2 + + echo + echo 'Test 2.3: two arguments (1, -2)' + ${SEQ} 1 -2 +} + +test_rounding() +{ + echo + echo 'Test 3.0: check for missing element due to rounding' + ${SEQ} 1 0.1 1.2 + + echo + echo 'Test 3.1: check for missing element due to rounding' + ${SEQ} 0 0.000001 0.000003 + + echo + echo 'Test 3.2: check for extra element due to rounding' + ${SEQ} 0.1 .99 1.99 + + echo + echo 'Test 3.3: check for extra element due to rounding check' + ${SEQ} 1050000 1050000 +} + +run_tests ${1:-seq} ${2:-seq.out}