From owner-freebsd-testing@FreeBSD.ORG Tue Jul 29 10:37:35 2014 Return-Path: Delivered-To: freebsd-testing@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8158726F for ; Tue, 29 Jul 2014 10:37:35 +0000 (UTC) Received: from smtprelay04.ispgateway.de (smtprelay04.ispgateway.de [80.67.29.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 400BC2846 for ; Tue, 29 Jul 2014 10:37:35 +0000 (UTC) Received: from [84.44.154.146] (helo=fabiankeil.de) by smtprelay04.ispgateway.de with esmtpsa (SSLv3:AES128-SHA:128) (Exim 4.68) (envelope-from ) id 1XC4mh-00072L-TD for freebsd-testing@freebsd.org; Tue, 29 Jul 2014 12:37:32 +0200 Date: Tue, 29 Jul 2014 12:37:35 +0200 From: Fabian Keil To: Subject: Re: atf_check() equivalent to test individual shell functions? Message-ID: <1552a16f.63e4cafe@fabiankeil.de> In-Reply-To: References: <41d8a2fb.75b47028@fabiankeil.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; boundary="Sig_/0mbW+85UlyoZ+jB1kJO0_kU"; protocol="application/pgp-signature" X-Df-Sender: Nzc1MDY3 X-BeenThere: freebsd-testing@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Testing on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jul 2014 10:37:35 -0000 --Sig_/0mbW+85UlyoZ+jB1kJO0_kU Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Julio Merino wrote: > On Sat, Jul 26, 2014 at 4:30 AM, Fabian Keil > wrote: > > Here's another zogftw-related problem. >=20 > What's zogftw? The program I'm writing tests for: http://www.fabiankeil.de/gehacktes/zogftw/ > > Putting something like this in a test case works as expected: > > > > | atf_check -s exit:0 -o empty -e empty $ZOGFTW cmd zogftw_string_ends_= with "abc" "c" >=20 > What is "$ZOGFTW cmd ..." supposed to be doing? $ZOGFTW is the path to zogftw ("$(atf_get_srcdir)/../zogftw"), "cmd" is a subcommand that executes the additional arguments in the context of zogftw itself. > > It would be preferably to source zogftw once at the beginning > > and call the shell function zogftw_string_ends_with() directly > > afterwards to reduce the overhead, though. > > > > The following sort of does this, but the stdout and stderr > > output isn't verified, it's tedious to write and if nothing > > fails, the "kyua debug" output isn't particular useful: > > > > | . $ZOGFTW source || atf_fail "Failed to source zogftw" > > | > > | if ! zogftw_string_ends_with "abc" "c"; then > > | atf_fail "Failed to find 'c' at the end of 'abc'" > > | fi > > > > The following also sort of works, but in case of errors the output > > isn't helpful (because atf_check_equal() doesn't see the actual > > function) and the stderr output isn't verified either: > > > > | . $ZOGFTW source || atf_fail "Failed to source zogftw" > > | > > | atf_check_equal $(zogftw_string_ends_with "abc" "c"; echo $?) "0" >=20 > Or just: >=20 > zogftw_string_ends_with "abc" "c" || atf_fail "abc doesn't end with c" In which case unexpected stdout output emitted from zogftw_string_ends_with would not be detected, though. > > What I'm looking for is something like this: > > > > | atf_check_shell_function -s return:0 -o empty -e empty zogftw_string_= ends_with "abc" "c" >=20 > That could be interesting. >=20 > However, note that atf_check currently is just a thin wrapper over the > atf-check binary and that's the reason why you cannot feed shell > functions into it. Implementing an atf_check_shell_function would > involve rewriting atf-check's functionality in libatf-sh.subr. Indeed, I just wondered if someone had already done it. =20 > > atf-sh-api(3) doesn't seem to mention anything like it, > > so I'm wondering how other people are testing individual > > shell functions? >=20 > Take a look at the test programs in here for other ideas: >=20 > https://github.com/jmmv/shtk Will do, thanks. > The background is that atf-sh has been mostly used for integration > testing until now so the support for unit-testing shell functions > hasn't been necessary. I agree that building some would be good. Great. Fabian --Sig_/0mbW+85UlyoZ+jB1kJO0_kU Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAlPXeW8ACgkQBYqIVf93VJ3srACbB8jHbT92z36nfc6nfNGSHAfq liQAoKePx8fS+ijmdYi+LTWwpsUVuFqC =VCkC -----END PGP SIGNATURE----- --Sig_/0mbW+85UlyoZ+jB1kJO0_kU--