Index: etc/mtree/BSD.tests.dist =================================================================== --- etc/mtree/BSD.tests.dist +++ etc/mtree/BSD.tests.dist @@ -714,6 +714,8 @@ regress.multitest.out .. .. + seq + .. soelim .. stat Index: usr.bin/seq/Makefile =================================================================== --- usr.bin/seq/Makefile +++ usr.bin/seq/Makefile @@ -1,8 +1,13 @@ # $NetBSD: Makefile,v 1.3 2009/04/14 22:15:26 lukem Exp $ # $FreeBSD$ +.include + PROG= seq LIBADD= m +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include Index: usr.bin/seq/seq.c =================================================================== --- usr.bin/seq/seq.c +++ usr.bin/seq/seq.c @@ -80,7 +80,9 @@ int equalize = 0; double first = 1.0; double last = 0.0; + double cur; double incr = 0.0; + double step; struct lconv *locale; char *fmt = NULL; const char *sep = "\n"; @@ -93,9 +95,9 @@ decimal_point = locale->decimal_point; /* - * Process options, but handle negative numbers separately - * least they trip up getopt(3). - */ + * Process options, but handle negative numbers separately + * least they trip up getopt(3). + */ while ((optind < argc) && !numeric(argv[optind]) && (c = getopt(argc, argv, "f:hs:t:w")) != -1) { @@ -129,7 +131,8 @@ if (errflg) { fprintf(stderr, - "usage: %s [-w] [-f format] [-s string] [-t string] [first [incr]] last\n", + "usage: %s [-w] [-f format] [-s string] [-t string] " + "[first [incr]] last\n", getprogname()); exit(1); } @@ -138,7 +141,7 @@ if (argc > 1) first = e_atof(argv[0]); - + if (argc > 2) { incr = e_atof(argv[1]); /* Plan 9/GNU don't do zero */ @@ -163,22 +166,16 @@ if (!valid_format(fmt)) errx(1, "invalid format string"); /* - * XXX to be bug for bug compatible with Plan 9 add a + * XXX to be bug for bug compatible with Plan 9 add a * newline if none found at the end of the format string. */ } else fmt = generate_format(first, incr, last, equalize, pad); - if (incr > 0) { - for (; first <= last; first += incr) { - printf(fmt, first); - fputs(sep, stdout); - } - } else { - for (; first >= last; first += incr) { - printf(fmt, first); - fputs(sep, stdout); - } + for (step = 0, cur = first; incr > 0 ? cur <= last : cur >= last; + cur = first + incr * ++step) { + printf(fmt, cur); + fputs(sep, stdout); } if (term != NULL) fputs(term, stdout); Index: usr.bin/seq/tests/Makefile =================================================================== --- /dev/null +++ usr.bin/seq/tests/Makefile @@ -0,0 +1,16 @@ +# $FreeBSD$ + +PACKAGE= tests + +ATF_TESTS_SH= seq_test + +${PACKAGE}FILES+= d_seq_float_a.out +${PACKAGE}FILES+= d_seq_float_b.out +${PACKAGE}FILES+= d_seq_float_c.out +${PACKAGE}FILES+= d_seq_float_d.out +${PACKAGE}FILES+= d_seq_float_e.out +${PACKAGE}FILES+= d_seq_float_f.out +${PACKAGE}FILES+= d_seq_generic_a.out +${PACKAGE}FILES+= d_seq_generic_b.out + +.include Index: usr.bin/seq/tests/Makefile.depend =================================================================== --- /dev/null +++ usr.bin/seq/tests/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif Index: usr.bin/seq/tests/d_seq_float_a.out =================================================================== --- /dev/null +++ usr.bin/seq/tests/d_seq_float_a.out @@ -0,0 +1,11 @@ +1 +1.1 +1.2 +1.3 +1.4 +1.5 +1.6 +1.7 +1.8 +1.9 +2 Index: usr.bin/seq/tests/d_seq_float_b.out =================================================================== --- /dev/null +++ usr.bin/seq/tests/d_seq_float_b.out @@ -0,0 +1,11 @@ +2 +1.9 +1.8 +1.7 +1.6 +1.5 +1.4 +1.3 +1.2 +1.1 +1 Index: usr.bin/seq/tests/d_seq_float_c.out =================================================================== --- /dev/null +++ usr.bin/seq/tests/d_seq_float_c.out @@ -0,0 +1,9 @@ +1.6 +1.65 +1.7 +1.75 +1.8 +1.85 +1.9 +1.95 +2 Index: usr.bin/seq/tests/d_seq_float_d.out =================================================================== --- /dev/null +++ usr.bin/seq/tests/d_seq_float_d.out @@ -0,0 +1,9 @@ +2 +1.95 +1.9 +1.85 +1.8 +1.75 +1.7 +1.65 +1.6 Index: usr.bin/seq/tests/d_seq_float_e.out =================================================================== --- /dev/null +++ usr.bin/seq/tests/d_seq_float_e.out @@ -0,0 +1,4 @@ +1 +1.3 +1.6 +1.9 Index: usr.bin/seq/tests/d_seq_float_f.out =================================================================== --- /dev/null +++ usr.bin/seq/tests/d_seq_float_f.out @@ -0,0 +1,4 @@ +2 +1.7 +1.4 +1.1 Index: usr.bin/seq/tests/d_seq_generic_a.out =================================================================== --- /dev/null +++ usr.bin/seq/tests/d_seq_generic_a.out @@ -0,0 +1 @@ +1 Index: usr.bin/seq/tests/d_seq_generic_b.out =================================================================== --- /dev/null +++ usr.bin/seq/tests/d_seq_generic_b.out @@ -0,0 +1 @@ +2 Index: usr.bin/seq/tests/seq_test.sh =================================================================== --- /dev/null +++ usr.bin/seq/tests/seq_test.sh @@ -0,0 +1,69 @@ +# +# Copyright 2018 Yuri Pankov +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +atf_test_case generic +generic_head() +{ + atf_set "descr" "Verify generic output without options" +} +generic_body() +{ + # These are here for sanity checks when fixing fp increment + atf_check -o file:"$(atf_get_srcdir)/d_seq_generic_a.out" \ + seq 1 2 2 + atf_check -o file:"$(atf_get_srcdir)/d_seq_generic_b.out" \ + seq 2 -2 1 +} + +atf_test_case float +float_head() +{ + atf_set "descr" "Verify output with floating point increment" +} +float_body() +{ + # Make sure we use correct decimal point + export LC_ALL=C + + atf_check -o file:"$(atf_get_srcdir)/d_seq_float_a.out" \ + seq 1 .1 2 + atf_check -o file:"$(atf_get_srcdir)/d_seq_float_b.out" \ + seq 2 -.1 1 + atf_check -o file:"$(atf_get_srcdir)/d_seq_float_c.out" \ + seq 1.6 .05 2 + atf_check -o file:"$(atf_get_srcdir)/d_seq_float_d.out" \ + seq 2 -.05 1.6 + atf_check -o file:"$(atf_get_srcdir)/d_seq_float_e.out" \ + seq 1 .3 2 + atf_check -o file:"$(atf_get_srcdir)/d_seq_float_f.out" \ + seq 2 -.3 1 +} + +atf_init_test_cases() +{ + atf_add_test_case generic + atf_add_test_case float +}