aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2006-10-31 20:30:47 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2006-10-31 20:30:47 +0000
commit7366f7fabcfe9f55c2bb0fbf8bdea37f412ff321 (patch)
tree2ad3887b771dc2eee9d5c07e1d00b88e3a24efbe
parent8060b26e9aef92ef9c520966ef001d92d3a0cb81 (diff)
downloadpaludis-7366f7fabcfe9f55c2bb0fbf8bdea37f412ff321.tar.gz
paludis-7366f7fabcfe9f55c2bb0fbf8bdea37f412ff321.tar.xz
Add match_package to ruby Paludis module
-rw-r--r--ruby/paludis_ruby.cc22
-rw-r--r--ruby/paludis_ruby_TEST.rb23
-rwxr-xr-xruby/paludis_ruby_TEST_cleanup.sh12
-rwxr-xr-xruby/paludis_ruby_TEST_setup.sh66
4 files changed, 123 insertions, 0 deletions
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index ea6dc18..9e3b6a4 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -26,6 +26,8 @@
using namespace paludis;
using namespace paludis::ruby;
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
namespace paludis
{
template<>
@@ -49,6 +51,24 @@ namespace
static VALUE c_dep_string_error;
static VALUE c_dep_string_parse_error;
static VALUE c_dep_string_nesting_error;
+
+ VALUE paludis_match_package(VALUE, VALUE en, VALUE a, VALUE t)
+ {
+ try
+ {
+ Environment * env;
+ Data_Get_Struct(en, Environment, env);
+ PackageDepAtom::ConstPointer atom(value_to_package_dep_atom(a));
+ PackageDatabaseEntry * target;
+ Data_Get_Struct(t, PackageDatabaseEntry, target);
+ return match_package(env, atom, *target) ? Qtrue : Qfalse;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+
+ }
}
RegisterRubyClass::RegisterRubyClass() :
@@ -152,6 +172,8 @@ extern "C"
c_dep_string_parse_error = rb_define_class_under(c_paludis_module, "DepStringParseError", c_dep_string_error);
c_dep_string_nesting_error = rb_define_class_under(c_paludis_module, "DepStringNestingError", c_dep_string_parse_error);
+ rb_define_module_function(c_paludis_module, "match_package", RUBY_FUNC_CAST(&paludis_match_package), 3);
+
rb_define_const(c_paludis_module, "Version", rb_str_new2((stringify(PALUDIS_VERSION_MAJOR) + "."
+ stringify(PALUDIS_VERSION_MINOR) + "." + stringify(PALUDIS_VERSION_MICRO)).c_str()));
RegisterRubyClass::get_instance()->execute();
diff --git a/ruby/paludis_ruby_TEST.rb b/ruby/paludis_ruby_TEST.rb
index 83c62d7..93fb08f 100644
--- a/ruby/paludis_ruby_TEST.rb
+++ b/ruby/paludis_ruby_TEST.rb
@@ -18,6 +18,8 @@
# Place, Suite 330, Boston, MA 02111-1307 USA
#
+ENV["PALUDIS_HOME"] = Dir.getwd().to_s + "/paludis_ruby_TEST_dir/home";
+
require 'test/unit'
class TC_Basic < Test::Unit::TestCase
@@ -26,3 +28,24 @@ class TC_Basic < Test::Unit::TestCase
end
end
+require 'Paludis'
+
+Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
+
+module Paludis
+
+ class TestCase_Match < Test::Unit::TestCase
+
+ def test_match
+ env = DefaultEnvironment.instance
+ atom_good = PackageDepAtom.new('>=foo/bar-1')
+ atom_bad = PackageDepAtom.new('>=foo/bar-2')
+ pde = PackageDatabaseEntry.new('foo/bar','1','test')
+
+ assert Paludis::match_package(env, atom_good, pde)
+ assert !Paludis::match_package(env, atom_bad, pde)
+
+ end
+ end
+
+end
diff --git a/ruby/paludis_ruby_TEST_cleanup.sh b/ruby/paludis_ruby_TEST_cleanup.sh
new file mode 100755
index 0000000..cda2562
--- /dev/null
+++ b/ruby/paludis_ruby_TEST_cleanup.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d paludis_ruby_TEST_dir ] ; then
+ rm -fr paludis_ruby_TEST_dir
+else
+ true
+fi
+
+
+
+
diff --git a/ruby/paludis_ruby_TEST_setup.sh b/ruby/paludis_ruby_TEST_setup.sh
new file mode 100755
index 0000000..29827a7
--- /dev/null
+++ b/ruby/paludis_ruby_TEST_setup.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir paludis_ruby_TEST_dir || exit 1
+cd paludis_ruby_TEST_dir || exit 1
+
+mkdir -p home/.paludis/repositories
+
+cat <<END > home/.paludis/repositories/testrepo.conf
+location = `pwd`/testrepo
+format = portage
+cache = /var/empty
+profiles = \${location}/profiles/testprofile
+END
+
+cat <<END > home/.paludis/keywords.conf
+* test
+~foo/bar-1 ~test
+END
+
+cat <<END > home/.paludis/use.conf
+* enabled
+~foo/bar-1 sometimes_enabled
+END
+
+cat <<END > home/.paludis/licenses.conf
+* *
+END
+
+mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,foo/bar/files} || exit 1
+cd testrepo || exit 1
+echo "testrepo" > profiles/repo_name || exit 1
+cat <<END > profiles/categories || exit 1
+foo
+END
+cat <<END > profiles/testprofile/make.defaults
+ARCH=test
+USERLAND=test
+KERNEL=test
+END
+cat <<END > profiles/profiles.desc
+test testprofile stable
+END
+
+cat <<"END" > foo/bar/bar-1.0.ebuild || exit 1
+DESCRIPTION="Test package"
+HOMEPAGE="http://paludis.berlios.de/"
+SRC_URI=""
+SLOT="0"
+IUSE=""
+LICENSE="GPL-2"
+KEYWORDS="test"
+END
+
+cat <<"END" > foo/bar/bar-2.0.ebuild || exit 1
+DESCRIPTION="Test package"
+HOMEPAGE="http://paludis.berlios.de/"
+SRC_URI=""
+SLOT="0"
+IUSE=""
+LICENSE="GPL-2"
+KEYWORDS="~test"
+END
+cd ..
+
+