aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-06 01:37:41 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-06 01:37:41 +0000
commit4a7e31c1a5bcef93417556a39f7c934df79033b2 (patch)
tree05b52454248f747a60dbb62c10675d257916488d
parent7a56cfc21ba06ece6ff30627bb634be1b7b7a1f9 (diff)
downloadpaludis-4a7e31c1a5bcef93417556a39f7c934df79033b2.tar.gz
paludis-4a7e31c1a5bcef93417556a39f7c934df79033b2.tar.xz
(ruby) Catch exceptions in MetadataKey value methods.
-rw-r--r--ruby/metadata_key.cc171
-rw-r--r--ruby/package_id_TEST.rb26
-rwxr-xr-xruby/package_id_TEST_setup.sh16
3 files changed, 165 insertions, 48 deletions
diff --git a/ruby/metadata_key.cc b/ruby/metadata_key.cc
index 7557559..fe76e91 100644
--- a/ruby/metadata_key.cc
+++ b/ruby/metadata_key.cc
@@ -79,9 +79,16 @@ namespace
static VALUE
fetch(VALUE self)
{
- tr1::shared_ptr<const MetadataKey> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
- return rb_str_new2(stringify(((*tr1::static_pointer_cast<const S_>(*self_ptr)).*m_)()).c_str());
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ return rb_str_new2(stringify(((*tr1::static_pointer_cast<const S_>(*self_ptr)).*m_)()).c_str());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
};
@@ -239,61 +246,110 @@ namespace
VALUE
metadata_package_id_key_value(VALUE self)
{
- tr1::shared_ptr<const MetadataKey> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
- return package_id_to_value((tr1::static_pointer_cast<const MetadataPackageIDKey>(*self_ptr))->value());
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ return package_id_to_value((tr1::static_pointer_cast<const MetadataPackageIDKey>(*self_ptr))->value());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
VALUE
metadata_string_key_value(VALUE self)
{
- tr1::shared_ptr<const MetadataKey> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
- return rb_str_new2((tr1::static_pointer_cast<const MetadataStringKey>(*self_ptr))->value().c_str());
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ return rb_str_new2((tr1::static_pointer_cast<const MetadataStringKey>(*self_ptr))->value().c_str());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
VALUE
metadata_size_key_value(VALUE self)
{
- tr1::shared_ptr<const MetadataKey> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
- return LONG2NUM((tr1::static_pointer_cast<const MetadataSizeKey>(*self_ptr))->value());
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ return LONG2NUM((tr1::static_pointer_cast<const MetadataSizeKey>(*self_ptr))->value());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
VALUE
metadata_fsentry_key_value(VALUE self)
{
- tr1::shared_ptr<const MetadataKey> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
- return rb_str_new2(stringify((tr1::static_pointer_cast<const MetadataFSEntryKey>(*self_ptr))->value()).c_str());
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ return rb_str_new2(stringify((tr1::static_pointer_cast<const MetadataFSEntryKey>(*self_ptr))->value()).c_str());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
VALUE
metadata_time_key_value(VALUE self)
{
- tr1::shared_ptr<const MetadataKey> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
- return rb_time_new((tr1::static_pointer_cast<const MetadataTimeKey>(*self_ptr))->value(), 0);
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ return rb_time_new((tr1::static_pointer_cast<const MetadataTimeKey>(*self_ptr))->value(), 0);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
VALUE
metadata_contents_key_value(VALUE self)
{
- tr1::shared_ptr<const MetadataKey> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
- if (tr1::static_pointer_cast<const MetadataContentsKey>(*self_ptr)->value())
- return contents_to_value(tr1::static_pointer_cast<const MetadataContentsKey>(*self_ptr)->value());
- return Qnil;
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ if (tr1::static_pointer_cast<const MetadataContentsKey>(*self_ptr)->value())
+ return contents_to_value(tr1::static_pointer_cast<const MetadataContentsKey>(*self_ptr)->value());
+ return Qnil;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
VALUE
metadata_repository_mask_info_key_value(VALUE self)
{
- tr1::shared_ptr<const MetadataKey> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
- if ((tr1::static_pointer_cast<const MetadataRepositoryMaskInfoKey>(*self_ptr))->value())
- return repository_mask_info_to_value(tr1::static_pointer_cast<const MetadataRepositoryMaskInfoKey>(*self_ptr)->value());
- return Qnil;
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ if ((tr1::static_pointer_cast<const MetadataRepositoryMaskInfoKey>(*self_ptr))->value())
+ return repository_mask_info_to_value(tr1::static_pointer_cast<const MetadataRepositoryMaskInfoKey>(*self_ptr)->value());
+ return Qnil;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
template <typename T_>
@@ -302,13 +358,20 @@ namespace
static VALUE
fetch(VALUE self)
{
- tr1::shared_ptr<const MetadataKey> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
- tr1::shared_ptr<const T_> c = tr1::static_pointer_cast<const MetadataCollectionKey<T_> >(*self_ptr)->value();
- VALUE result (rb_ary_new());
- for (typename T_::ConstIterator i(c->begin()), i_end(c->end()) ; i != i_end ; ++i)
- rb_ary_push(result, rb_str_new2(stringify(*i).c_str()));
- return result;
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ tr1::shared_ptr<const T_> c = tr1::static_pointer_cast<const MetadataCollectionKey<T_> >(*self_ptr)->value();
+ VALUE result (rb_ary_new());
+ for (typename T_::ConstIterator i(c->begin()), i_end(c->end()) ; i != i_end ; ++i)
+ rb_ary_push(result, rb_str_new2(stringify(*i).c_str()));
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
};
@@ -318,14 +381,21 @@ namespace
static VALUE
fetch(VALUE self)
{
- tr1::shared_ptr<const MetadataKey> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
- tr1::shared_ptr<const PackageIDSequence> c = tr1::static_pointer_cast<const MetadataCollectionKey<PackageIDSequence> >(
- *self_ptr)->value();
- VALUE result (rb_ary_new());
- for (PackageIDSequence::ConstIterator i(c->begin()), i_end(c->end()) ; i != i_end ; ++i)
- rb_ary_push(result, package_id_to_value(*i));
- return result;
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ tr1::shared_ptr<const PackageIDSequence> c = tr1::static_pointer_cast<const MetadataCollectionKey<PackageIDSequence> >(
+ *self_ptr)->value();
+ VALUE result (rb_ary_new());
+ for (PackageIDSequence::ConstIterator i(c->begin()), i_end(c->end()) ; i != i_end ; ++i)
+ rb_ary_push(result, package_id_to_value(*i));
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
};
@@ -335,10 +405,17 @@ namespace
static VALUE
fetch(VALUE self)
{
- tr1::shared_ptr<const MetadataKey> * self_ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
- tr1::shared_ptr<const typename T_::ConstItem> c = tr1::static_pointer_cast<const MetadataSpecTreeKey<T_> >(*self_ptr)->value();
- return dep_tree_to_value<T_>(c);
+ try
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ tr1::shared_ptr<const typename T_::ConstItem> c = tr1::static_pointer_cast<const MetadataSpecTreeKey<T_> >(*self_ptr)->value();
+ return dep_tree_to_value<T_>(c);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
}
};
diff --git a/ruby/package_id_TEST.rb b/ruby/package_id_TEST.rb
index 1647d39..832f8dc 100644
--- a/ruby/package_id_TEST.rb
+++ b/ruby/package_id_TEST.rb
@@ -43,6 +43,10 @@ module Paludis
env.package_database.fetch_repository("testrepo").package_ids("foo/bar").first
end
+ def pid_bad
+ env.package_database.fetch_repository("testrepo").package_ids("bad/pkg").first
+ end
+
def pid_installed
env_vdb.package_database.fetch_repository("installed").package_ids("cat-one/pkg-one").first
end
@@ -342,6 +346,28 @@ module Paludis
assert_equal ['test_inherited'], pid_installed["INHERITED"].value
end
end
+
+ class TestCase_BadKeys < Test::Unit::TestCase
+ include TestStuff
+
+ def test_keywords_key
+ assert_raise NameError do
+ pid_bad.keywords_key.value
+ end
+ end
+
+ def test_iuse_key
+ assert_raise NameError do
+ pid_bad.iuse_key.value
+ end
+ end
+
+ def test_build_dependenciess_key
+ assert_raise RuntimeError do
+ pid_bad.build_dependencies_key.value
+ end
+ end
+ end
end
diff --git a/ruby/package_id_TEST_setup.sh b/ruby/package_id_TEST_setup.sh
index 9087d21..7147bea 100755
--- a/ruby/package_id_TEST_setup.sh
+++ b/ruby/package_id_TEST_setup.sh
@@ -4,11 +4,12 @@
mkdir package_id_TEST_dir || exit 1
cd package_id_TEST_dir || exit 1
-mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,foo/bar/files} || exit 1
+mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,foo/bar/files,bad/pkg/files} || exit 1
cd testrepo || exit 1
echo "testrepo" > profiles/repo_name || exit 1
cat <<END > profiles/categories || exit 1
foo
+bad
END
cat <<END > profiles/profiles.desc
test testprofile stable
@@ -37,6 +38,19 @@ DEPEND="foo/bar"
RDEPEND=""
END
+cat <<"END" > bad/pkg/pkg-1.0.ebuild || exit 1
+DESCRIPTION="Test package"
+HOMEPAGE="http://paludis.pioto.org/"
+SRC_URI="http://example.com/${P}.tar.bz2"
+SLOT="0"
+IUSE="testflag!!!"
+LICENSE="GPL-2"
+KEYWORDS="test!!!"
+RESTRICT="monkey"
+DEPEND="||(foo/bar bar/foo)"
+RDEPEND=""
+END
+
cd ..
mkdir -p installed/cat-one/pkg-{one,two}-1 || exit 1