[Libguestfs] [PATCH v2 nbdkit] tests: Add generic ‘requires’ function for test prerequisites.

Richard W.M. Jones rjones at redhat.com
Wed Jan 23 16:26:22 UTC 2019


On Wed, Jan 23, 2019 at 10:02:18AM -0600, Eric Blake wrote:
> > +++ b/tests/test-ip.sh
> > @@ -37,26 +37,17 @@
> >  source ./functions.sh
> >  set -e
> >  
> > -rm -f ip.pid ipv4.out ipv6.out
> > -cleanup_fn rm -f ip.pid ipv4.out ipv6.out
> > +requires ss --version
> > +requires ip -V
> > +requires qemu-img --version
> >  
> > -# Don't fail if certain commands aren't available.
> > -if ! ss --version; then
> > -    echo "$0: 'ss' command not available"
> > -    exit 77
> > -fi
> > -if ! command -v qemu-img; then
> > -    echo "$0: 'qemu-img' command not available"
> > -    exit 77
> > -fi
> >  if ! qemu-img --help | grep -- --image-opts; then
> >      echo "$0: 'qemu-img' command does not have the --image-opts option"
> >      exit 77
> 
> The old test insists on --image-opts,
> 
> >  fi
> > -if ! ip -V; then
> > -    echo "$0: 'ip' command not available"
> > -    exit 77
> > -fi
> > +
> > +rm -f ip.pid ipv4.out ipv6.out
> > +cleanup_fn rm -f ip.pid ipv4.out ipv6.out
> 
> ...but the rewrite does not.  Could be solved with:
> 
> requires qemu-img info --image-opts driver=file,filename=functions.sh

Yes - as you can see I didn't convert the old test, it's still there.
However I will try your variation to see if that works instead.

> > +++ b/tests/test-partitioning2.sh
> > @@ -40,16 +40,12 @@ source ./functions.sh
> >  set -e
> >  set -x
> >  
> > +requires mke2fs -V
> > +
> >  files="partitioning2.pid partitioning2.sock partitioning2.fs partitioning2.p1 partitioning2.p3"
> >  rm -f $files
> >  cleanup_fn rm -f $files
> >  
> > -# Test that mke2fs works
> > -if ! mke2fs -V; then
> > -    echo "$0: missing or broken mke2fs"
> > -    exit 77
> > -fi
> > -
> >  # Create partitions before and after.
> >  truncate -s 1 partitioning2.p1
> 
> 'truncate' is not universally available; that may be something for a
> future patch to add a requires line for (but not this patch, which
> should be just the mechanical rewrites).

We had a problem on FreeBSD where truncate --size does not work (their
binary only understands truncate -s).  That was fixed by commit
f62e3712428.  Do you know what platforms would lack truncate entirely?

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




More information about the Libguestfs mailing list