Pino Toscano
2018-Jun-27 10:44 UTC
[Libguestfs] [PATCH 0/3] test-tool: small options-related improvements
*** BLURB HERE *** Pino Toscano (3): test-tool: implement --short-options & --long-options test-tool: add a documentation test bash: add a completion script for libguestfs-test-tool .gitignore | 1 + bash/Makefile.am | 3 ++- bash/virt-v2v-copy-to-local | 6 +++++ test-tool/Makefile.am | 17 ++++++++++++-- test-tool/libguestfs-test-tool.pod | 8 +++---- test-tool/test-libguestfs-test-tool-docs.sh | 25 +++++++++++++++++++++ test-tool/test-tool.c | 9 +++++++- 7 files changed, 61 insertions(+), 8 deletions(-) create mode 100755 test-tool/test-libguestfs-test-tool-docs.sh -- 2.17.1
Pino Toscano
2018-Jun-27 10:44 UTC
[Libguestfs] [PATCH 1/3] test-tool: implement --short-options & --long-options
While not useful per-se, it will help checking the available options. --- test-tool/Makefile.am | 5 ++++- test-tool/test-tool.c | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test-tool/Makefile.am b/test-tool/Makefile.am index bf4f5a843..2cbd4d1b1 100644 --- a/test-tool/Makefile.am +++ b/test-tool/Makefile.am @@ -22,11 +22,14 @@ EXTRA_DIST = libguestfs-test-tool.pod bin_PROGRAMS = libguestfs-test-tool man_MANS = libguestfs-test-tool.1 -libguestfs_test_tool_SOURCES = test-tool.c +libguestfs_test_tool_SOURCES = \ + ../common/options/display-options.c \ + test-tool.c libguestfs_test_tool_CPPFLAGS = \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \ -DGUESTFS_WARN_DEPRECATED=1 \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c index 49e9ab22a..73e084e50 100644 --- a/test-tool/test-tool.c +++ b/test-tool/test-tool.c @@ -37,6 +37,7 @@ #include "guestfs.h" #include "guestfs-utils.h" +#include "display-options.h" #include "ignore-value.h" @@ -81,8 +82,10 @@ main (int argc, char *argv[]) static const char options[] = "t:V?"; static const struct option long_options[] = { { "help", 0, 0, '?' }, + { "long-options", 0, 0, 0 }, { "qemu", 1, 0, 0 }, { "qemudir", 1, 0, 0 }, + { "short-options", 0, 0, 0 }, { "timeout", 1, 0, 't' }, { "version", 0, 0, 'V' }, { 0, 0, 0, 0 } @@ -103,7 +106,11 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "qemu")) { + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_options); + else if (STREQ (long_options[option_index].name, "short-options")) + display_short_options (options); + else if (STREQ (long_options[option_index].name, "qemu")) { qemu = optarg; qemu_use_wrapper = 0; } -- 2.17.1
Pino Toscano
2018-Jun-27 10:44 UTC
[Libguestfs] [PATCH 2/3] test-tool: add a documentation test
Add the podcheck.pl test, to make sure the documentation is in sync with the available options. Also fix the formats of options in the current POD, so it matches what used already in other documentations, and what podcheck.pl expects. --- test-tool/Makefile.am | 12 +++++++++- test-tool/libguestfs-test-tool.pod | 8 +++---- test-tool/test-libguestfs-test-tool-docs.sh | 25 +++++++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100755 test-tool/test-libguestfs-test-tool-docs.sh diff --git a/test-tool/Makefile.am b/test-tool/Makefile.am index 2cbd4d1b1..e44fa8943 100644 --- a/test-tool/Makefile.am +++ b/test-tool/Makefile.am @@ -17,7 +17,9 @@ include $(top_srcdir)/subdir-rules.mk -EXTRA_DIST = libguestfs-test-tool.pod +EXTRA_DIST = \ + libguestfs-test-tool.pod \ + test-libguestfs-test-tool-docs.sh bin_PROGRAMS = libguestfs-test-tool man_MANS = libguestfs-test-tool.1 @@ -56,5 +58,13 @@ stamp-libguestfs-test-tool.pod: libguestfs-test-tool.pod $< touch $@ +# Tests. + +TESTS_ENVIRONMENT = \ + $(top_builddir)/run --test + +TESTS = \ + test-libguestfs-test-tool-docs.sh + check-valgrind: $(top_builddir)/run --test @VG@ ./libguestfs-test-tool diff --git a/test-tool/libguestfs-test-tool.pod b/test-tool/libguestfs-test-tool.pod index e1f7b673f..d4034a038 100644 --- a/test-tool/libguestfs-test-tool.pod +++ b/test-tool/libguestfs-test-tool.pod @@ -39,19 +39,19 @@ L<http://libguestfs.org/> website. Display short usage information and exit. -=item B<--qemu qemu_binary> +=item B<--qemu> qemu_binary If you have downloaded another qemu binary, point this option at the full path of the binary to try it. -=item B<--qemudir qemu_source_dir> +=item B<--qemudir> qemu_source_dir If you have compiled qemu from source, point this option at the source directory to try it. -=item B<-t N> +=item B<-t> N -=item B<--timeout N> +=item B<--timeout> N Set the launch timeout to C<N> seconds. The default is 600 seconds (10 minutes) which does not usually need to be adjusted. diff --git a/test-tool/test-libguestfs-test-tool-docs.sh b/test-tool/test-libguestfs-test-tool-docs.sh new file mode 100755 index 000000000..234a1408f --- /dev/null +++ b/test-tool/test-libguestfs-test-tool-docs.sh @@ -0,0 +1,25 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2018 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +set -e + +$TEST_FUNCTIONS +skip_if_skipped + +$top_srcdir/podcheck.pl libguestfs-test-tool.pod libguestfs-test-tool \ + --ignore=-? -- 2.17.1
Pino Toscano
2018-Jun-27 10:44 UTC
[Libguestfs] [PATCH 3/3] bash: add a completion script for libguestfs-test-tool
Use the simple virt-v2v-copy-to-local script for it. --- .gitignore | 1 + bash/Makefile.am | 3 ++- bash/virt-v2v-copy-to-local | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 871795bcc..a78fd1633 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ Makefile.in /AUTHORS /autom4te.cache /bash/guestunmount +/bash/libguestfs-test-tool /bash/virt-builder /bash/virt-cat /bash/virt-copy-in diff --git a/bash/Makefile.am b/bash/Makefile.am index 129c2972e..9af1550d2 100644 --- a/bash/Makefile.am +++ b/bash/Makefile.am @@ -28,6 +28,7 @@ scripts = \ # Some of the scripts are simply symbolic links. symlinks = \ guestunmount \ + libguestfs-test-tool \ virt-builder \ virt-cat \ virt-copy-in \ @@ -65,7 +66,7 @@ CLEANFILES += \ # Any tool that has --short-options and --long-options only is handled # by this common script. -virt-win-reg: +libguestfs-test-tool virt-win-reg: rm -f $@ $(LN_S) virt-v2v-copy-to-local $@ diff --git a/bash/virt-v2v-copy-to-local b/bash/virt-v2v-copy-to-local index bfebcbb20..25500d595 100644 --- a/bash/virt-v2v-copy-to-local +++ b/bash/virt-v2v-copy-to-local @@ -51,3 +51,9 @@ _virt_win_reg () _guestfs_options_only "virt-win-reg" } && complete -o default -F _virt_win_reg virt-win-reg + +_libguestfs-test-tool () +{ + _guestfs_options_only "libguestfs-test-tool" +} && +complete -o default -F _libguestfs-test-tool libguestfs-test-tool -- 2.17.1
Richard W.M. Jones
2018-Jun-28 14:40 UTC
Re: [Libguestfs] [PATCH 0/3] test-tool: small options-related improvements
On Wed, Jun 27, 2018 at 12:44:56PM +0200, Pino Toscano wrote:> *** BLURB HERE *** > > Pino Toscano (3): > test-tool: implement --short-options & --long-options > test-tool: add a documentation test > bash: add a completion script for libguestfs-test-tool > > .gitignore | 1 + > bash/Makefile.am | 3 ++- > bash/virt-v2v-copy-to-local | 6 +++++ > test-tool/Makefile.am | 17 ++++++++++++-- > test-tool/libguestfs-test-tool.pod | 8 +++---- > test-tool/test-libguestfs-test-tool-docs.sh | 25 +++++++++++++++++++++ > test-tool/test-tool.c | 9 +++++++- > 7 files changed, 61 insertions(+), 8 deletions(-) > create mode 100755 test-tool/test-libguestfs-test-tool-docs.shACK series, thanks. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Eric Blake
2018-Jun-29 14:53 UTC
Re: [Libguestfs] [PATCH 1/3] test-tool: implement --short-options & --long-options
On 06/27/2018 05:44 AM, Pino Toscano wrote:> While not useful per-se, it will help checking the available options. > ---> @@ -81,8 +82,10 @@ main (int argc, char *argv[]) > static const char options[] = "t:V?"; > static const struct option long_options[] = { > { "help", 0, 0, '?' }, > + { "long-options", 0, 0, 0 }, > { "qemu", 1, 0, 0 }, > { "qemudir", 1, 0, 0 }, > + { "short-options", 0, 0, 0 },If it is our intent to leave these undocumented, we COULD go with naming them "-long-options" and "-short-options" in the long_options array. The bash completion script would then have to call 'utility ---long-options' (yes, with the triple dash) - but it makes it obvious that they remain undocumented for internal use, and the leading - means that '--s' and '--l' do not cause an ambiguous abbreviation with any other long option that IS documented. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org