From 3c43019f8df837f3c0c4325679d46cbb336eced2 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 30 Apr 2013 17:41:05 +0100 Subject: [PATCH] ruby: Standardize test names and numbering. --- ruby/Makefile.am | 4 +- ruby/Rakefile.in | 4 +- ruby/run-ruby-tests | 2 +- ruby/{tests => t}/tc_010_load.rb | 4 +- ruby/t/tc_020_create.rb | 28 ++++++++++++ .../tc_060_optargs.rb => t/tc_070_optargs.rb} | 0 .../tc_050_lvcreate.rb => t/tc_100_launch.rb} | 4 +- ruby/t/tc_410_close_event.rb | 43 +++++++++++++++++++ .../tc_420_log_messages.rb} | 20 +++------ .../tc_800_rhbz507346.rb} | 0 .../tc_810_rhbz664558c6.rb} | 0 11 files changed, 84 insertions(+), 25 deletions(-) rename ruby/{tests => t}/tc_010_load.rb (92%) create mode 100644 ruby/t/tc_020_create.rb rename ruby/{tests/tc_060_optargs.rb => t/tc_070_optargs.rb} (100%) rename ruby/{tests/tc_050_lvcreate.rb => t/tc_100_launch.rb} (96%) create mode 100644 ruby/t/tc_410_close_event.rb rename ruby/{tests/tc_400_events.rb => t/tc_420_log_messages.rb} (79%) rename ruby/{tests/tc_rhbz507346.rb => t/tc_800_rhbz507346.rb} (100%) rename ruby/{tests/tc_rhbz664558c6.rb => t/tc_810_rhbz664558c6.rb} (100%) diff --git a/ruby/Makefile.am b/ruby/Makefile.am index 0faa2e0e6..0c4ee5a4b 100644 --- a/ruby/Makefile.am +++ b/ruby/Makefile.am @@ -32,11 +32,11 @@ EXTRA_DIST = \ lib/guestfs.rb \ run-bindtests \ run-ruby-tests \ - tests/tc_*.rb + t/tc_*.rb CLEANFILES = \ lib/*~ \ - tests/*~ \ + t/*~ \ ext/guestfs/*~ \ ext/guestfs/extconf.h \ ext/guestfs/_guestfs.o \ diff --git a/ruby/Rakefile.in b/ruby/Rakefile.in index a74e19189..631757538 100644 --- a/ruby/Rakefile.in +++ b/ruby/Rakefile.in @@ -70,7 +70,7 @@ desc "Build the native library" task :build => GUESTFS_MODULE Rake::TestTask.new(:test) do |t| - t.test_files = FileList['tests/tc_*.rb'] + t.test_files = FileList['t/tc_*.rb'] t.libs = [ 'lib', 'ext/guestfs' ] end task :test => :build @@ -100,7 +100,7 @@ PKG_FILES = FileList[ "Rakefile", "COPYING", "README", "NEWS", "@srcdir@/README.rdoc", "lib/**/*.rb", "ext/**/*.[ch]", "ext/**/MANIFEST", "ext/**/extconf.rb", - "tests/**/*", + "t/**/*", "spec/**/*" ] diff --git a/ruby/run-ruby-tests b/ruby/run-ruby-tests index c618241f8..ac18ea35a 100755 --- a/ruby/run-ruby-tests +++ b/ruby/run-ruby-tests @@ -21,7 +21,7 @@ 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 +for f in t/tc_*.rb; do echo $RAKE test "$@" TEST="$f" $RAKE test "$@" TEST="$f" done diff --git a/ruby/tests/tc_010_load.rb b/ruby/t/tc_010_load.rb similarity index 92% rename from ruby/tests/tc_010_load.rb rename to ruby/t/tc_010_load.rb index 80c1e0302..4274d5abb 100644 --- a/ruby/tests/tc_010_load.rb +++ b/ruby/t/tc_010_load.rb @@ -1,5 +1,5 @@ # libguestfs Ruby bindings -*- ruby -*- -# Copyright (C) 2009 Red Hat Inc. +# Copyright (C) 2009-2013 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 @@ -22,7 +22,5 @@ require 'guestfs' class TestLoad < Test::Unit::TestCase def test_load - g = Guestfs::create() - assert_not_nil (g) end end diff --git a/ruby/t/tc_020_create.rb b/ruby/t/tc_020_create.rb new file mode 100644 index 000000000..2b57ba106 --- /dev/null +++ b/ruby/t/tc_020_create.rb @@ -0,0 +1,28 @@ +# libguestfs Ruby bindings -*- ruby -*- +# Copyright (C) 2009-2013 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. + +require 'test/unit' +$:.unshift(File::join(File::dirname(__FILE__), "..", "lib")) +$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "guestfs")) +require 'guestfs' + +class TestLoad < Test::Unit::TestCase + def test_create + g = Guestfs::create() + assert_not_nil (g) + end +end diff --git a/ruby/tests/tc_060_optargs.rb b/ruby/t/tc_070_optargs.rb similarity index 100% rename from ruby/tests/tc_060_optargs.rb rename to ruby/t/tc_070_optargs.rb diff --git a/ruby/tests/tc_050_lvcreate.rb b/ruby/t/tc_100_launch.rb similarity index 96% rename from ruby/tests/tc_050_lvcreate.rb rename to ruby/t/tc_100_launch.rb index 4e9c95793..4bd8187cb 100644 --- a/ruby/tests/tc_050_lvcreate.rb +++ b/ruby/t/tc_100_launch.rb @@ -1,5 +1,5 @@ # libguestfs Ruby bindings -*- ruby -*- -# Copyright (C) 2009 Red Hat Inc. +# Copyright (C) 2009-2013 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,7 +21,7 @@ $:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "guestfs")) require 'guestfs' class TestLoad < Test::Unit::TestCase - def test_lvcreate + def test_launch g = Guestfs::create() File.open("test.img", "w") { diff --git a/ruby/t/tc_410_close_event.rb b/ruby/t/tc_410_close_event.rb new file mode 100644 index 000000000..ebf4bbc28 --- /dev/null +++ b/ruby/t/tc_410_close_event.rb @@ -0,0 +1,43 @@ +# libguestfs Ruby bindings -*- ruby -*- +# Copyright (C) 2011-2013 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. + +require 'test/unit' +$:.unshift(File::join(File::dirname(__FILE__), "..", "lib")) +$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "guestfs")) +require 'guestfs' + +class TestLoad < Test::Unit::TestCase + def test_events + g = Guestfs::create() + + close_invoked = 0 + close = Proc.new {| event, event_handle, buf, array | + close_invoked += 1 + } + + # Check that the close event is called. + g.set_event_callback(close, Guestfs::EVENT_CLOSE) + + if close_invoked != 0 + raise "close_invoked should be 0" + end + g.close() + if close_invoked != 1 + raise "close_invoked should be 1" + end + end +end diff --git a/ruby/tests/tc_400_events.rb b/ruby/t/tc_420_log_messages.rb similarity index 79% rename from ruby/tests/tc_400_events.rb rename to ruby/t/tc_420_log_messages.rb index 7c911c436..d23a0fbbc 100644 --- a/ruby/tests/tc_400_events.rb +++ b/ruby/t/tc_420_log_messages.rb @@ -1,5 +1,5 @@ # libguestfs Ruby bindings -*- ruby -*- -# Copyright (C) 2011 Red Hat Inc. +# Copyright (C) 2011-2013 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 @@ -24,7 +24,9 @@ class TestLoad < Test::Unit::TestCase def test_events g = Guestfs::create() + log_invoked = 0 log = Proc.new {| event, event_handle, buf, array | + log_invoked += 1 if event == Guestfs::EVENT_APPLIANCE buf.chomp! end @@ -32,20 +34,11 @@ class TestLoad < Test::Unit::TestCase puts "ruby event logged: event=#{event_string} eh=#{event_handle} buf='#{buf}' array=#{array}" } - close_invoked = 0 - close = Proc.new {| event, event_handle, buf, array | - close_invoked += 1 - log.call(event, event_handle, buf, array) - } - # Grab log, trace and daemon messages into our custom callback. event_bitmask = Guestfs::EVENT_APPLIANCE | Guestfs::EVENT_LIBRARY | Guestfs::EVENT_TRACE g.set_event_callback(log, event_bitmask) - # Check that the close event is called. - g.set_event_callback(close, Guestfs::EVENT_CLOSE) - # Make sure we see some messages. g.set_trace(1) g.set_verbose(1) @@ -54,12 +47,9 @@ class TestLoad < Test::Unit::TestCase g.add_drive_ro("/dev/null") g.set_autosync(1) - if close_invoked != 0 - raise "close_invoked should be 0" - end g.close() - if close_invoked != 1 - raise "close_invoked should be 1" + if log_invoked == 0 + raise "log_invoked should be > 0" end end end diff --git a/ruby/tests/tc_rhbz507346.rb b/ruby/t/tc_800_rhbz507346.rb similarity index 100% rename from ruby/tests/tc_rhbz507346.rb rename to ruby/t/tc_800_rhbz507346.rb diff --git a/ruby/tests/tc_rhbz664558c6.rb b/ruby/t/tc_810_rhbz664558c6.rb similarity index 100% rename from ruby/tests/tc_rhbz664558c6.rb rename to ruby/t/tc_810_rhbz664558c6.rb