aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-06 20:13:49 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-06 20:13:49 +0000
commita9e23d28d8a7e10b265ed9280b94e98317d83977 (patch)
tree97e37bef588c685be0b7a99f915e02d063ca09cf
parent27715dabdd3a71a14a162370200938598911879b (diff)
downloadpaludis-a9e23d28d8a7e10b265ed9280b94e98317d83977.tar.gz
paludis-a9e23d28d8a7e10b265ed9280b94e98317d83977.tar.xz
(ruby) SuppotsInstallActionTest.new -> SupportsActionTest.new(InstallAction)
-rw-r--r--doc/api/ruby/example_action.rb4
-rw-r--r--doc/api/ruby/example_package_id.rb14
-rw-r--r--ruby/action.cc185
-rw-r--r--ruby/action_TEST.rb39
-rwxr-xr-xruby/demos/find_unmanaged_files.rb4
-rw-r--r--ruby/package_id_TEST.rb2
-rw-r--r--ruby/repository_TEST.rb8
7 files changed, 66 insertions, 190 deletions
diff --git a/doc/api/ruby/example_action.rb b/doc/api/ruby/example_action.rb
index f1d754e..bd3695a 100644
--- a/doc/api/ruby/example_action.rb
+++ b/doc/api/ruby/example_action.rb
@@ -22,9 +22,9 @@ ids = env[Selection::AllVersionsSorted.new(Generator::Matches.new(
# For each ID:
ids.each do | id |
- # Do we support a FetchAction? We find out by creating a SupportsFetchActionTest object, and
+ # Do we support a FetchAction? We find out by creating a SupportsActionTest object, and
# querying via the PackageID#supports_action method.
- supports_fetch_action = SupportsFetchActionTest.new
+ supports_fetch_action = SupportsActionTest.new(FetchAction)
if not id.supports_action(supports_fetch_action)
puts "ID #{id} does not support the fetch action."
else
diff --git a/doc/api/ruby/example_package_id.rb b/doc/api/ruby/example_package_id.rb
index 8fa10a9..da841eb 100644
--- a/doc/api/ruby/example_package_id.rb
+++ b/doc/api/ruby/example_package_id.rb
@@ -58,13 +58,13 @@ ids.each do | id |
# way of doing this, since it's not something we'd expect to be
# doing.
actions = []
- actions << "install" if id.supports_action(SupportsInstallActionTest.new)
- actions << "installed" if id.supports_action(SupportsInstalledActionTest.new)
- actions << "uninstall" if id.supports_action(SupportsUninstallActionTest.new)
- actions << "pretend" if id.supports_action(SupportsPretendActionTest.new)
- actions << "config" if id.supports_action(SupportsConfigActionTest.new)
- actions << "fetch" if id.supports_action(SupportsFetchActionTest.new)
- actions << "info" if id.supports_action(SupportsInfoActionTest.new)
+ actions << "install" if id.supports_action(SupportsActionTest.new(InstallAction))
+ actions << "installed" if id.supports_action(SupportsActionTest.new(InstalledAction))
+ actions << "uninstall" if id.supports_action(SupportsActionTest.new(UninstallAction))
+ actions << "pretend" if id.supports_action(SupportsActionTest.new(PretendAction))
+ actions << "config" if id.supports_action(SupportsActionTest.new(ConfigAction))
+ actions << "fetch" if id.supports_action(SupportsActionTest.new(FetchAction))
+ actions << "info" if id.supports_action(SupportsActionTest.new(InfoAction))
puts " Actions: ".ljust(40) + actions.join(' ')
diff --git a/ruby/action.cc b/ruby/action.cc
index c846f39..fee69b2 100644
--- a/ruby/action.cc
+++ b/ruby/action.cc
@@ -22,6 +22,7 @@
#include <paludis/action.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/kc.hh>
+#include <paludis/util/make_shared_ptr.hh>
#include <ruby.h>
using namespace paludis;
@@ -31,14 +32,7 @@ using namespace paludis::ruby;
namespace
{
- static VALUE c_supports_action_test_base;
- static VALUE c_supports_fetch_action_test;
- static VALUE c_supports_info_action_test;
- static VALUE c_supports_config_action_test;
- static VALUE c_supports_install_action_test;
- static VALUE c_supports_uninstall_action_test;
- static VALUE c_supports_pretend_action_test;
- static VALUE c_supports_installed_action_test;
+ static VALUE c_supports_action_test;
static VALUE c_action;
static VALUE c_fetch_action;
@@ -188,74 +182,49 @@ namespace
}
/*
- * Document-method: SupportsFetchActionTest.new
+ * Document-method: SupportsActionTest.new
*
* call-seq:
- * SupportsFetchActionTest.new -> SupportsFetchActionTest
+ * SupportsActionTest.new(ActionClass) -> SupportsActionTest
*
- * Create new SupportsFetchActionTest object.
+ * Create new SupportsActionTest object. The ActionClass should be, e.g. InstallAction.
*/
- /*
- * Document-method: SupportsInfoActionTest.new
- *
- * call-seq:
- * SupportsInfoActionTest.new -> SupportsInfoActionTest
- *
- * Create new SupportsInfoActionTest object.
- */
- /*
- * Document-method: SupportsConfigActionTest.new
- *
- * call-seq:
- * SupportsConfigActionTest.new -> SupportsInfoActionTest
- *
- * Create new SupportsConfigActionTest object.
- */
- /*
- * Document-method: SupportsInstallActionTest.new
- *
- * call-seq:
- * SupportsInstallActionTest.new -> SupportsInstallActionTest
- *
- * Create new SupportsInstallActionTest object.
- */
- /*
- * Document-method: SupportsUninstallActionTest.new
- *
- * call-seq:
- * SupportsUninstallActionTest.new -> SupportsUninstallActionTest
- *
- * Create new SupportsUninstallActionTest object.
- */
- /*
- * Document-method: SupportsPretendActionTest.new
- *
- * call-seq:
- * SupportsPretendActionTest.new -> SupportsPretendActionTest
- *
- * Create new SupportsPretendActionTest object.
- */
- /*
- * Document-method: SupportsInstalledActionTest.new
- *
- * call-seq:
- * SupportsInstalledActionTest.new -> SupportsInstalledActionTest
- *
- * Create new SupportsInstalledActionTest object.
- */
- template <typename A_>
- struct SupportsActionTestNew
+ static VALUE
+ supports_action_test_new(VALUE self, VALUE action_class)
{
- static VALUE
- supports_action_test_new(VALUE self)
+ std::tr1::shared_ptr<const SupportsActionTestBase> * ptr(0);
+
+ try
{
- std::tr1::shared_ptr<const SupportsActionTestBase> * a(
- new std::tr1::shared_ptr<const SupportsActionTestBase>(new SupportsActionTest<A_>));
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<std::tr1::shared_ptr<const SupportsActionTestBase> >::free, a));
+ if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, install_action_value_ptr()))
+ ptr = new std::tr1::shared_ptr<const SupportsActionTestBase>(make_shared_ptr(new SupportsActionTest<InstallAction>()));
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, installed_action_value_ptr()))
+ ptr = new std::tr1::shared_ptr<const SupportsActionTestBase>(make_shared_ptr(new SupportsActionTest<InstalledAction>()));
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, uninstall_action_value_ptr()))
+ ptr = new std::tr1::shared_ptr<const SupportsActionTestBase>(make_shared_ptr(new SupportsActionTest<UninstallAction>()));
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, pretend_action_value_ptr()))
+ ptr = new std::tr1::shared_ptr<const SupportsActionTestBase>(make_shared_ptr(new SupportsActionTest<PretendAction>()));
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, config_action_value_ptr()))
+ ptr = new std::tr1::shared_ptr<const SupportsActionTestBase>(make_shared_ptr(new SupportsActionTest<ConfigAction>()));
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, fetch_action_value_ptr()))
+ ptr = new std::tr1::shared_ptr<const SupportsActionTestBase>(make_shared_ptr(new SupportsActionTest<FetchAction>()));
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, info_action_value_ptr()))
+ ptr = new std::tr1::shared_ptr<const SupportsActionTestBase>(make_shared_ptr(new SupportsActionTest<InfoAction>()));
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, pretend_fetch_action_value_ptr()))
+ ptr = new std::tr1::shared_ptr<const SupportsActionTestBase>(make_shared_ptr(new SupportsActionTest<PretendFetchAction>()));
+ else
+ rb_raise(rb_eTypeError, "Can't convert %s into an Action subclass", rb_obj_classname(action_class));
+
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<std::tr1::shared_ptr<const SupportsActionTestBase> >::free, ptr));
rb_obj_call_init(tdata, 0, &self);
return tdata;
}
- };
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
/*
* call-seq:
@@ -775,82 +744,12 @@ namespace
void do_register_action()
{
/*
- * Document-class: Paludis::SupportsActionTestBase
- *
- * Base class for action tests, used by Paludis::PackageID#supports_action.
- */
- c_supports_action_test_base = rb_define_class_under(paludis_module(), "SupportsActionTestBase", rb_cObject);
- rb_funcall(c_supports_action_test_base, rb_intern("private_class_method"), 1, rb_str_new2("new"));
-
- /*
- * Document-class: Paludis::SupportsFetchActionTest
- *
- * Tests whether a Paludis::PackageID supports a Paludis::FetchAction.
- */
- c_supports_fetch_action_test = rb_define_class_under(paludis_module(), "SupportsFetchActionTest", c_supports_action_test_base);
- rb_define_singleton_method(c_supports_fetch_action_test, "new",
- RUBY_FUNC_CAST((&SupportsActionTestNew<FetchAction>::supports_action_test_new)), 0);
- rb_define_method(c_supports_fetch_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
-
- /*
- * Document-class: Paludis::SupportsInfoActionTest
- *
- * Tests whether a Paludis::PackageID supports a Paludis::InfoAction.
- */
- c_supports_info_action_test = rb_define_class_under(paludis_module(), "SupportsInfoActionTest", c_supports_action_test_base);
- rb_define_singleton_method(c_supports_info_action_test, "new",
- RUBY_FUNC_CAST((&SupportsActionTestNew<InfoAction>::supports_action_test_new)), 0);
- rb_define_method(c_supports_info_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
-
- /*
- * Document-class: Paludis::SupportsConfigActionTest
- *
- * Tests whether a Paludis::PackageID supports a Paludis::ConfigAction.
- */
- c_supports_config_action_test = rb_define_class_under(paludis_module(), "SupportsConfigActionTest", c_supports_action_test_base);
- rb_define_singleton_method(c_supports_config_action_test, "new",
- RUBY_FUNC_CAST((&SupportsActionTestNew<ConfigAction>::supports_action_test_new)), 0);
- rb_define_method(c_supports_config_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
-
- /*
- * Document-class: Paludis::SupportsInstallActionTest
- *
- * Tests whether a Paludis::PackageID supports a Paludis::InstallAction.
- */
- c_supports_install_action_test = rb_define_class_under(paludis_module(), "SupportsInstallActionTest", c_supports_action_test_base);
- rb_define_singleton_method(c_supports_install_action_test, "new",
- RUBY_FUNC_CAST((&SupportsActionTestNew<InstallAction>::supports_action_test_new)), 0);
- rb_define_method(c_supports_install_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
-
- /*
- * Document-class: Paludis::SupportsUninstallActionTest
- *
- * Tests whether a Paludis::PackageID supports a Paludis::UninstallAction.
- */
- c_supports_uninstall_action_test = rb_define_class_under(paludis_module(), "SupportsUninstallActionTest", c_supports_action_test_base);
- rb_define_singleton_method(c_supports_uninstall_action_test, "new",
- RUBY_FUNC_CAST((&SupportsActionTestNew<UninstallAction>::supports_action_test_new)), 0);
- rb_define_method(c_supports_uninstall_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
-
- /*
- * Document-class: Paludis::SupportsPretendActionTest
- *
- * Tests whether a Paludis::PackageID supports a Paludis::PretendAction.
- */
- c_supports_pretend_action_test = rb_define_class_under(paludis_module(), "SupportsPretendActionTest", c_supports_action_test_base);
- rb_define_singleton_method(c_supports_pretend_action_test, "new",
- RUBY_FUNC_CAST((&SupportsActionTestNew<PretendAction>::supports_action_test_new)), 0);
- rb_define_method(c_supports_pretend_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
-
- /*
- * Document-class: Paludis::SupportsInstalledActionTest
+ * Document-class: Paludis::SupportsActionTest
*
- * Tests whether a Paludis::PackageID supports a Paludis::InstalledAction.
+ * Tests whether a Paludis::PackageID supports a particular action.
*/
- c_supports_installed_action_test = rb_define_class_under(paludis_module(), "SupportsInstalledActionTest", c_supports_action_test_base);
- rb_define_singleton_method(c_supports_installed_action_test, "new",
- RUBY_FUNC_CAST((&SupportsActionTestNew<InstalledAction>::supports_action_test_new)), 0);
- rb_define_method(c_supports_installed_action_test, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
+ c_supports_action_test = rb_define_class_under(paludis_module(), "SupportsActionTest", rb_cObject);
+ rb_define_singleton_method(c_supports_action_test, "new", RUBY_FUNC_CAST(&supports_action_test_new), 1);
/*
* Document-class: Paludis::Action
@@ -1026,7 +925,7 @@ namespace
std::tr1::shared_ptr<const SupportsActionTestBase>
paludis::ruby::value_to_supports_action_test_base(VALUE v)
{
- if (rb_obj_is_kind_of(v, c_supports_action_test_base))
+ if (rb_obj_is_kind_of(v, c_supports_action_test))
{
std::tr1::shared_ptr<const SupportsActionTestBase> * v_ptr;
Data_Get_Struct(v, std::tr1::shared_ptr<const SupportsActionTestBase>, v_ptr);
@@ -1034,7 +933,7 @@ paludis::ruby::value_to_supports_action_test_base(VALUE v)
}
else
{
- rb_raise(rb_eTypeError, "Can't convert %s into SupportsActionTestBase", rb_obj_classname(v));
+ rb_raise(rb_eTypeError, "Can't convert %s into SupportsActionTest", rb_obj_classname(v));
}
}
diff --git a/ruby/action_TEST.rb b/ruby/action_TEST.rb
index c2382a2..c3ca9e3 100644
--- a/ruby/action_TEST.rb
+++ b/ruby/action_TEST.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# vim: set sw=4 sts=4 et tw=80 :
#
-# Copyright (c) 2007 Ciaran McCreesh
+# Copyright (c) 2007, 2008 Ciaran McCreesh
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
@@ -45,68 +45,45 @@ module Paludis
end
end
- class TestCase_SupportsActionTestBase < Test::Unit::TestCase
- def test_no_create
- assert_raise NoMethodError do
- ce = SupportsActionTestBase.new('test')
- end
- end
- end
-
class TestCase_SupportsFetchActionTest < Test::Unit::TestCase
def test_create
- assert_kind_of SupportsFetchActionTest, SupportsFetchActionTest.new
- assert_kind_of SupportsActionTestBase, SupportsFetchActionTest.new
+ assert_kind_of SupportsActionTest, SupportsActionTest.new(FetchAction)
end
end
class TestCase_SupportsInfoActionTest < Test::Unit::TestCase
def test_create
- assert_kind_of SupportsInfoActionTest, SupportsInfoActionTest.new
- assert_kind_of SupportsActionTestBase, SupportsInfoActionTest.new
+ assert_kind_of SupportsActionTest, SupportsActionTest.new(InfoAction)
end
end
class TestCase_SupportsConfigActionTest < Test::Unit::TestCase
def test_create
- assert_kind_of SupportsConfigActionTest, SupportsConfigActionTest.new
- assert_kind_of SupportsActionTestBase, SupportsConfigActionTest.new
+ assert_kind_of SupportsActionTest, SupportsActionTest.new(ConfigAction)
end
end
class TestCase_SupportsInstallActionTest < Test::Unit::TestCase
def test_create
- assert_kind_of SupportsInstallActionTest, SupportsInstallActionTest.new
- assert_kind_of SupportsActionTestBase, SupportsInstallActionTest.new
+ assert_kind_of SupportsActionTest, SupportsActionTest.new(InstallAction)
end
end
class TestCase_SupportsUninstallActionTest < Test::Unit::TestCase
def test_create
- assert_kind_of SupportsUninstallActionTest, SupportsUninstallActionTest.new
- assert_kind_of SupportsActionTestBase, SupportsUninstallActionTest.new
+ assert_kind_of SupportsActionTest, SupportsActionTest.new(UninstallAction)
end
end
class TestCase_SupportsInstallActionTest < Test::Unit::TestCase
def test_create
- assert_kind_of SupportsInstallActionTest, SupportsInstallActionTest.new
- assert_kind_of SupportsActionTestBase, SupportsInstallActionTest.new
+ assert_kind_of SupportsActionTest, SupportsActionTest.new(InstallAction)
end
end
class TestCase_SupportsInstallActionTest < Test::Unit::TestCase
def test_create
- assert_kind_of SupportsInstallActionTest, SupportsInstallActionTest.new
- assert_kind_of SupportsActionTestBase, SupportsInstallActionTest.new
- end
- end
-
- class TestCase_Action < Test::Unit::TestCase
- def test_no_create
- assert_raise NoMethodError do
- ce = Action.new('test')
- end
+ assert_kind_of SupportsActionTest, SupportsActionTest.new(InstallAction)
end
end
diff --git a/ruby/demos/find_unmanaged_files.rb b/ruby/demos/find_unmanaged_files.rb
index f97d9b0..f0cfa1f 100755
--- a/ruby/demos/find_unmanaged_files.rb
+++ b/ruby/demos/find_unmanaged_files.rb
@@ -13,7 +13,7 @@ def get_contents(repo, files, root)
repo.category_names do |cat|
repo.package_names(cat) do |pkg|
repo.package_ids(pkg) do |pid|
- next unless pid.supports_action(SupportsInstalledActionTest.new)
+ next unless pid.supports_action(SupportsActionTest.new(InstalledAction))
next if pid.contents_key.nil?
contents = pid.contents_key.value
contents.each do |entry|
@@ -103,7 +103,7 @@ in_fs = []
Find.find(*files) {|file| in_fs << file}
db.repositories do |repo|
- next unless repo.some_ids_might_support_action(SupportsInstalledActionTest.new)
+ next unless repo.some_ids_might_support_action(SupportsActionTest.new(InstalledAction))
in_fs-= get_contents(repo, files, root)
end
diff --git a/ruby/package_id_TEST.rb b/ruby/package_id_TEST.rb
index 19a2683..47e33ec 100644
--- a/ruby/package_id_TEST.rb
+++ b/ruby/package_id_TEST.rb
@@ -138,7 +138,7 @@ module Paludis
end
def test_supports_action_test
- assert pid_testrepo.supports_action(SupportsFetchActionTest.new)
+ assert pid_testrepo.supports_action(SupportsActionTest.new(FetchAction))
assert_raise TypeError do
pid_testrepo.supports_action(1)
end
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 92d07c1..53f9b1d 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -476,10 +476,10 @@ module Paludis
include RepositoryTestCase
def test_some_ids_might_support
- assert repo.some_ids_might_support_action(SupportsInstallActionTest.new)
- assert ! repo.some_ids_might_support_action(SupportsInstalledActionTest.new)
- assert ! installed_repo.some_ids_might_support_action(SupportsInstallActionTest.new)
- assert installed_repo.some_ids_might_support_action(SupportsInstalledActionTest.new)
+ assert repo.some_ids_might_support_action(SupportsActionTest.new(InstallAction))
+ assert ! repo.some_ids_might_support_action(SupportsActionTest.new(InstalledAction))
+ assert ! installed_repo.some_ids_might_support_action(SupportsActionTest.new(InstallAction))
+ assert installed_repo.some_ids_might_support_action(SupportsActionTest.new(InstalledAction))
end
end