Richard W.M. Jones
2016-Jun-07 21:35 UTC
[Libguestfs] [PATCH 1/2] ruby: Print exceptions thrown by event callbacks.
--- generator/ruby.ml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/generator/ruby.ml b/generator/ruby.ml index 97ccfdc..0f71ccc 100644 --- a/generator/ruby.ml +++ b/generator/ruby.ml @@ -404,15 +404,17 @@ event_callback_wrapper_wrapper (VALUE argvv) return Qnil; } +/* Callbacks aren't supposed to throw exceptions. We just print the + * exception on stderr and hope for the best. + */ static VALUE event_callback_handle_exception (VALUE not_used, VALUE exn) { - /* Callbacks aren't supposed to throw exceptions. */ - fprintf (stderr, \"libguestfs: exception in callback!\\n\"); + volatile VALUE message; - /* XXX We could print the exception, but it's very difficult from - * a Ruby extension. - */ + message = rb_funcall (exn, rb_intern (\"to_s\"), 0); + fprintf (stderr, \"libguestfs: exception in callback: %%s\\n\", + StringValueCStr (message)); return Qnil; } -- 2.7.4
Richard W.M. Jones
2016-Jun-07 21:35 UTC
[Libguestfs] [PATCH 2/2] ruby: tests: Give each test class and method a unique name.
'tc_410_close_event.rb' was not being run. You could prove this by simply inserting "exit 1" into that test. The reason is unclear, but by renaming every class and method in the tests to be unique, this ensures the tests are run. --- ruby/t/tc_010_load.rb | 4 ++-- ruby/t/tc_020_create.rb | 4 ++-- ruby/t/tc_030_create_flags.rb | 4 ++-- ruby/t/tc_040_create_multiple.rb | 4 ++-- ruby/t/tc_050_handle_properties.rb | 4 ++-- ruby/t/tc_060_explicit_close.rb | 4 ++-- ruby/t/tc_070_optargs.rb | 4 ++-- ruby/t/tc_090_retvalues.rb | 4 ++-- ruby/t/tc_100_launch.rb | 4 ++-- ruby/t/tc_410_close_event.rb | 4 ++-- ruby/t/tc_420_log_messages.rb | 4 ++-- ruby/t/tc_800_rhbz507346.rb | 4 ++-- ruby/t/tc_810_rhbz664558c6.rb | 4 ++-- ruby/t/tc_820_rhbz1046509.rb | 4 ++-- 14 files changed, 28 insertions(+), 28 deletions(-) diff --git a/ruby/t/tc_010_load.rb b/ruby/t/tc_010_load.rb index 2ec0314..06922e1 100644 --- a/ruby/t/tc_010_load.rb +++ b/ruby/t/tc_010_load.rb @@ -17,7 +17,7 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_load +class Test010Load < MiniTest::Unit::TestCase + def test_010_load end end diff --git a/ruby/t/tc_020_create.rb b/ruby/t/tc_020_create.rb index a2a01a1..251512b 100644 --- a/ruby/t/tc_020_create.rb +++ b/ruby/t/tc_020_create.rb @@ -17,8 +17,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_create +class Test020Create < MiniTest::Unit::TestCase + def test_020_create g = Guestfs::Guestfs.new() refute_nil (g) end diff --git a/ruby/t/tc_030_create_flags.rb b/ruby/t/tc_030_create_flags.rb index 405326f..c89d3ac 100644 --- a/ruby/t/tc_030_create_flags.rb +++ b/ruby/t/tc_030_create_flags.rb @@ -17,8 +17,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_create_flags +class Test030CreateFlags < MiniTest::Unit::TestCase + def test_030_create_flags g = Guestfs::Guestfs.new(:environment => false, :close_on_exit => true) refute_nil (g) g.parse_environment() diff --git a/ruby/t/tc_040_create_multiple.rb b/ruby/t/tc_040_create_multiple.rb index 16c67d3..e832989 100644 --- a/ruby/t/tc_040_create_multiple.rb +++ b/ruby/t/tc_040_create_multiple.rb @@ -17,8 +17,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_create_multiple +class Test040CreateMultiple < MiniTest::Unit::TestCase + def test_040_create_multiple g1 = Guestfs::Guestfs.new() g2 = Guestfs::Guestfs.new() g3 = Guestfs::Guestfs.new() diff --git a/ruby/t/tc_050_handle_properties.rb b/ruby/t/tc_050_handle_properties.rb index bcf3406..d8fddb0 100644 --- a/ruby/t/tc_050_handle_properties.rb +++ b/ruby/t/tc_050_handle_properties.rb @@ -17,8 +17,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_handle_properties +class Test050HandleProperties < MiniTest::Unit::TestCase + def test_050_handle_properties g = Guestfs::Guestfs.new() refute_nil (g) v = g.get_verbose() diff --git a/ruby/t/tc_060_explicit_close.rb b/ruby/t/tc_060_explicit_close.rb index a4effd5..37e09f4 100644 --- a/ruby/t/tc_060_explicit_close.rb +++ b/ruby/t/tc_060_explicit_close.rb @@ -17,8 +17,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_explicit_close +class Test060ExplicitClose < MiniTest::Unit::TestCase + def test_060_explicit_close g = Guestfs::Guestfs.new() refute_nil (g) g.close() diff --git a/ruby/t/tc_070_optargs.rb b/ruby/t/tc_070_optargs.rb index b08220d..d24aebd 100644 --- a/ruby/t/tc_070_optargs.rb +++ b/ruby/t/tc_070_optargs.rb @@ -17,8 +17,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_optargs +class Test070Optargs < MiniTest::Unit::TestCase + def test_070_optargs g = Guestfs::Guestfs.new() g.add_drive("/dev/null", {}) diff --git a/ruby/t/tc_090_retvalues.rb b/ruby/t/tc_090_retvalues.rb index 1fcc12d..4bcc8b5 100644 --- a/ruby/t/tc_090_retvalues.rb +++ b/ruby/t/tc_090_retvalues.rb @@ -17,8 +17,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_rint +class Test090RetValues < MiniTest::Unit::TestCase + def test_090_retvalues g = Guestfs::Guestfs.new() assert_equal 10, g.internal_test_rint("10") diff --git a/ruby/t/tc_100_launch.rb b/ruby/t/tc_100_launch.rb index b79b984..1f89023 100644 --- a/ruby/t/tc_100_launch.rb +++ b/ruby/t/tc_100_launch.rb @@ -17,8 +17,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_launch +class Test100Launch < MiniTest::Unit::TestCase + def test_100_launch g = Guestfs::Guestfs.new() g.add_drive_scratch(500*1024*1024) diff --git a/ruby/t/tc_410_close_event.rb b/ruby/t/tc_410_close_event.rb index be62b91..b77d44f 100644 --- a/ruby/t/tc_410_close_event.rb +++ b/ruby/t/tc_410_close_event.rb @@ -17,8 +17,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_events +class Test410CloseEvent < MiniTest::Unit::TestCase + def test_410_close_event g = Guestfs::Guestfs.new() close_invoked = 0 diff --git a/ruby/t/tc_420_log_messages.rb b/ruby/t/tc_420_log_messages.rb index e64ea74..44355fd 100644 --- a/ruby/t/tc_420_log_messages.rb +++ b/ruby/t/tc_420_log_messages.rb @@ -17,8 +17,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_events +class Test420LogMessages < MiniTest::Unit::TestCase + def test_420_log_messages g = Guestfs::Guestfs.new() log_invoked = 0 diff --git a/ruby/t/tc_800_rhbz507346.rb b/ruby/t/tc_800_rhbz507346.rb index eb516fb..60dd345 100644 --- a/ruby/t/tc_800_rhbz507346.rb +++ b/ruby/t/tc_800_rhbz507346.rb @@ -17,8 +17,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_rhbz507346 +class Test800RHBZ507346 < MiniTest::Unit::TestCase + def test_800_rhbz507346 g = Guestfs::Guestfs.new() g.add_drive_scratch(10*1024*1024) g.launch() diff --git a/ruby/t/tc_810_rhbz664558c6.rb b/ruby/t/tc_810_rhbz664558c6.rb index 347e403..dc7e9e4 100644 --- a/ruby/t/tc_810_rhbz664558c6.rb +++ b/ruby/t/tc_810_rhbz664558c6.rb @@ -21,8 +21,8 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase - def test_rhbz664558c6 +class Test810RHBZ664558C6 < MiniTest::Unit::TestCase + def test_810_rhbz_664558c6 g = Guestfs::Guestfs.new() close_invoked = 0 diff --git a/ruby/t/tc_820_rhbz1046509.rb b/ruby/t/tc_820_rhbz1046509.rb index c15f7a7..eb06eab 100644 --- a/ruby/t/tc_820_rhbz1046509.rb +++ b/ruby/t/tc_820_rhbz1046509.rb @@ -20,13 +20,13 @@ require File::join(File::dirname(__FILE__), 'test_helper') -class TestLoad < MiniTest::Unit::TestCase +class Test820RHBZ1046509 < MiniTest::Unit::TestCase def _handleok(g) g.add_drive("/dev/null") g.close() end - def test_rhbz1046509 + def test_820_rhbz1046509 g = Guestfs::create() _handleok(g) -- 2.7.4
Pino Toscano
2016-Jun-10 13:10 UTC
Re: [Libguestfs] [PATCH 2/2] ruby: tests: Give each test class and method a unique name.
In data martedì 7 giugno 2016 22:35:33, Richard W.M. Jones ha scritto:> 'tc_410_close_event.rb' was not being run. You could prove this by > simply inserting "exit 1" into that test. > > The reason is unclear, but by renaming every class and method in the > tests to be unique, this ensures the tests are run. > ---ruby/t/tc_410_close_event.rb: def test_events ruby/t/tc_420_log_messages.rb: def test_events This explains: all the tests have TestLoad as class name, and these two tests have the same method name. IMHO renaming just the class names should be enough, but this patch is fine as well. Thanks, -- Pino Toscano
Seemingly Similar Threads
- [PATCH 1/2] ruby: Print exceptions thrown by event callbacks.
- Re: [PATCH 2/2] ruby: tests: Give each test class and method a unique name.
- [PATCH 2/2] ruby: tests: Give each test class and method a unique name.
- [PATCH] ruby: Fix .new method (RHBZ#1046509).
- [PATCH 1/2] Revert "ruby: Run tests one at a time, instead of in parallel."