Eric Blake
2019-Sep-12 03:10 UTC
[Libguestfs] [libnbd PATCH] nbdsh: Start adding unit tests
Ultimately, I'd like to add a unit test covering our recent fix for handling globals from consecutive -c, but let's start with a simple test that --help output is sane. Sanity includes a mention of the man page for more details (similar to nbdkit --help, although I couldn't figure out how to make python's argparse output that sentence last). --- python/nbdsh.py | 3 ++- sh/Makefile.am | 9 ++++++--- sh/test-help.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100755 sh/test-help.sh diff --git a/python/nbdsh.py b/python/nbdsh.py index 553e632..117c824 100644 --- a/python/nbdsh.py +++ b/python/nbdsh.py @@ -23,7 +23,8 @@ def shell(): import nbd - description = '''Network Block Device (NBD) shell''' + description = '''Network Block Device (NBD) shell. Please read the + nbdsh(1) manual page for full usage.''' parser = argparse.ArgumentParser (prog='nbdsh', description=description) parser.add_argument ('--connect', help="connect to NBD URI") diff --git a/sh/Makefile.am b/sh/Makefile.am index 2e04e46..2e9a047 100644 --- a/sh/Makefile.am +++ b/sh/Makefile.am @@ -21,6 +21,7 @@ EXTRA_DIST = \ nbdsh.pod \ examples/LICENSE-FOR-EXAMPLES \ examples/hexdump.sh \ + test-help.sh \ $(NULL) if HAVE_PYTHON @@ -40,8 +41,10 @@ nbdsh.1: nbdsh.pod $(top_builddir)/podwrapper.pl endif HAVE_POD -if HAVE_NBDKIT - TESTS_ENVIRONMENT = LIBNBD_DEBUG=1 LOG_COMPILER = $(top_builddir)/run -TESTS +TESTS = test-help.sh + +if HAVE_NBDKIT + +TESTS + endif HAVE_NBDKIT diff --git a/sh/test-help.sh b/sh/test-help.sh new file mode 100755 index 0000000..6ed1c9c --- /dev/null +++ b/sh/test-help.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# nbd client library in userspace +# Copyright (C) 2019 Red Hat Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +# Test that nbdsh --help looks sane. + +fail=0 +output=$(nbdsh --help) +if [ $? != 0 ]; then + echo "$0: unexpected exit status" + fail=1 +fi +if [[ ! ( "$output" =~ "usage:" && "$output" =~ "manual page" ) ]]; then + echo "$0: unexpected output" + fail=1 +fi +echo "$output" +exit $fail -- 2.21.0
Richard W.M. Jones
2019-Sep-12 07:51 UTC
Re: [Libguestfs] [libnbd PATCH] nbdsh: Start adding unit tests
Yes this is fine, ACK. FWIW the following Fedora packages contain the fixed nbdsh: libnbd-1.0.1-2.fc29 libnbd-1.0.1-2.fc30 libnbd-1.0.1-2.fc31 libnbd-1.1.1-2.fc32 For fc<=31 you will need to enable updates-testing to get them. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Eric Blake
2019-Sep-12 11:38 UTC
Re: [Libguestfs] [libnbd PATCH] nbdsh: Start adding unit tests
On 9/11/19 10:10 PM, Eric Blake wrote:> Ultimately, I'd like to add a unit test covering our recent fix for > handling globals from consecutive -c, but let's start with a simple > test that --help output is sane. Sanity includes a mention of the man > page for more details (similar to nbdkit --help, although I couldn't > figure out how to make python's argparse output that sentence last).Found it - pass epilog=... to the ArgumentParser() construction.> --- > python/nbdsh.py | 3 ++- > sh/Makefile.am | 9 ++++++--- > sh/test-help.sh | 32 ++++++++++++++++++++++++++++++++ > 3 files changed, 40 insertions(+), 4 deletions(-) > create mode 100755 sh/test-help.sh >-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Seemingly Similar Threads
- [libnbd PATCH] nbdsh: Add -b option to simplify h.block_status
- [libnbd PATCH] nbdsh: Hide nbd.Error from abrt-python3-handler
- [libnbd PATCH v2 0/3] Improve nbdsh -u handling
- [libnbd PATCH v2] nbdsh: Prefer --uri over --connect
- [libnbd PATCH v2] nbdsh: Catch nbd.Error from -c arguments