[PATCH 0/2] Add RELAX NG schema and tests for virt-inspector --xml
-- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
-- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
Richard W.M. Jones wrote:
Subject: [PATCH 1/2] inspector: Add RELAX NG schema for virt-inspector --xml output.
diff --git a/inspector/virt-inspector b/inspector/virt-inspector ... +There is a RELAX-NG schema for this XML in the file +I<virt-inspector.rng> which normally ships with virt-inspector, or can +be found in the source.
diff --git a/inspector/virt-inspector.rng b/inspector/virt-inspector.rng new file mode 100644 index 0000000..1da58fc --- /dev/null +++ b/inspector/virt-inspector.rng @@ -0,0 +1,168 @@ +<grammar xmlns="http://relaxng.org/ns/structure/1.0"> + <!-- -*- xml -*- + This is a RELAX NG schema for the output of 'virt-inspector - -xml'. + + To validate an existing document against this schema, you can + use xmllint, like this: + + virt-inspector - -xml Foo > output.xml + xmllint - -noout - -relaxng virt-inspector.rng output.xml + + (Note that because of limitations of XML, I have had to put spaces + between double dashes in the above code. Those spaces should not + be there in what you type on the command line).
This looks fine (in spite of having to write "- -" for "--" above ;-), so ACK.
The four examples are from some guests I have running locally. They all validate against the RELAX NG schema, according to xmllint. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
Richard W.M. Jones wrote:
The four examples are from some guests I have running locally. They all validate against the RELAX NG schema, according to xmllint. ... Subject: [PATCH 2/2] inspector: Add tests for RELAX NG schema. ... diff --git a/inspector/Makefile.am b/inspector/Makefile.am index c8ebaf7..25f5e3c 100644 --- a/inspector/Makefile.am +++ b/inspector/Makefile.am @@ -17,12 +17,17 @@
EXTRA_DIST = \ run-inspector-locally \ - virt-inspector + virt-inspector \ + virt-inspector.rng \ + example1.xml example2.xml example3.xml example4.xml
There's no need to add these in EXTRA_DIST, since...
if HAVE_INSPECTOR
bin_SCRIPTS = virt-inspector man_MANS = virt-inspector.1 +dist_doc_DATA = \ + virt-inspector.rng \ + example1.xml example2.xml example3.xml example4.xml
...adding them in dist_doc_DATA already ensures they're distributed (the "dist_" prefix).
noinst_DATA = $(top_builddir)/html/virt-inspector.1.html
@@ -42,4 +47,11 @@ $(top_builddir)/html/virt-inspector.1.html: virt-inspector --outfile html/virt-inspector.1.html \ inspector/$<
+if HAVE_XMLLINT + +TESTS = example1.xml example2.xml example3.xml example4.xml +TESTS_ENVIRONMENT = $(XMLLINT) --noout --relaxng virt-inspector.rng
This is a cute trick, and is fine if you're confident this is the only type of test there will ever be in this subdirectory. Otherwise, you might want to change it to generate tiny scripts to accomplish the same task in a way that will accommodate non-xml-related tests. E.g., something like this: ----------------------------------------------------------------------------- xml = example1.xml example2.xml example3.xml example4.xml xml_sh = $(subst .xml,.sh,$(xml)) TESTS = $(xml_sh) DISTCLEANFILES = $(xml_sh) z = $(subst .sh,.xml,$@) $(xml_sh): Makefile ( printf '%s\n' '#!/bin/sh' \ 'exec $(XMLLINT) --noout --relaxng virt-inspector.rng $(z)'; \ ) > $@-t && chmod a+x $@-t && mv $@-t $@ ----------------------------------------------------------------------------- Regarding conditional tests, how about running them unconditionally, but making them skip with a diagnostic when xmllint is not available, e.g., insert two more lines into each generated script: ( xmllint --version > /dev/null 2>&1 ) \ || { echo "$0: skipping this test: xmllint is not available" exit 77; } Then even if xmllint is not around at configure-time, but is later installed, the tests *will* be run. If you do this, you can drop the configure-time test, of course.
participants (2)
-
Jim Meyering -
Richard W.M. Jones