summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-11-20 13:56:06 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-11-20 14:11:47 +0000
commit7f1f7dd44f4b85c1ce027b2ed194d388518ff452 (patch)
treeebe5c95addfcbefdb0361a988f7ece455a7d67aa
parentb19f007bd2449f635780078e61a174f19838b32d (diff)
downloadlibguestfs-7f1f7dd44f4b85c1ce027b2ed194d388518ff452.tar.gz
libguestfs-7f1f7dd44f4b85c1ce027b2ed194d388518ff452.tar.xz
libguestfs-7f1f7dd44f4b85c1ce027b2ed194d388518ff452.zip
lua: Add bindtests.
-rw-r--r--.gitignore1
-rw-r--r--generator/bindtests.ml56
-rw-r--r--generator/main.ml1
-rw-r--r--lua/Makefile.am5
-rwxr-xr-xlua/run-bindtests20
5 files changed, 82 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index d0c91a7e..f80359b6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -216,6 +216,7 @@ Makefile.in
/libtool
/local*
/ltmain.sh
+/lua/bindtests.lua
/lua/examples/guestfs-lua.3
/lua/examples/stamp-guestfs-lua.pod
/lua/guestfs.so
diff --git a/generator/bindtests.ml b/generator/bindtests.ml
index bb035b34..11094d18 100644
--- a/generator/bindtests.ml
+++ b/generator/bindtests.ml
@@ -739,6 +739,62 @@ and generate_erlang_bindtests () =
pr " ok = file:write(File, \"EOF\\n\"),\n";
pr " ok = file:close(File).\n"
+and generate_lua_bindtests () =
+ generate_header LuaStyle GPLv2plus;
+
+ pr "require \"guestfs\"\n";
+ pr "\n";
+ pr "g = Guestfs.create ()\n";
+ pr "\n";
+
+ generate_lang_bindtests (
+ fun f args optargs ->
+ pr "g:%s (" f;
+ let needs_comma = ref false in
+ List.iter (
+ fun arg ->
+ if !needs_comma then pr ", ";
+ needs_comma := true;
+
+ match arg with
+ | CallString s -> pr "\"%s\"" s
+ | CallOptString None -> pr "nil"
+ | CallOptString (Some s) -> pr "\"%s\"" s
+ | CallStringList xs ->
+ pr "{%s}" (String.concat "," (List.map (sprintf "\"%s\"") xs))
+ | CallInt i -> pr "%d" i
+ | CallInt64 i -> pr "\"%Ld\"" i
+ | CallBool b -> pr "%b" b
+ | CallBuffer s -> pr "\"%s\"" (c_quote s)
+ ) args;
+ (match optargs with
+ | None -> ()
+ | Some optargs ->
+ if !needs_comma then pr ", ";
+
+ pr "{";
+ needs_comma := false;
+ List.iter (
+ fun optarg ->
+ if !needs_comma then pr ", ";
+ needs_comma := true;
+ match optarg with
+ | CallOBool (n, v) -> pr "%s = %b" n v
+ | CallOInt (n, v) -> pr "%s = %d" n v
+ | CallOInt64 (n, v) -> pr "%s = \"%Ld\"" n v
+ | CallOString (n, v) -> pr "%s = \"%s\"" n v
+ | CallOStringList (n, xs) ->
+ pr "%s = {%s}" n
+ (String.concat "," (List.map (sprintf "\"%s\"") xs))
+ ) optargs;
+ pr "}";
+ );
+ pr ")\n"
+ );
+
+ pr "\n";
+ pr "print (\"EOF\")\n"
+
(* Language-independent bindings tests - we do it this way to
* ensure there is parity in testing bindings across all languages.
*)
diff --git a/generator/main.ml b/generator/main.ml
index 55867474..618052b4 100644
--- a/generator/main.ml
+++ b/generator/main.ml
@@ -154,6 +154,7 @@ Run it from the top source directory using the command
output_to "erlang/erl-guestfs.c" generate_erlang_c;
output_to ~perm:0o555 "erlang/bindtests.erl" generate_erlang_bindtests;
output_to "lua/lua-guestfs.c" generate_lua_c;
+ output_to "lua/bindtests.lua" generate_lua_bindtests;
output_to "gobject/bindtests.js" generate_gobject_js_bindtests;
output_to "gobject/Makefile.inc" generate_gobject_makefile;
diff --git a/lua/Makefile.am b/lua/Makefile.am
index abdc4f02..8cc5930d 100644
--- a/lua/Makefile.am
+++ b/lua/Makefile.am
@@ -20,10 +20,12 @@ include $(top_srcdir)/subdir-rules.mk
lualibdir = $(libdir)/lua/$(LUA_VERSION)
generator_built = \
+ bindtests.lua \
lua-guestfs.c
EXTRA_DIST = \
- $(generator_built)
+ $(generator_built) \
+ run-bindtests
CLEANFILES = *~ guestfs.so
@@ -50,6 +52,7 @@ guestfs.so: libluaguestfs.la
# Tests.
TESTS_ENVIRONMENT = $(top_builddir)/run --test
TESTS = \
+ run-bindtests \
tests/010-load.lua \
tests/015-globals.lua \
tests/020-create.lua \
diff --git a/lua/run-bindtests b/lua/run-bindtests
new file mode 100755
index 00000000..170e45b8
--- /dev/null
+++ b/lua/run-bindtests
@@ -0,0 +1,20 @@
+#!/bin/sh -
+# libguestfs Lua bindings
+# Copyright (C) 2012 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.
+
+lua bindtests.lua > bindtests.tmp
+diff -u $srcdir/../bindtests bindtests.tmp