xref: /openbsd-src/regress/usr.bin/seq/seqtest.sh (revision fafd6c403a36917c7f5b9d673e2a068bbde9f169)
1#!/bin/sh
2#	$OpenBSD: seqtest.sh,v 1.1 2023/06/12 20:19:45 millert Exp $
3#
4# Public domain, 2023, Todd C. Miller <millert@openbsd.org>
5#
6# Usage: seqtest.sh [seq_bin log_file]
7#
8# If no log file is specified, seq.out is used.
9
10run_tests()
11{
12	SEQ=$1
13	LOG=$2
14	rm -f $LOG
15	exec >$LOG 2>&1
16
17	test_args;
18	test_simple;
19	test_rounding;
20}
21
22test_args()
23{
24	echo 'Test 1.1: check for invalid format string'
25	${SEQ} -f foo 3
26
27	echo
28	echo 'Test 1.2: check for valid format string'
29	${SEQ} -f bar%f 3
30
31	echo
32	echo 'Test 1.3: check for invalid increment'
33	${SEQ} 1 0 1
34
35	echo
36	echo 'Test 1.4: check for first > last'
37	${SEQ} 1 .1 -1
38
39	echo
40	echo 'Test 1.5: check for increment mismatch'
41	${SEQ} 0 -0.1 1
42
43	echo
44	echo 'Test 1.6: check for increment mismatch'
45	${SEQ} 1 0.1 0
46}
47
48test_simple()
49{
50	echo
51	echo 'Test 2.0: single argument (0)'
52	${SEQ} 0
53
54	echo
55	echo 'Test 2.1: single argument (1)'
56	${SEQ} 1
57
58	echo
59	echo 'Test 2.2: single argument (-1)'
60	${SEQ} -1
61
62	echo
63	echo 'Test 2.3: two arguments (1, 1)'
64	${SEQ} 1 1
65
66	echo
67	echo 'Test 2.3: two arguments (1, 2)'
68	${SEQ} 1 2
69
70	echo
71	echo 'Test 2.3: two arguments (1, -2)'
72	${SEQ} 1 -2
73}
74
75test_rounding()
76{
77	echo
78	echo 'Test 3.0: check for missing element due to rounding'
79	${SEQ} 1 0.1 1.2
80
81	echo
82	echo 'Test 3.1: check for missing element due to rounding'
83	${SEQ} 0 0.000001 0.000003
84
85	echo
86	echo 'Test 3.2: check for extra element due to rounding'
87	${SEQ} 0.1 .99 1.99
88
89	echo
90	echo 'Test 3.3: check for extra element due to rounding check'
91	${SEQ} 1050000 1050000
92}
93
94run_tests ${1:-seq} ${2:-seq.out}
95