Date: Wed, 22 Jan 2014 18:56:50 -0500 From: Julio Merino <julio@meroh.net> To: Garrett Cooper <yaneurabeya@gmail.com> Cc: freebsd-testing@FreeBSD.org, Giorgos Keramidas <keramida@freebsd.org> Subject: Re: [PATCH] convert bin/date over to ATF Message-ID: <B90AA730-B7B8-4F1A-9D07-67861C9A6401@meroh.net> In-Reply-To: <6079AD8F-5EBB-431C-A06B-9B51E2729F5A@gmail.com> References: <6079AD8F-5EBB-431C-A06B-9B51E2729F5A@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Jan 20, 2014, at 13:40, Garrett Cooper <yaneurabeya@gmail.com> wrote: > This is based on work done by Giorgos a couple years ago. > Thanks! > -Garrett Pasting patch contents and commenting inline: > diff --git a/bin/date/tests/Makefile b/bin/date/tests/Makefile > index 540008b..459d019 100644 > --- a/bin/date/tests/Makefile > +++ b/bin/date/tests/Makefile > @@ -4,6 +4,6 @@ > =20 > TESTSDIR=3D ${TESTSBASE}/bin/date > =20 > -TAP_TESTS_SH=3D legacy_test > +ATF_TESTS_SH=3D regress Tests ought to end with _test per the description in = https://wiki.freebsd.org/TestSuite/Structure Also, "regress_test" is not a very indicative name. Will this only = contain test cases for bugs to prevent regressions? date_test or integration_test (due to the lack of unit tests for the = code) may be better choices. =20 > --- /dev/null > +++ b/bin/date/tests/regress.sh > @@ -0,0 +1,557 @@ > +#!/bin/sh Remove. This comes from atf.test.mk automatically. > + > +# > +# Regression tests for date(1) > +# > +# Submitted by Edwin Groothuis <edwin@FreeBSD.org> > +# > +# $FreeBSD: src/tools/regression/bin/date/regress.sh,v 1.4 2011/01/09 = 22:05:09 keramida Exp $ > +# > + > +# > +# These two date/times have been chosen carefully, they > +# create both the single digit and double/multidigit version of > +# the values. > +# > +# To create a new one, make sure you are using the UTC timezone! > +# > + > +TEST1=3D3222243 # 1970-02-07 07:04:03 > +TEST2=3D1005600000 # 2001-11-12 21:11:12 > + > +export LC_ALL=3DC > +export TZ=3DUTC Kyua does this already as part of the contract between atf and the = runtime engine. You should not be resetting these. > + > +check() > +{ > + S=3D$1 > + A1=3D$2 > + A2=3D$3 S, A1, A2? What do these mean? Also, make local. > + > + # If the second sample text for formatted output has not been > + # passed, assume it should match exactly the first one. > + if [ -z "${A2}" ]; then > + A2=3D${A1} > + fi > + > + R=3D`date -r ${TEST1} +%${S}` Prefer $() over ``. > + atf_check test "${R}" =3D "${A1}" > + > + R=3D`date -r ${TEST2} +%${S}` > + atf_check test "${R}" =3D "${A2}" > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case A > +A_head() > +{ > + atf_set "descr" "Verifies that 'A' formatting spec works" These test case names are truly non-descriptive. I'd recommend renaming = them to something like formatting_spec__A, etc. and omitting the = definition of head() altogether. Will result on a much shorter test = program, and being concise here for readability matters a lot. ... and then you can just create a "macro" to define test cases. Like = this, but untested: formatting_spec_test_case() { local subname=3D"${1}"; shift local name=3D"formatting_spec__${subname}" atf_test_case "${name}" eval "${name}_body() { check ${*} }" } formatting_spec_test_case a a Sat Mon formatting_spec_test_case B B February November ... formatting_spec_test_case plus + "Sat Feb 7 07:04:03 UTC 1970" "Mon Nov = 12 21:20:00 UTC 2001" > +} > +A_body() > +{ > + check A Saturday Monday > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case a > +a_head() > +{ > + atf_set "descr" "Verifies that 'a' formatting spec works" > +} > +a_body() > +{ > + check a Sat Mon > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case B > +B_head() > +{ > + atf_set "descr" "Verifies that 'B' formatting spec works" > +} > +B_body() > +{ > + check B February November > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case b > +b_head() > +{ > + atf_set "descr" "Verifies that 'b' formatting spec works" > +} > +b_body() > +{ > + check b Feb Nov > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case C > +C_head() > +{ > + atf_set "descr" "Verifies that 'C' formatting spec works" > +} > +C_body() > +{ > + check C 19 20 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case c > +c_head() > +{ > + atf_set "descr" "Verifies that 'c' formatting spec works" > +} > +c_body() > +{ > + check c "Sat Feb 7 07:04:03 1970" "Mon Nov 12 21:20:00 2001" > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case D > +D_head() > +{ > + atf_set "descr" "Verifies that 'D' formatting spec works" > +} > +D_body() > +{ > + check D 02/07/70 11/12/01 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case d > +d_head() > +{ > + atf_set "descr" "Verifies that 'd' formatting spec works" > +} > +d_body() > +{ > + check d 07 12 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case e > +e_head() > +{ > + atf_set "descr" "Verifies that 'e' formatting spec works" > +} > +e_body() > +{ > + check e " 7" 12 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case F > +F_head() > +{ > + atf_set "descr" "Verifies that 'F' formatting spec works" > +} > +F_body() > +{ > + check F "1970-02-07" "2001-11-12" > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case G > +G_head() > +{ > + atf_set "descr" "Verifies that 'G' formatting spec works" > +} > +G_body() > +{ > + check G 1970 2001 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case g > +g_head() > +{ > + atf_set "descr" "Verifies that 'g' formatting spec works" > +} > +g_body() > +{ > + check g 70 01 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case H > +H_head() > +{ > + atf_set "descr" "Verifies that 'H' formatting spec works" > +} > +H_body() > +{ > + check H 07 21 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case h > +h_head() > +{ > + atf_set "descr" "Verifies that 'h' formatting spec works" > +} > +h_body() > +{ > + check h Feb Nov > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case I > +I_head() > +{ > + atf_set "descr" "Verifies that 'I' formatting spec works" > +} > +I_body() > +{ > + check I 07 09 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case j > +j_head() > +{ > + atf_set "descr" "Verifies that 'j' formatting spec works" > +} > +j_body() > +{ > + check j 038 316 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case k > +k_head() > +{ > + atf_set "descr" "Verifies that 'k' formatting spec works" > +} > +k_body() > +{ > + check k " 7" 21 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case l > +l_head() > +{ > + atf_set "descr" "Verifies that 'l' formatting spec works" > +} > +l_body() > +{ > + check l " 7" " 9" > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case M > +M_head() > +{ > + atf_set "descr" "Verifies that 'M' formatting spec works" > +} > +M_body() > +{ > + check M 04 20 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case m > +m_head() > +{ > + atf_set "descr" "Verifies that 'm' formatting spec works" > +} > +m_body() > +{ > + check m 02 11 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case p > +p_head() > +{ > + atf_set "descr" "Verifies that 'p' formatting spec works" > +} > +p_body() > +{ > + check p AM PM > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case R > +R_head() > +{ > + atf_set "descr" "Verifies that 'R' formatting spec works" > +} > +R_body() > +{ > + check R 07:04 21:20 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case r > +r_head() > +{ > + atf_set "descr" "Verifies that 'r' formatting spec works" > +} > +r_body() > +{ > + check r "07:04:03 AM" "09:20:00 PM" > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case S > +S_head() > +{ > + atf_set "descr" "Verifies that 'S' formatting spec works" > +} > +S_body() > +{ > + check S 03 00 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case s > +s_head() > +{ > + atf_set "descr" "Verifies that 's' formatting spec works" > +} > +s_body() > +{ > + check s ${TEST1} ${TEST2} > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case U > +U_head() > +{ > + atf_set "descr" "Verifies that 'U' formatting spec works" > +} > +U_body() > +{ > + check U 05 45 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case u > +u_head() > +{ > + atf_set "descr" "Verifies that 'u' formatting spec works" > +} > +u_body() > +{ > + check u 6 1 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case V > +V_head() > +{ > + atf_set "descr" "Verifies that 'V' formatting spec works" > +} > +V_body() > +{ > + check V 06 46 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case v > +v_head() > +{ > + atf_set "descr" "Verifies that 'v' formatting spec works" > +} > +v_body() > +{ > + check v " 7-Feb-1970" "12-Nov-2001" > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case W > +W_head() > +{ > + atf_set "descr" "Verifies that 'W' formatting spec works" > +} > +W_body() > +{ > + check W 05 46 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case w > +w_head() > +{ > + atf_set "descr" "Verifies that 'w' formatting spec works" > +} > +w_body() > +{ > + check w 6 1 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case X > +X_head() > +{ > + atf_set "descr" "Verifies that 'X' formatting spec works" > +} > +X_body() > +{ > + check X "07:04:03" "21:20:00" > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case x > +x_head() > +{ > + atf_set "descr" "Verifies that 'x' formatting spec works" > +} > +x_body() > +{ > + check x "02/07/70" "11/12/01" > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case Y > +Y_head() > +{ > + atf_set "descr" "Verifies that 'Y' formatting spec works" > +} > +Y_body() > +{ > + check Y 1970 2001 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case y > +y_head() > +{ > + atf_set "descr" "Verifies that 'y' formatting spec works" > +} > +y_body() > +{ > + check y 70 01 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case Z > +Z_head() > +{ > + atf_set "descr" "Verifies that 'Z' formatting spec works" > +} > +Z_body() > +{ > + check Z UTC UTC > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case z > +z_head() > +{ > + atf_set "descr" "Verifies that 'z' formatting spec works" > +} > +z_body() > +{ > + check z +0000 +0000 > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case pct > +pct_head() > +{ > + atf_set "descr" "Verifies that '%' formatting spec works" > +} > +pct_body() > +{ > + check % % % > +} > + > +# = ---------------------------------------------------------------------- > + > +atf_test_case plus > +plus_head() > +{ > + atf_set "descr" "Verifies that '+' formatting spec works" > +} > +plus_body() > +{ > + check + "Sat Feb 7 07:04:03 UTC 1970" "Mon Nov 12 21:20:00 UTC = 2001" > +} > + > +# = ---------------------------------------------------------------------- > +# Main test case driving script. > +# = ---------------------------------------------------------------------- > + > +atf_init_test_cases() > +{ > + atf_add_test_case A > + atf_add_test_case a > + atf_add_test_case B > + atf_add_test_case b > + atf_add_test_case C > + atf_add_test_case c > + atf_add_test_case D > + atf_add_test_case d > + atf_add_test_case e > + atf_add_test_case F > + atf_add_test_case G > + atf_add_test_case g > + atf_add_test_case H > + atf_add_test_case h > + atf_add_test_case I > + atf_add_test_case j > + atf_add_test_case k > + atf_add_test_case l > + atf_add_test_case M > + atf_add_test_case m > + atf_add_test_case p > + atf_add_test_case R > + atf_add_test_case r > + atf_add_test_case S > + atf_add_test_case s > + atf_add_test_case U > + atf_add_test_case u > + atf_add_test_case V > + atf_add_test_case v > + atf_add_test_case W > + atf_add_test_case w > + atf_add_test_case X > + atf_add_test_case x > + atf_add_test_case Y > + atf_add_test_case y > + atf_add_test_case Z > + atf_add_test_case z > + atf_add_test_case pct > + atf_add_test_case plus > +} >=20 >=20
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?B90AA730-B7B8-4F1A-9D07-67861C9A6401>