ruby: Standardize test names and numbering.

This commit is contained in:
Richard W.M. Jones
2013-04-30 17:41:05 +01:00
parent a24639d7d3
commit 3c43019f8d
11 changed files with 84 additions and 25 deletions

View File

@@ -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 \

View File

@@ -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/**/*"
]

View File

@@ -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

View File

@@ -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

28
ruby/t/tc_020_create.rb Normal file
View File

@@ -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

View File

@@ -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") {

View File

@@ -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

View File

@@ -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