Pino Toscano
2014-Apr-23 13:19 UTC
[Libguestfs] [HIVEX] port ruby tests to MiniTest (#1090407)
Just like it has been done in libguestfs, port the ruby tests in hivex from Test::Unit to MiniTest, keeping backward compatibility with the old test framework. Pino Toscano (2): ruby: tests: isolate boilerplate in common file ruby: tests: convert from Test::Unit to MiniTest (RHBZ#1090407) ruby/Makefile.am | 3 ++- ruby/tests/tc_010_load.rb | 9 ++++----- ruby/tests/tc_021_close.rb | 9 ++++----- ruby/tests/tc_120_rlenvalue.rb | 13 ++++++------- ruby/tests/tc_130_special.rb | 9 ++++----- ruby/tests/tc_200_write.rb | 9 ++++----- ruby/tests/tc_210_setvalue.rb | 9 ++++----- ruby/tests/test_helper.rb | 31 +++++++++++++++++++++++++++++++ 8 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 ruby/tests/test_helper.rb -- 1.9.0
Pino Toscano
2014-Apr-23 13:19 UTC
[Libguestfs] [PATCH 1/2] ruby: tests: isolate boilerplate in common file
Isolate in a common file all the standard boilerplate in tests, i.e. the import of the test framework and the guestfs module (including the import path hack needed for the latter). (This is the same change as fbae7f3e69ce598c52af71ec204f8dbd0a9ce5e5 in libguestfs.) --- ruby/Makefile.am | 3 ++- ruby/tests/tc_010_load.rb | 5 ++--- ruby/tests/tc_021_close.rb | 5 ++--- ruby/tests/tc_120_rlenvalue.rb | 5 ++--- ruby/tests/tc_130_special.rb | 3 +-- ruby/tests/tc_200_write.rb | 5 ++--- ruby/tests/tc_210_setvalue.rb | 5 ++--- ruby/tests/test_helper.rb | 20 ++++++++++++++++++++ 8 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 ruby/tests/test_helper.rb diff --git a/ruby/Makefile.am b/ruby/Makefile.am index 7a5fe42..0e9a868 100644 --- a/ruby/Makefile.am +++ b/ruby/Makefile.am @@ -23,7 +23,8 @@ EXTRA_DIST = \ ext/hivex/_hivex.c \ lib/hivex.rb \ run-ruby-tests \ - tests/tc_*.rb + tests/tc_*.rb \ + tests/test_helper.rb CLEANFILES = \ lib/*~ \ diff --git a/ruby/tests/tc_010_load.rb b/ruby/tests/tc_010_load.rb index 8a8ae51..a45e904 100644 --- a/ruby/tests/tc_010_load.rb +++ b/ruby/tests/tc_010_load.rb @@ -1,5 +1,5 @@ # hivex Ruby bindings -*- ruby -*- -# Copyright (C) 2009-2011 Red Hat Inc. +# Copyright (C) 2009-2014 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 @@ -15,8 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -require 'test/unit' -require 'hivex' +require File::join(File::dirname(__FILE__), 'test_helper') class TestLoad < Test::Unit::TestCase def test_load diff --git a/ruby/tests/tc_021_close.rb b/ruby/tests/tc_021_close.rb index 9c5ea65..3068e23 100644 --- a/ruby/tests/tc_021_close.rb +++ b/ruby/tests/tc_021_close.rb @@ -1,5 +1,5 @@ # hivex Ruby bindings -*- ruby -*- -# Copyright (C) 2009-2011 Red Hat Inc. +# Copyright (C) 2009-2014 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 @@ -15,8 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -require 'test/unit' -require 'hivex' +require File::join(File::dirname(__FILE__), 'test_helper') class TestClose < Test::Unit::TestCase def test_close diff --git a/ruby/tests/tc_120_rlenvalue.rb b/ruby/tests/tc_120_rlenvalue.rb index 5cb0a80..f269805 100644 --- a/ruby/tests/tc_120_rlenvalue.rb +++ b/ruby/tests/tc_120_rlenvalue.rb @@ -1,5 +1,5 @@ # hivex Ruby bindings -*- ruby -*- -# Copyright (C) 2009-2011 Red Hat Inc. +# Copyright (C) 2009-2014 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 @@ -21,8 +21,7 @@ # length and offset for this value cell should be 37 bytes, position # 8712. -require 'test/unit' -require 'hivex' +require File::join(File::dirname(__FILE__), 'test_helper') class TestRLenValue < Test::Unit::TestCase def test_RLenValue diff --git a/ruby/tests/tc_130_special.rb b/ruby/tests/tc_130_special.rb index 0623f4d..aedb543 100644 --- a/ruby/tests/tc_130_special.rb +++ b/ruby/tests/tc_130_special.rb @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- # -*- ruby -*- -require 'test/unit' -require 'hivex' +require File::join(File::dirname(__FILE__), 'test_helper') class TestRLenValue < Test::Unit::TestCase def test_RLenValue diff --git a/ruby/tests/tc_200_write.rb b/ruby/tests/tc_200_write.rb index 6ae239e..36faec2 100644 --- a/ruby/tests/tc_200_write.rb +++ b/ruby/tests/tc_200_write.rb @@ -1,5 +1,5 @@ # hivex Ruby bindings -*- ruby -*- -# Copyright (C) 2009-2011 Red Hat Inc. +# Copyright (C) 2009-2014 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 @@ -15,8 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -require 'test/unit' -require 'hivex' +require File::join(File::dirname(__FILE__), 'test_helper') class TestWrite < Test::Unit::TestCase def test_write diff --git a/ruby/tests/tc_210_setvalue.rb b/ruby/tests/tc_210_setvalue.rb index 4d1aa7e..3796dad 100644 --- a/ruby/tests/tc_210_setvalue.rb +++ b/ruby/tests/tc_210_setvalue.rb @@ -1,5 +1,5 @@ # hivex Ruby bindings -*- ruby -*- -# Copyright (C) 2009-2011 Red Hat Inc. +# Copyright (C) 2009-2014 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 @@ -15,8 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -require 'test/unit' -require 'hivex' +require File::join(File::dirname(__FILE__), 'test_helper') class TestSetValue < Test::Unit::TestCase def test_set_value diff --git a/ruby/tests/test_helper.rb b/ruby/tests/test_helper.rb new file mode 100644 index 0000000..67e1b14 --- /dev/null +++ b/ruby/tests/test_helper.rb @@ -0,0 +1,20 @@ +# hivex Ruby bindings -*- ruby -*- +# Copyright (C) 2009-2014 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. + +require 'test/unit' + +require 'hivex' -- 1.9.0
Pino Toscano
2014-Apr-23 13:19 UTC
[Libguestfs] [PATCH 2/2] ruby: tests: convert from Test::Unit to MiniTest (RHBZ#1090407)
Convert the tests to the MiniTest test framework, but keeping the usage of the old Test::Unit as fallback in case MiniTest is not available. In the latter case, use a bit of "glue" to make the old API look like the new API, so we can just rely on the newer MiniTest API. (This is the same change as 2f5e9066db817f75b245f256abc0c64dd1ae54eb in libguestfs.) --- ruby/tests/tc_010_load.rb | 4 ++-- ruby/tests/tc_021_close.rb | 4 ++-- ruby/tests/tc_120_rlenvalue.rb | 8 ++++---- ruby/tests/tc_130_special.rb | 6 +++--- ruby/tests/tc_200_write.rb | 4 ++-- ruby/tests/tc_210_setvalue.rb | 4 ++-- ruby/tests/test_helper.rb | 13 ++++++++++++- 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/ruby/tests/tc_010_load.rb b/ruby/tests/tc_010_load.rb index a45e904..76fef60 100644 --- a/ruby/tests/tc_010_load.rb +++ b/ruby/tests/tc_010_load.rb @@ -17,9 +17,9 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < Test::Unit::TestCase +class TestLoad < MiniTest::Unit::TestCase def test_load h = Hivex::open("../images/minimal", {}) - assert_not_nil (h) + refute_nil (h) end end diff --git a/ruby/tests/tc_021_close.rb b/ruby/tests/tc_021_close.rb index 3068e23..38b88a9 100644 --- a/ruby/tests/tc_021_close.rb +++ b/ruby/tests/tc_021_close.rb @@ -17,10 +17,10 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestClose < Test::Unit::TestCase +class TestClose < MiniTest::Unit::TestCase def test_close h = Hivex::open("../images/minimal", {}) - assert_not_nil (h) + refute_nil (h) h.close() end end diff --git a/ruby/tests/tc_120_rlenvalue.rb b/ruby/tests/tc_120_rlenvalue.rb index f269805..6c03f43 100644 --- a/ruby/tests/tc_120_rlenvalue.rb +++ b/ruby/tests/tc_120_rlenvalue.rb @@ -23,16 +23,16 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestRLenValue < Test::Unit::TestCase +class TestRLenValue < MiniTest::Unit::TestCase def test_RLenValue h = Hivex::open(File::join(ENV['abs_srcdir'], '..', 'images', 'rlenvalue_test_hive'), {}) - assert_not_nil(h) + refute_nil(h) root = h.root() - assert_not_nil(root) + refute_nil(root) moderate_value_node = h.node_get_child(root, "ModerateValueParent") - assert_not_nil(moderate_value_node) + refute_nil(moderate_value_node) moderate_value_value = h.node_get_value(moderate_value_node, "33Bytes") diff --git a/ruby/tests/tc_130_special.rb b/ruby/tests/tc_130_special.rb index aedb543..282b288 100644 --- a/ruby/tests/tc_130_special.rb +++ b/ruby/tests/tc_130_special.rb @@ -3,13 +3,13 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestRLenValue < Test::Unit::TestCase +class TestRLenValue < MiniTest::Unit::TestCase def test_RLenValue h = Hivex::open(File::join(ENV['abs_srcdir'], '..', 'images', 'special'), {}) - assert_not_nil(h) + refute_nil(h) root = h.root() - assert_not_nil(root) + refute_nil(root) nodes = h.node_children (root) node = nodes.find { |n| h.node_name(n) == "abcd_äöüß" } diff --git a/ruby/tests/tc_200_write.rb b/ruby/tests/tc_200_write.rb index 36faec2..327d0a8 100644 --- a/ruby/tests/tc_200_write.rb +++ b/ruby/tests/tc_200_write.rb @@ -17,10 +17,10 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestWrite < Test::Unit::TestCase +class TestWrite < MiniTest::Unit::TestCase def test_write h = Hivex::open("../images/minimal", {:write => 1}) - assert_not_nil (h) + refute_nil (h) root = h.root() assert (root) diff --git a/ruby/tests/tc_210_setvalue.rb b/ruby/tests/tc_210_setvalue.rb index 3796dad..62ffd99 100644 --- a/ruby/tests/tc_210_setvalue.rb +++ b/ruby/tests/tc_210_setvalue.rb @@ -17,10 +17,10 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestSetValue < Test::Unit::TestCase +class TestSetValue < MiniTest::Unit::TestCase def test_set_value h = Hivex::open("../images/minimal", {:write => 1}) - assert_not_nil (h) + refute_nil (h) root = h.root() assert (root) diff --git a/ruby/tests/test_helper.rb b/ruby/tests/test_helper.rb index 67e1b14..f939b94 100644 --- a/ruby/tests/test_helper.rb +++ b/ruby/tests/test_helper.rb @@ -15,6 +15,17 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -require 'test/unit' +begin + require 'minitest/autorun' +rescue LoadError + require 'test/unit' + MiniTest = Test + module Test + Assertions = Unit::Assertions + module Assertions + alias refute_nil assert_not_nil + end + end +end require 'hivex' -- 1.9.0
Richard W.M. Jones
2014-Apr-23 13:28 UTC
Re: [Libguestfs] [HIVEX] port ruby tests to MiniTest (#1090407)
Thanks for doing this, ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top