Hilko Bengen
2014-Jan-13 12:07 UTC
[Libguestfs] [PATCH 1/3] ruby: Fix tests for out-of-tree build, simplify test scripts
---
configure.ac | 1 +
ruby/run-ruby-tests | 27 ---------------------------
ruby/run-ruby-tests.in | 27 +++++++++++++++++++++++++++
ruby/tests/tc_010_load.rb | 2 --
ruby/tests/tc_021_close.rb | 2 --
ruby/tests/tc_120_rlenvalue.rb | 4 +---
ruby/tests/tc_200_write.rb | 2 --
ruby/tests/tc_210_setvalue.rb | 2 --
run.in | 4 ++--
9 files changed, 31 insertions(+), 40 deletions(-)
delete mode 100755 ruby/run-ruby-tests
create mode 100755 ruby/run-ruby-tests.in
diff --git a/configure.ac b/configure.ac
index 4066ca5..6785037 100644
--- a/configure.ac
+++ b/configure.ac
@@ -564,6 +564,7 @@ AC_CONFIG_FILES([Makefile
sh/Makefile
xml/Makefile])
AC_CONFIG_FILES([python/run-python-tests], [chmod +x python/run-python-tests])
+AC_CONFIG_FILES([ruby/run-ruby-tests], [chmod +x ruby/run-ruby-tests])
AC_CONFIG_FILES([run], [chmod +x,-w run])
AC_OUTPUT
diff --git a/ruby/run-ruby-tests b/ruby/run-ruby-tests
deleted file mode 100755
index 2efd890..0000000
--- a/ruby/run-ruby-tests
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh -
-# hivex Ruby bindings
-# Copyright (C) 2009-2011 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-set -e
-
-# Run them one at a time, otherwise rake runs them in parallel (which
-# is bound to fail because they all use a single test image file).
-
-for f in tests/tc_*.rb; do
- echo $RAKE test "$@" TEST="$f"
- $RAKE test "$@" TEST="$f"
-done
diff --git a/ruby/run-ruby-tests.in b/ruby/run-ruby-tests.in
new file mode 100755
index 0000000..b61699e
--- /dev/null
+++ b/ruby/run-ruby-tests.in
@@ -0,0 +1,27 @@
+#!/bin/sh -
+# hivex Ruby bindings
+# Copyright (C) 2009-2011 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+set -e
+
+# Run them one at a time, otherwise rake runs them in parallel (which
+# is bound to fail because they all use a single test image file).
+export abs_srcdir=@abs_srcdir@
+for f in @srcdir@/tests/tc_*.rb; do
+ echo $RAKE test "$@" TEST="$f"
+ $RAKE test "$@" TEST="$f"
+done
diff --git a/ruby/tests/tc_010_load.rb b/ruby/tests/tc_010_load.rb
index 113ab69..8a8ae51 100644
--- a/ruby/tests/tc_010_load.rb
+++ b/ruby/tests/tc_010_load.rb
@@ -16,8 +16,6 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
require 'test/unit'
-$:.unshift(File::join(File::dirname(__FILE__), "..",
"lib"))
-$:.unshift(File::join(File::dirname(__FILE__), "..", "ext",
"hivex"))
require 'hivex'
class TestLoad < Test::Unit::TestCase
diff --git a/ruby/tests/tc_021_close.rb b/ruby/tests/tc_021_close.rb
index a089cf3..9c5ea65 100644
--- a/ruby/tests/tc_021_close.rb
+++ b/ruby/tests/tc_021_close.rb
@@ -16,8 +16,6 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
require 'test/unit'
-$:.unshift(File::join(File::dirname(__FILE__), "..",
"lib"))
-$:.unshift(File::join(File::dirname(__FILE__), "..", "ext",
"hivex"))
require 'hivex'
class TestClose < Test::Unit::TestCase
diff --git a/ruby/tests/tc_120_rlenvalue.rb b/ruby/tests/tc_120_rlenvalue.rb
index 368cb19..5cb0a80 100644
--- a/ruby/tests/tc_120_rlenvalue.rb
+++ b/ruby/tests/tc_120_rlenvalue.rb
@@ -22,13 +22,11 @@
# 8712.
require 'test/unit'
-$:.unshift(File::join(File::dirname(__FILE__), "..",
"lib"))
-$:.unshift(File::join(File::dirname(__FILE__), "..", "ext",
"hivex"))
require 'hivex'
class TestRLenValue < Test::Unit::TestCase
def test_RLenValue
- h = Hivex::open("../images/rlenvalue_test_hive", {})
+ h = Hivex::open(File::join(ENV['abs_srcdir'], '..',
'images', 'rlenvalue_test_hive'), {})
assert_not_nil(h)
root = h.root()
diff --git a/ruby/tests/tc_200_write.rb b/ruby/tests/tc_200_write.rb
index b46dc7b..6ae239e 100644
--- a/ruby/tests/tc_200_write.rb
+++ b/ruby/tests/tc_200_write.rb
@@ -16,8 +16,6 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
require 'test/unit'
-$:.unshift(File::join(File::dirname(__FILE__), "..",
"lib"))
-$:.unshift(File::join(File::dirname(__FILE__), "..", "ext",
"hivex"))
require 'hivex'
class TestWrite < Test::Unit::TestCase
diff --git a/ruby/tests/tc_210_setvalue.rb b/ruby/tests/tc_210_setvalue.rb
index e55e5fe..4d1aa7e 100644
--- a/ruby/tests/tc_210_setvalue.rb
+++ b/ruby/tests/tc_210_setvalue.rb
@@ -16,8 +16,6 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
require 'test/unit'
-$:.unshift(File::join(File::dirname(__FILE__), "..",
"lib"))
-$:.unshift(File::join(File::dirname(__FILE__), "..", "ext",
"hivex"))
require 'hivex'
class TestSetValue < Test::Unit::TestCase
diff --git a/run.in b/run.in
index 9592e38..46b3df6 100755
--- a/run.in
+++ b/run.in
@@ -70,9 +70,9 @@ export PYTHONPATH
export RUBY=@RUBY@
export RAKE=@RAKE@
if [ -z "$RUBYLIB" ]; then
- RUBYLIB="$b/ruby/lib:$b/ruby/ext/hivex"
+ RUBYLIB="$s/ruby/lib:$b/ruby/ext/hivex"
else
- RUBYLIB="$b/ruby/lib:$b/ruby/ext/hivex:$RUBYLIB"
+ RUBYLIB="$s/ruby/lib:$b/ruby/ext/hivex:$RUBYLIB"
fi
export RUBYLIB
export LD_LIBRARY_PATH="$b/ruby/ext/hivex:$LD_LIBRARY_PATH"
--
1.8.5.2
Hilko Bengen
2014-Jan-13 12:07 UTC
[Libguestfs] [PATCH 2/3] ruby: Properly declare UTF-8 encoding on node names, value keys
---
generator/generator.ml | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/generator/generator.ml b/generator/generator.ml
index 4119b04..991e3ac 100755
--- a/generator/generator.ml
+++ b/generator/generator.ml
@@ -3367,6 +3367,7 @@ and generate_ruby_c () #include <stdint.h>
#include <ruby.h>
+#include <ruby/encoding.h>
#include \"hivex.h\"
@@ -3657,7 +3658,8 @@ get_values (VALUE valuesv, size_t *nr_values)
| RString ->
if f_len_exists name then (
pr " size_t sz = hivex_%s_len (%s);\n" name (String.concat
", " c_params);
- pr " VALUE rv = rb_str_new (r, sz);\n"
+ pr " VALUE rv = rb_str_new (r, sz);\n";
+ pr " rb_enc_associate (rv, rb_utf8_encoding ());";
) else
pr " VALUE rv = rb_str_new2 (r);\n";
pr " free (r);\n";
--
1.8.5.2
Hilko Bengen
2014-Jan-13 12:07 UTC
[Libguestfs] [PATCH 3/3] ruby: Add test for "special" keys and values
---
ruby/tests/tc_130_special.rb | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
create mode 100644 ruby/tests/tc_130_special.rb
diff --git a/ruby/tests/tc_130_special.rb b/ruby/tests/tc_130_special.rb
new file mode 100644
index 0000000..0623f4d
--- /dev/null
+++ b/ruby/tests/tc_130_special.rb
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+# -*- ruby -*-
+
+require 'test/unit'
+require 'hivex'
+
+class TestRLenValue < Test::Unit::TestCase
+ def test_RLenValue
+ h = Hivex::open(File::join(ENV['abs_srcdir'], '..',
'images', 'special'), {})
+ assert_not_nil(h)
+
+ root = h.root()
+ assert_not_nil(root)
+
+ nodes = h.node_children (root)
+ node = nodes.find { |n| h.node_name(n) == "abcd_äöüß" }
+ assert node != nil
+ value = h.node_values(node).find { |v| h.value_key(v) ==
"abcd_äöüß" }
+ assert value != nil
+ node = nodes.find { |n| h.node_name(n) == "zero\0key" }
+ assert node != nil
+ value = h.node_values(node).find { |v| h.value_key(v) ==
"zero\0val" }
+ assert value != nil
+ node = nodes.find { |n| h.node_name(n) == "weird™" }
+ assert node != nil
+ value = h.node_values(node).find { |v| h.value_key(v) == "symbols
$£₤₧€" }
+ assert value != nil
+
+ end
+end
--
1.8.5.2
Richard W.M. Jones
2014-Jan-13 13:25 UTC
Re: [Libguestfs] [PATCH 3/3] ruby: Add test for "special" keys and values
On Mon, Jan 13, 2014 at 01:07:13PM +0100, Hilko Bengen wrote:> --- > ruby/tests/tc_130_special.rb | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > create mode 100644 ruby/tests/tc_130_special.rb > > diff --git a/ruby/tests/tc_130_special.rb b/ruby/tests/tc_130_special.rb > new file mode 100644 > index 0000000..0623f4d > --- /dev/null > +++ b/ruby/tests/tc_130_special.rb > @@ -0,0 +1,30 @@ > +# -*- coding: utf-8 -*- > +# -*- ruby -*- > + > +require 'test/unit' > +require 'hivex' > + > +class TestRLenValue < Test::Unit::TestCase > + def test_RLenValue > + h = Hivex::open(File::join(ENV['abs_srcdir'], '..', 'images', 'special'), {}) > + assert_not_nil(h) > + > + root = h.root() > + assert_not_nil(root) > + > + nodes = h.node_children (root) > + node = nodes.find { |n| h.node_name(n) == "abcd_äöüß" } > + assert node != nil > + value = h.node_values(node).find { |v| h.value_key(v) == "abcd_äöüß" } > + assert value != nil > + node = nodes.find { |n| h.node_name(n) == "zero\0key" } > + assert node != nil > + value = h.node_values(node).find { |v| h.value_key(v) == "zero\0val" } > + assert value != nil > + node = nodes.find { |n| h.node_name(n) == "weird™" } > + assert node != nil > + value = h.node_values(node).find { |v| h.value_key(v) == "symbols $£₤₧€" } > + assert value != nil > + > + end > +end > -- > 1.8.5.2ACK to all three of these ruby patches. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Apparently Analagous Threads
- [hivex PATCH] ruby: improve test functions
- [PATCH 2/4] hivex: python: Fix encoding for "special" test script
- [PATCH 4/7] python: Add test for "special" keys and values
- [PATCH 3/7] perl: Add test for "special" keys and values
- [PATCH 1/3] ruby: Fix tests for out-of-tree build, simplify test scripts