Blame SOURCES/0049-ruby-Fix-.new-method-RHBZ-1046509.patch

cd6068
From d299014ef6b766c23db2f2a11fb21d5df7123e51 Mon Sep 17 00:00:00 2001
cd6068
From: "Richard W.M. Jones" <rjones@redhat.com>
cd6068
Date: Fri, 27 Dec 2013 09:45:49 +0000
cd6068
Subject: [PATCH] ruby: Fix .new method (RHBZ#1046509).
cd6068
cd6068
The .new method was unintentionally broken in
cd6068
commit 9466060201600db47016133d80af22eb38091a49.
cd6068
cd6068
This fixes the .new method and allows it to be called with multiple
cd6068
parameters, so you can use:
cd6068
cd6068
  Guestfs::Guestfs.new
cd6068
  Guestfs::Guestfs.new()
cd6068
  Guestfs::Guestfs.new(:close_on_exit => false)
cd6068
  etc.
cd6068
cd6068
For backwards compatibility, Guestfs::create may still be used.
cd6068
cd6068
This commit also adds regression tests:
cd6068
cd6068
 - Use .new method in regular tests.  (Because this was not done
cd6068
   before, we didn't catch the breakage.)
cd6068
cd6068
 - Test that ::create still works.
cd6068
cd6068
 - Test that args can be passed to .new method.
cd6068
cd6068
(cherry picked from commit ee4ce2a0298d012bd8c500c35dc50e1f53e88c8b)
cd6068
---
cd6068
 generator/bindtests.ml             |  2 +-
cd6068
 generator/ruby.ml                  | 92 +++++++++++++++++++++++++++++++-------
cd6068
 ruby/t/tc_020_create.rb            |  2 +-
cd6068
 ruby/t/tc_030_create_flags.rb      | 29 ++++++++++++
cd6068
 ruby/t/tc_040_create_multiple.rb   | 32 +++++++++++++
cd6068
 ruby/t/tc_050_handle_properties.rb | 36 +++++++++++++++
cd6068
 ruby/t/tc_060_explicit_close.rb    | 29 ++++++++++++
cd6068
 ruby/t/tc_070_optargs.rb           |  2 +-
cd6068
 ruby/t/tc_100_launch.rb            |  2 +-
cd6068
 ruby/t/tc_410_close_event.rb       |  2 +-
cd6068
 ruby/t/tc_420_log_messages.rb      |  2 +-
cd6068
 ruby/t/tc_800_rhbz507346.rb        |  2 +-
cd6068
 ruby/t/tc_810_rhbz664558c6.rb      |  2 +-
cd6068
 ruby/t/tc_820_rhbz1046509.rb       | 42 +++++++++++++++++
cd6068
 14 files changed, 251 insertions(+), 25 deletions(-)
cd6068
 create mode 100644 ruby/t/tc_030_create_flags.rb
cd6068
 create mode 100644 ruby/t/tc_040_create_multiple.rb
cd6068
 create mode 100644 ruby/t/tc_050_handle_properties.rb
cd6068
 create mode 100644 ruby/t/tc_060_explicit_close.rb
cd6068
 create mode 100644 ruby/t/tc_820_rhbz1046509.rb
cd6068
cd6068
diff --git a/generator/bindtests.ml b/generator/bindtests.ml
cd6068
index 55b6a81..e18b9be 100644
cd6068
--- a/generator/bindtests.ml
cd6068
+++ b/generator/bindtests.ml
cd6068
@@ -452,7 +452,7 @@ and generate_ruby_bindtests () =
cd6068
   pr "\
cd6068
 require 'guestfs'
cd6068
 
cd6068
-g = Guestfs::create()
cd6068
+g = Guestfs::Guestfs.new()
cd6068
 ";
cd6068
 
cd6068
   let mkargs args optargs =
cd6068
diff --git a/generator/ruby.ml b/generator/ruby.ml
cd6068
index 3a7d05d..eb176ab 100644
cd6068
--- a/generator/ruby.ml
cd6068
+++ b/generator/ruby.ml
cd6068
@@ -42,6 +42,7 @@ let rec generate_ruby_c () =
cd6068
 #include <stdint.h>
cd6068
 #include <string.h>
cd6068
 #include <errno.h>
cd6068
+#include <assert.h>
cd6068
 
cd6068
 #pragma GCC diagnostic push
cd6068
 #pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
cd6068
@@ -135,34 +136,89 @@ ruby_guestfs_free (void *gvp)
cd6068
   }
cd6068
 }
cd6068
 
cd6068
+/* This is the ruby internal alloc function for the class.  We do nothing
cd6068
+ * here except allocate an object containing a NULL guestfs handle.
cd6068
+ * Note we cannot call guestfs_create here because we need the extra
cd6068
+ * parameters, which ruby passes via the initialize method (see next
cd6068
+ * function).
cd6068
+ */
cd6068
+static VALUE
cd6068
+ruby_guestfs_alloc (VALUE klass)
cd6068
+{
cd6068
+  guestfs_h *g = NULL;
cd6068
+
cd6068
+  /* Wrap it, and make sure the close function is called when the
cd6068
+   * handle goes away.
cd6068
+   */
cd6068
+  return Data_Wrap_Struct (c_guestfs, NULL, ruby_guestfs_free, g);
cd6068
+}
cd6068
+
cd6068
+static unsigned
cd6068
+parse_flags (int argc, VALUE *argv)
cd6068
+{
cd6068
+  volatile VALUE optargsv;
cd6068
+  unsigned flags = 0;
cd6068
+  volatile VALUE v;
cd6068
+
cd6068
+  optargsv = argc == 1 ? argv[0] : rb_hash_new ();
cd6068
+  Check_Type (optargsv, T_HASH);
cd6068
+
cd6068
+  v = rb_hash_lookup (optargsv, ID2SYM (rb_intern (\"environment\")));
cd6068
+  if (v != Qnil && !RTEST (v))
cd6068
+    flags |= GUESTFS_CREATE_NO_ENVIRONMENT;
cd6068
+  v = rb_hash_lookup (optargsv, ID2SYM (rb_intern (\"close_on_exit\")));
cd6068
+  if (v != Qnil && !RTEST (v))
cd6068
+    flags |= GUESTFS_CREATE_NO_CLOSE_ON_EXIT;
cd6068
+
cd6068
+  return flags;
cd6068
+}
cd6068
+
cd6068
 /*
cd6068
  * call-seq:
cd6068
  *   Guestfs::Guestfs.new([{:environment => false, :close_on_exit => false}]) -> Guestfs::Guestfs
cd6068
  *
cd6068
  * Call
cd6068
- * +guestfs_create+[http://libguestfs.org/guestfs.3.html#guestfs_create]
cd6068
+ * +guestfs_create_flags+[http://libguestfs.org/guestfs.3.html#guestfs_create_flags]
cd6068
  * to create a new libguestfs handle.  The handle is represented in
cd6068
  * Ruby as an instance of the Guestfs::Guestfs class.
cd6068
  */
cd6068
 static VALUE
cd6068
-ruby_guestfs_create (int argc, VALUE *argv, VALUE m)
cd6068
+ruby_guestfs_initialize (int argc, VALUE *argv, VALUE m)
cd6068
 {
cd6068
   guestfs_h *g;
cd6068
+  unsigned flags;
cd6068
 
cd6068
   if (argc > 1)
cd6068
     rb_raise (rb_eArgError, \"expecting 0 or 1 arguments\");
cd6068
 
cd6068
-  volatile VALUE optargsv = argc == 1 ? argv[0] : rb_hash_new ();
cd6068
-  Check_Type (optargsv, T_HASH);
cd6068
+  /* Should have been set to NULL by prior call to alloc function. */
cd6068
+  assert (DATA_PTR (m) == NULL);
cd6068
 
cd6068
-  unsigned flags = 0;
cd6068
-  volatile VALUE v;
cd6068
-  v = rb_hash_lookup (optargsv, ID2SYM (rb_intern (\"environment\")));
cd6068
-  if (v != Qnil && !RTEST (v))
cd6068
-    flags |= GUESTFS_CREATE_NO_ENVIRONMENT;
cd6068
-  v = rb_hash_lookup (optargsv, ID2SYM (rb_intern (\"close_on_exit\")));
cd6068
-  if (v != Qnil && !RTEST (v))
cd6068
-    flags |= GUESTFS_CREATE_NO_CLOSE_ON_EXIT;
cd6068
+  flags = parse_flags (argc, argv);
cd6068
+
cd6068
+  g = guestfs_create_flags (flags);
cd6068
+  if (!g)
cd6068
+    rb_raise (e_Error, \"failed to create guestfs handle\");
cd6068
+
cd6068
+  DATA_PTR (m) = g;
cd6068
+
cd6068
+  /* Don't print error messages to stderr by default. */
cd6068
+  guestfs_set_error_handler (g, NULL, NULL);
cd6068
+
cd6068
+  return m;
cd6068
+}
cd6068
+
cd6068
+/* For backwards compatibility. */
cd6068
+static VALUE
cd6068
+ruby_guestfs_create (int argc, VALUE *argv, VALUE module)
cd6068
+{
cd6068
+  guestfs_h *g;
cd6068
+  unsigned flags;
cd6068
+
cd6068
+  if (argc > 1)
cd6068
+    rb_raise (rb_eArgError, \"expecting 0 or 1 arguments\");
cd6068
+
cd6068
+  flags = parse_flags (argc, argv);
cd6068
 
cd6068
   g = guestfs_create_flags (flags);
cd6068
   if (!g)
cd6068
@@ -171,9 +227,6 @@ ruby_guestfs_create (int argc, VALUE *argv, VALUE m)
cd6068
   /* Don't print error messages to stderr by default. */
cd6068
   guestfs_set_error_handler (g, NULL, NULL);
cd6068
 
cd6068
-  /* Wrap it, and make sure the close function is called when the
cd6068
-   * handle goes away.
cd6068
-   */
cd6068
   return Data_Wrap_Struct (c_guestfs, NULL, ruby_guestfs_free, g);
cd6068
 }
cd6068
 
cd6068
@@ -707,10 +760,10 @@ Init__guestfs (void)
cd6068
 #ifndef HAVE_TYPE_RB_ALLOC_FUNC_T
cd6068
 #define rb_alloc_func_t void*
cd6068
 #endif
cd6068
-  rb_define_alloc_func (c_guestfs, (rb_alloc_func_t) ruby_guestfs_create);
cd6068
+  rb_define_alloc_func (c_guestfs, (rb_alloc_func_t) ruby_guestfs_alloc);
cd6068
 #endif
cd6068
 
cd6068
-  rb_define_module_function (m_guestfs, \"create\", ruby_guestfs_create, -1);
cd6068
+  rb_define_method (c_guestfs, \"initialize\", ruby_guestfs_initialize, -1);
cd6068
   rb_define_method (c_guestfs, \"close\", ruby_guestfs_close, 0);
cd6068
   rb_define_method (c_guestfs, \"set_event_callback\",
cd6068
                     ruby_set_event_callback, 2);
cd6068
@@ -719,6 +772,11 @@ Init__guestfs (void)
cd6068
   rb_define_module_function (m_guestfs, \"event_to_string\",
cd6068
                     ruby_event_to_string, 1);
cd6068
 
cd6068
+  /* For backwards compatibility with older code, define a ::create
cd6068
+   * module function.
cd6068
+   */
cd6068
+  rb_define_module_function (m_guestfs, \"create\", ruby_guestfs_create, -1);
cd6068
+
cd6068
 ";
cd6068
 
cd6068
   (* Constants. *)
cd6068
diff --git a/ruby/t/tc_020_create.rb b/ruby/t/tc_020_create.rb
cd6068
index 2b57ba1..4a04e97 100644
cd6068
--- a/ruby/t/tc_020_create.rb
cd6068
+++ b/ruby/t/tc_020_create.rb
cd6068
@@ -22,7 +22,7 @@ require 'guestfs'
cd6068
 
cd6068
 class TestLoad < Test::Unit::TestCase
cd6068
   def test_create
cd6068
-    g = Guestfs::create()
cd6068
+    g = Guestfs::Guestfs.new()
cd6068
     assert_not_nil (g)
cd6068
   end
cd6068
 end
cd6068
diff --git a/ruby/t/tc_030_create_flags.rb b/ruby/t/tc_030_create_flags.rb
cd6068
new file mode 100644
cd6068
index 0000000..7ec2ce9
cd6068
--- /dev/null
cd6068
+++ b/ruby/t/tc_030_create_flags.rb
cd6068
@@ -0,0 +1,29 @@
cd6068
+# libguestfs Ruby bindings -*- ruby -*-
cd6068
+# Copyright (C) 2013 Red Hat Inc.
cd6068
+#
cd6068
+# This program is free software; you can redistribute it and/or modify
cd6068
+# it under the terms of the GNU General Public License as published by
cd6068
+# the Free Software Foundation; either version 2 of the License, or
cd6068
+# (at your option) any later version.
cd6068
+#
cd6068
+# This program is distributed in the hope that it will be useful,
cd6068
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
cd6068
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
cd6068
+# GNU General Public License for more details.
cd6068
+#
cd6068
+# You should have received a copy of the GNU General Public License
cd6068
+# along with this program; if not, write to the Free Software
cd6068
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
cd6068
+
cd6068
+require 'test/unit'
cd6068
+$:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
cd6068
+$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "guestfs"))
cd6068
+require 'guestfs'
cd6068
+
cd6068
+class TestLoad < Test::Unit::TestCase
cd6068
+  def test_create_flags
cd6068
+    g = Guestfs::Guestfs.new(:environment => false, :close_on_exit => true)
cd6068
+    assert_not_nil (g)
cd6068
+    g.parse_environment()
cd6068
+  end
cd6068
+end
cd6068
diff --git a/ruby/t/tc_040_create_multiple.rb b/ruby/t/tc_040_create_multiple.rb
cd6068
new file mode 100644
cd6068
index 0000000..339b699
cd6068
--- /dev/null
cd6068
+++ b/ruby/t/tc_040_create_multiple.rb
cd6068
@@ -0,0 +1,32 @@
cd6068
+# libguestfs Ruby bindings -*- ruby -*-
cd6068
+# Copyright (C) 2013 Red Hat Inc.
cd6068
+#
cd6068
+# This program is free software; you can redistribute it and/or modify
cd6068
+# it under the terms of the GNU General Public License as published by
cd6068
+# the Free Software Foundation; either version 2 of the License, or
cd6068
+# (at your option) any later version.
cd6068
+#
cd6068
+# This program is distributed in the hope that it will be useful,
cd6068
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
cd6068
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
cd6068
+# GNU General Public License for more details.
cd6068
+#
cd6068
+# You should have received a copy of the GNU General Public License
cd6068
+# along with this program; if not, write to the Free Software
cd6068
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
cd6068
+
cd6068
+require 'test/unit'
cd6068
+$:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
cd6068
+$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "guestfs"))
cd6068
+require 'guestfs'
cd6068
+
cd6068
+class TestLoad < Test::Unit::TestCase
cd6068
+  def test_create_multiple
cd6068
+    g1 = Guestfs::Guestfs.new()
cd6068
+    g2 = Guestfs::Guestfs.new()
cd6068
+    g3 = Guestfs::Guestfs.new()
cd6068
+    assert_not_nil (g1)
cd6068
+    assert_not_nil (g2)
cd6068
+    assert_not_nil (g3)
cd6068
+  end
cd6068
+end
cd6068
diff --git a/ruby/t/tc_050_handle_properties.rb b/ruby/t/tc_050_handle_properties.rb
cd6068
new file mode 100644
cd6068
index 0000000..cf4a7a7
cd6068
--- /dev/null
cd6068
+++ b/ruby/t/tc_050_handle_properties.rb
cd6068
@@ -0,0 +1,36 @@
cd6068
+# libguestfs Ruby bindings -*- ruby -*-
cd6068
+# Copyright (C) 2013 Red Hat Inc.
cd6068
+#
cd6068
+# This program is free software; you can redistribute it and/or modify
cd6068
+# it under the terms of the GNU General Public License as published by
cd6068
+# the Free Software Foundation; either version 2 of the License, or
cd6068
+# (at your option) any later version.
cd6068
+#
cd6068
+# This program is distributed in the hope that it will be useful,
cd6068
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
cd6068
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
cd6068
+# GNU General Public License for more details.
cd6068
+#
cd6068
+# You should have received a copy of the GNU General Public License
cd6068
+# along with this program; if not, write to the Free Software
cd6068
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
cd6068
+
cd6068
+require 'test/unit'
cd6068
+$:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
cd6068
+$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "guestfs"))
cd6068
+require 'guestfs'
cd6068
+
cd6068
+class TestLoad < Test::Unit::TestCase
cd6068
+  def test_handle_properties
cd6068
+    g = Guestfs::Guestfs.new()
cd6068
+    assert_not_nil (g)
cd6068
+    v = g.get_verbose()
cd6068
+    g.set_verbose(v)
cd6068
+    v = g.get_trace()
cd6068
+    g.set_trace(v)
cd6068
+    v = g.get_memsize()
cd6068
+    g.set_memsize(v)
cd6068
+    v = g.get_path()
cd6068
+    g.set_path(v)
cd6068
+  end
cd6068
+end
cd6068
diff --git a/ruby/t/tc_060_explicit_close.rb b/ruby/t/tc_060_explicit_close.rb
cd6068
new file mode 100644
cd6068
index 0000000..74456e4
cd6068
--- /dev/null
cd6068
+++ b/ruby/t/tc_060_explicit_close.rb
cd6068
@@ -0,0 +1,29 @@
cd6068
+# libguestfs Ruby bindings -*- ruby -*-
cd6068
+# Copyright (C) 2013 Red Hat Inc.
cd6068
+#
cd6068
+# This program is free software; you can redistribute it and/or modify
cd6068
+# it under the terms of the GNU General Public License as published by
cd6068
+# the Free Software Foundation; either version 2 of the License, or
cd6068
+# (at your option) any later version.
cd6068
+#
cd6068
+# This program is distributed in the hope that it will be useful,
cd6068
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
cd6068
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
cd6068
+# GNU General Public License for more details.
cd6068
+#
cd6068
+# You should have received a copy of the GNU General Public License
cd6068
+# along with this program; if not, write to the Free Software
cd6068
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
cd6068
+
cd6068
+require 'test/unit'
cd6068
+$:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
cd6068
+$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "guestfs"))
cd6068
+require 'guestfs'
cd6068
+
cd6068
+class TestLoad < Test::Unit::TestCase
cd6068
+  def test_explicit_close
cd6068
+    g = Guestfs::Guestfs.new()
cd6068
+    assert_not_nil (g)
cd6068
+    g.close()
cd6068
+  end
cd6068
+end
cd6068
diff --git a/ruby/t/tc_070_optargs.rb b/ruby/t/tc_070_optargs.rb
cd6068
index 4506466..e28f944 100644
cd6068
--- a/ruby/t/tc_070_optargs.rb
cd6068
+++ b/ruby/t/tc_070_optargs.rb
cd6068
@@ -22,7 +22,7 @@ require 'guestfs'
cd6068
 
cd6068
 class TestLoad < Test::Unit::TestCase
cd6068
   def test_optargs
cd6068
-    g = Guestfs::create()
cd6068
+    g = Guestfs::Guestfs.new()
cd6068
 
cd6068
     g.add_drive("/dev/null", {})
cd6068
     g.add_drive("/dev/null", :readonly => 1)
cd6068
diff --git a/ruby/t/tc_100_launch.rb b/ruby/t/tc_100_launch.rb
cd6068
index 4bd8187..f318ae8 100644
cd6068
--- a/ruby/t/tc_100_launch.rb
cd6068
+++ b/ruby/t/tc_100_launch.rb
cd6068
@@ -22,7 +22,7 @@ require 'guestfs'
cd6068
 
cd6068
 class TestLoad < Test::Unit::TestCase
cd6068
   def test_launch
cd6068
-    g = Guestfs::create()
cd6068
+    g = Guestfs::Guestfs.new()
cd6068
 
cd6068
     File.open("test.img", "w") {
cd6068
       |f| f.seek(500*1024*1024); f.write("\0")
cd6068
diff --git a/ruby/t/tc_410_close_event.rb b/ruby/t/tc_410_close_event.rb
cd6068
index ebf4bbc..d7e53d4 100644
cd6068
--- a/ruby/t/tc_410_close_event.rb
cd6068
+++ b/ruby/t/tc_410_close_event.rb
cd6068
@@ -22,7 +22,7 @@ require 'guestfs'
cd6068
 
cd6068
 class TestLoad < Test::Unit::TestCase
cd6068
   def test_events
cd6068
-    g = Guestfs::create()
cd6068
+    g = Guestfs::Guestfs.new()
cd6068
 
cd6068
     close_invoked = 0
cd6068
     close = Proc.new {| event, event_handle, buf, array |
cd6068
diff --git a/ruby/t/tc_420_log_messages.rb b/ruby/t/tc_420_log_messages.rb
cd6068
index d23a0fb..0c3bd4d 100644
cd6068
--- a/ruby/t/tc_420_log_messages.rb
cd6068
+++ b/ruby/t/tc_420_log_messages.rb
cd6068
@@ -22,7 +22,7 @@ require 'guestfs'
cd6068
 
cd6068
 class TestLoad < Test::Unit::TestCase
cd6068
   def test_events
cd6068
-    g = Guestfs::create()
cd6068
+    g = Guestfs::Guestfs.new()
cd6068
 
cd6068
     log_invoked = 0
cd6068
     log = Proc.new {| event, event_handle, buf, array |
cd6068
diff --git a/ruby/t/tc_800_rhbz507346.rb b/ruby/t/tc_800_rhbz507346.rb
cd6068
index 6082201..7b8d526 100644
cd6068
--- a/ruby/t/tc_800_rhbz507346.rb
cd6068
+++ b/ruby/t/tc_800_rhbz507346.rb
cd6068
@@ -22,7 +22,7 @@ require 'guestfs'
cd6068
 
cd6068
 class TestLoad < Test::Unit::TestCase
cd6068
   def test_rhbz507346
cd6068
-    g = Guestfs::create()
cd6068
+    g = Guestfs::Guestfs.new()
cd6068
 
cd6068
     File.open("test.img", "w") {
cd6068
       |f| f.seek(10*1024*1024); f.write("\0")
cd6068
diff --git a/ruby/t/tc_810_rhbz664558c6.rb b/ruby/t/tc_810_rhbz664558c6.rb
cd6068
index 290deac..5eb373e 100644
cd6068
--- a/ruby/t/tc_810_rhbz664558c6.rb
cd6068
+++ b/ruby/t/tc_810_rhbz664558c6.rb
cd6068
@@ -26,7 +26,7 @@ require 'guestfs'
cd6068
 
cd6068
 class TestLoad < Test::Unit::TestCase
cd6068
   def test_rhbz664558c6
cd6068
-    g = Guestfs::create()
cd6068
+    g = Guestfs::Guestfs.new()
cd6068
 
cd6068
     close_invoked = 0
cd6068
     close = Proc.new {| event, event_handle, buf, array |
cd6068
diff --git a/ruby/t/tc_820_rhbz1046509.rb b/ruby/t/tc_820_rhbz1046509.rb
cd6068
new file mode 100644
cd6068
index 0000000..978decd
cd6068
--- /dev/null
cd6068
+++ b/ruby/t/tc_820_rhbz1046509.rb
cd6068
@@ -0,0 +1,42 @@
cd6068
+# libguestfs Ruby bindings -*- ruby -*-
cd6068
+# Copyright (C) 2013 Red Hat Inc.
cd6068
+#
cd6068
+# This program is free software; you can redistribute it and/or modify
cd6068
+# it under the terms of the GNU General Public License as published by
cd6068
+# the Free Software Foundation; either version 2 of the License, or
cd6068
+# (at your option) any later version.
cd6068
+#
cd6068
+# This program is distributed in the hope that it will be useful,
cd6068
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
cd6068
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
cd6068
+# GNU General Public License for more details.
cd6068
+#
cd6068
+# You should have received a copy of the GNU General Public License
cd6068
+# along with this program; if not, write to the Free Software
cd6068
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
cd6068
+
cd6068
+# Test that we don't break the old ::create module function while
cd6068
+# fixing https://bugzilla.redhat.com/show_bug.cgi?id=1046509
cd6068
+
cd6068
+require 'test/unit'
cd6068
+$:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
cd6068
+$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "guestfs"))
cd6068
+require 'guestfs'
cd6068
+
cd6068
+class TestLoad < Test::Unit::TestCase
cd6068
+  def _handleok(g)
cd6068
+    g.add_drive("/dev/null")
cd6068
+    g.close()
cd6068
+  end
cd6068
+
cd6068
+  def test_rhbz1046509
cd6068
+    g = Guestfs::create()
cd6068
+    _handleok(g)
cd6068
+
cd6068
+    g = Guestfs::create(:close_on_exit => true)
cd6068
+    _handleok(g)
cd6068
+
cd6068
+    g = Guestfs::create(:close_on_exit => true, :environment => true)
cd6068
+    _handleok(g)
cd6068
+  end
cd6068
+end
cd6068
-- 
cd6068
1.8.3.1
cd6068