aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-23 23:06:34 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-23 23:06:34 +0000
commitaf29052be127eddcbd129318149965f446ffe47f (patch)
tree2d74c18077723901269ba7998aa5eb2a07458778
parentc2e11fac6dbccc0db35f7cd389cecda80ece3dba (diff)
downloadpaludis-af29052be127eddcbd129318149965f446ffe47f.tar.gz
paludis-af29052be127eddcbd129318149965f446ffe47f.tar.xz
Make LogLevel stringifiable. Remove log_level_string method. More ruby work.
-rw-r--r--paludis/default_environment.cc2
-rw-r--r--paludis/ebin.cc2
-rw-r--r--paludis/ebuild.cc2
-rw-r--r--paludis/repositories/cran/cran_repository.cc6
-rw-r--r--paludis/util/log.cc19
-rw-r--r--paludis/util/log.hh8
-rw-r--r--ruby/Makefile.am22
-rw-r--r--ruby/default_environment.cc42
-rw-r--r--ruby/default_environment_TEST.rb84
-rwxr-xr-xruby/default_environment_TEST_setup.sh43
-rw-r--r--ruby/log.cc66
-rw-r--r--ruby/log_TEST.rb53
-rw-r--r--ruby/mask_reasons.cc103
-rw-r--r--ruby/mask_reasons_TEST.rb41
-rw-r--r--ruby/paludis_ruby.cc25
-rw-r--r--ruby/paludis_ruby.hh11
-rw-r--r--ruby/version_spec_TEST.rb53
17 files changed, 549 insertions, 33 deletions
diff --git a/paludis/default_environment.cc b/paludis/default_environment.cc
index ee2f523..aec0542 100644
--- a/paludis/default_environment.cc
+++ b/paludis/default_environment.cc
@@ -367,7 +367,7 @@ namespace
MakeEnvCommand cmd(make_env_command("bash '" + stringify(f) + "'")
("ROOT", DefaultConfig::get_instance()->root())
("HOOK", hook.name())
- ("HOOK_LOG_LEVEL", Log::get_instance()->log_level_string())
+ ("HOOK_LOG_LEVEL", stringify(Log::get_instance()->log_level()))
("HOOK_CONFIG_SUFFIX", DefaultConfig::config_suffix())
("PALUDIS_EBUILD_DIR", getenv_with_default("PALUDIS_EBUILD_DIR", LIBEXECDIR "/paludis"))
("PALUDIS_COMMAND", paludis_command));
diff --git a/paludis/ebin.cc b/paludis/ebin.cc
index 4e575a6..1c1b664 100644
--- a/paludis/ebin.cc
+++ b/paludis/ebin.cc
@@ -97,7 +97,7 @@ EbinCommand::operator() ()
("PALUDIS_HOOK_DIRS", params.environment->hook_dirs())
("PALUDIS_COMMAND", params.environment->paludis_command())
("KV", kernel_version())
- ("PALUDIS_EBUILD_LOG_LEVEL", Log::get_instance()->log_level_string())
+ ("PALUDIS_EBUILD_LOG_LEVEL", stringify(Log::get_instance()->log_level()))
("PALUDIS_EBUILD_DIR", getenv_with_default("PALUDIS_EBUILD_DIR", LIBEXECDIR "/paludis"))));
if (do_run_command(add_portage_vars(cmd)))
diff --git a/paludis/ebuild.cc b/paludis/ebuild.cc
index ced866c..cc7a348 100644
--- a/paludis/ebuild.cc
+++ b/paludis/ebuild.cc
@@ -101,7 +101,7 @@ EbuildCommand::operator() ()
("PALUDIS_HOOK_DIRS", params.environment->hook_dirs())
("PALUDIS_COMMAND", params.environment->paludis_command())
("KV", kernel_version())
- ("PALUDIS_EBUILD_LOG_LEVEL", Log::get_instance()->log_level_string())
+ ("PALUDIS_EBUILD_LOG_LEVEL", stringify(Log::get_instance()->log_level()))
("PALUDIS_EBUILD_DIR", getenv_with_default("PALUDIS_EBUILD_DIR", LIBEXECDIR "/paludis"))));
if (do_run_command(add_portage_vars(cmd)))
diff --git a/paludis/repositories/cran/cran_repository.cc b/paludis/repositories/cran/cran_repository.cc
index 1b75376..acb1bb9 100644
--- a/paludis/repositories/cran/cran_repository.cc
+++ b/paludis/repositories/cran/cran_repository.cc
@@ -520,7 +520,7 @@ CRANRepository::do_install(const QualifiedPackageName &q, const VersionSpec &vn,
cmd = cmd("PV", stringify(vn));
cmd = cmd("PALUDIS_CRAN_MIRRORS", _imp->mirror);
cmd = cmd("PALUDIS_EBUILD_DIR", std::string(LIBEXECDIR "/paludis/"));
- cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", Log::get_instance()->log_level_string());
+ cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", stringify(Log::get_instance()->log_level()));
cmd = cmd("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files());
@@ -542,7 +542,7 @@ CRANRepository::do_install(const QualifiedPackageName &q, const VersionSpec &vn,
cmd = cmd("PV", stringify(vn));
cmd = cmd("PALUDIS_CRAN_LIBRARY", stringify(_imp->library));
cmd = cmd("PALUDIS_EBUILD_DIR", std::string(LIBEXECDIR "/paludis/"));
- cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", Log::get_instance()->log_level_string());
+ cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", stringify(Log::get_instance()->log_level()));
cmd = cmd("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files());
cmd = cmd("ROOT", stringify(_imp->root));
cmd = cmd("WORKDIR", workdir);
@@ -558,7 +558,7 @@ CRANRepository::do_install(const QualifiedPackageName &q, const VersionSpec &vn,
cmd = cmd("PV", stringify(vn));
cmd = cmd("PALUDIS_CRAN_LIBRARY", stringify(_imp->library));
cmd = cmd("PALUDIS_EBUILD_DIR", std::string(LIBEXECDIR "/paludis/"));
- cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", Log::get_instance()->log_level_string());
+ cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", stringify(Log::get_instance()->log_level()));
cmd = cmd("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files());
cmd = cmd("ROOT", stringify(_imp->root));
cmd = cmd("WORKDIR", workdir);
diff --git a/paludis/util/log.cc b/paludis/util/log.cc
index bbca09e..cbb445d 100644
--- a/paludis/util/log.cc
+++ b/paludis/util/log.cc
@@ -120,22 +120,26 @@ Log::set_log_stream(std::ostream * const s)
_imp->stream = s;
}
-std::string
-Log::log_level_string() const
+std::ostream &
+paludis::operator<< (std::ostream & s, const LogLevel & l)
{
- switch (Log::get_instance()->log_level())
+ switch (l)
{
case ll_qa:
- return "qa";
+ s << "qa";
+ return s;
case ll_warning:
- return "warning";
+ s << "warning";
+ return s;
case ll_debug:
- return "debug";
+ s << "debug";
+ return s;
case ll_silent:
- return "silent";
+ s << "silent";
+ return s;
case last_ll:
;
@@ -149,3 +153,4 @@ Log::set_program_name(const std::string & s)
{
_imp->program_name = s;
}
+
diff --git a/paludis/util/log.hh b/paludis/util/log.hh
index 100c52b..87edc3f 100644
--- a/paludis/util/log.hh
+++ b/paludis/util/log.hh
@@ -107,15 +107,13 @@ namespace paludis
void set_log_stream(std::ostream * const);
/**
- * Log level, as a string.
- */
- std::string log_level_string() const;
-
- /**
* Set our program name.
*/
void set_program_name(const std::string &);
};
+
+ std::ostream &
+ operator<< (std::ostream &, const LogLevel &);
}
#endif
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index e212d03..0642746 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -19,14 +19,18 @@ IF_RUBY_TESTS = \
name_TEST.rb \
default_environment_TEST.rb \
package_database_entry_TEST.rb \
- version_spec_TEST.rb
+ version_spec_TEST.rb \
+ mask_reasons_TEST.rb \
+ log_TEST.rb
IF_RUBY_SOURCES = \
paludis_ruby.cc paludis_ruby.hh \
name.cc \
default_environment.cc \
package_database_entry.cc \
- version_spec.cc
+ version_spec.cc \
+ mask_reasons.cc \
+ log.cc
EXTRA_DIST = $(IF_RUBY_TESTS) $(IF_RUBY_SOURCES) \
default_environment_TEST_setup.sh default_environment_TEST_cleanup.sh
@@ -44,11 +48,13 @@ TESTS_ENVIRONMENT = env \
if ENABLE_RUBY
OUR_OBJECTS = \
- name.o \
default_environment.o \
- paludis_ruby.o \
+ log.o \
+ mask_reasons.o \
+ name.o \
package_database_entry.o \
- version_spec.o
+ version_spec.o \
+ paludis_ruby.o
TESTS = $(IF_RUBY_TESTS)
noinst_DATA = $(OUR_OBJECTS)
@@ -75,6 +81,12 @@ package_database_entry.o : package_database_entry.cc paludis_ruby.hh
version_spec.o : version_spec.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/version_spec.cc
+mask_reasons.o : mask_reasons.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/mask_reasons.cc
+
+log.o : log.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/log.cc
+
.libs/Paludis.so : $(OUR_OBJECTS)
mkdir -p .libs
$(CXX) -fPIC -shared $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
diff --git a/ruby/default_environment.cc b/ruby/default_environment.cc
index 3bb699a..41e2877 100644
--- a/ruby/default_environment.cc
+++ b/ruby/default_environment.cc
@@ -19,7 +19,6 @@
#include <paludis_ruby.hh>
#include <paludis/default_environment.hh>
-#include <paludis/util/compare.hh>
#include <ruby.h>
using namespace paludis;
@@ -81,6 +80,45 @@ namespace
}
}
+ VALUE
+ default_environment_accept_license(int argc, VALUE * argv, VALUE)
+ {
+ try
+ {
+ if (1 == argc || 2 == argc)
+ {
+ PackageDatabaseEntry * pde_ptr(0);
+ if (2 == argc)
+ Data_Get_Struct(argv[1], PackageDatabaseEntry, pde_ptr);
+
+ return DefaultEnvironment::get_instance()->accept_license(
+ std::string(STR2CSTR(argv[0])), pde_ptr) ? Qtrue : Qfalse;
+ }
+ else
+ rb_raise(rb_eArgError, "DefaultEnvironment.accept_license expects one or two arguments, but got %d", argc);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ default_environment_mask_reasons(VALUE, VALUE pde)
+ {
+ PackageDatabaseEntry * pde_ptr(0);
+ Data_Get_Struct(pde, PackageDatabaseEntry, pde_ptr);
+ try
+ {
+ MaskReasons r(DefaultEnvironment::get_instance()->mask_reasons(*pde_ptr));
+ return create_mask_reasons(r);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
void do_register_default_environment()
{
rb_require("singleton");
@@ -89,6 +127,8 @@ namespace
rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_default_environment);
rb_define_method(c_default_environment, "query_use", RUBY_FUNC_CAST(&default_environment_query_use), -1);
rb_define_method(c_default_environment, "accept_keyword", RUBY_FUNC_CAST(&default_environment_accept_keyword), -1);
+ rb_define_method(c_default_environment, "accept_license", RUBY_FUNC_CAST(&default_environment_accept_license), -1);
+ rb_define_method(c_default_environment, "mask_reasons", RUBY_FUNC_CAST(&default_environment_mask_reasons), 1);
}
}
diff --git a/ruby/default_environment_TEST.rb b/ruby/default_environment_TEST.rb
index f8892be..5559d88 100644
--- a/ruby/default_environment_TEST.rb
+++ b/ruby/default_environment_TEST.rb
@@ -23,6 +23,8 @@ ENV["PALUDIS_HOME"] = Dir.getwd().to_s + "/default_environment_TEST_dir/home";
require 'test/unit'
require 'Paludis'
+Log.instance.log_level = Log::LogLevel::Warning
+
class TestCase_DefaultEnvironment < Test::Unit::TestCase
def test_instance
assert_equal DefaultEnvironment.instance.__id__, DefaultEnvironment.instance.__id__
@@ -33,39 +35,111 @@ class TestCase_DefaultEnvironment < Test::Unit::TestCase
x = DefaultEnvironment.new()
end
end
+end
+class TestCase_DefaultEnvironmentUse < Test::Unit::TestCase
def test_query_use
assert DefaultEnvironment.instance.query_use(UseFlagName.new("enabled"))
assert ! DefaultEnvironment.instance.query_use(UseFlagName.new("not_enabled"))
assert ! DefaultEnvironment.instance.query_use(UseFlagName.new("sometimes_enabled"))
pde = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
- VersionSpec.new("1.0"), RepositoryName.new("nothing"))
+ VersionSpec.new("1.0"), RepositoryName.new("testrepo"))
assert DefaultEnvironment.instance.query_use(UseFlagName.new("enabled"), pde)
assert ! DefaultEnvironment.instance.query_use(UseFlagName.new("not_enabled"), pde)
assert DefaultEnvironment.instance.query_use(UseFlagName.new("sometimes_enabled"), pde)
end
+ def test_query_use_bad
+ assert_raise ArgumentError do
+ DefaultEnvironment.instance.query_use(1, 2, 3)
+ end
+ assert_raise TypeError do
+ DefaultEnvironment.instance.query_use("not_enabled")
+ end
+ end
+
+end
+
+class TestCase_DefaultEnvironmentAcceptKeyword < Test::Unit::TestCase
def test_accept_keyword
assert DefaultEnvironment.instance.accept_keyword(KeywordName.new("test"))
assert ! DefaultEnvironment.instance.accept_keyword(KeywordName.new("bad"))
assert ! DefaultEnvironment.instance.accept_keyword(KeywordName.new("~test"))
pde = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
- VersionSpec.new("1.0"), RepositoryName.new("nothing"))
+ VersionSpec.new("1.0"), RepositoryName.new("testrepo"))
assert DefaultEnvironment.instance.accept_keyword(KeywordName.new("test"), pde)
assert ! DefaultEnvironment.instance.accept_keyword(KeywordName.new("bad"), pde)
assert DefaultEnvironment.instance.accept_keyword(KeywordName.new("~test"), pde)
end
- def test_query_use_bad
+ def test_accept_keyword_bad
assert_raise ArgumentError do
- DefaultEnvironment.instance.query_use(1, 2, 3)
+ DefaultEnvironment.instance.accept_keyword(1, 2, 3)
end
assert_raise TypeError do
- DefaultEnvironment.instance.query_use("not_enabled")
+ DefaultEnvironment.instance.accept_keyword("foo")
+ end
+ end
+end
+
+class TestCase_DefaultEnvironmentAcceptLicense < Test::Unit::TestCase
+ def test_accept_license
+ assert DefaultEnvironment.instance.accept_license("test")
+
+ pde = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
+ VersionSpec.new("1.0"), RepositoryName.new("testrepo"))
+
+ assert DefaultEnvironment.instance.accept_license("test", pde)
+ end
+
+ def test_accept_license_bad
+ assert_raise ArgumentError do
+ DefaultEnvironment.instance.accept_license(1, 2, 3)
+ end
+ assert_raise TypeError do
+ DefaultEnvironment.instance.accept_license(123)
+ end
+ end
+end
+
+class TestCase_DefaultEnvironmentMaskReasons < Test::Unit::TestCase
+ def test_mask_reasons
+ p = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
+ VersionSpec.new("1.0"), RepositoryName.new("testrepo"))
+
+ m = DefaultEnvironment.instance.mask_reasons(p)
+ assert m.empty?
+ end
+
+ def test_mask_reasons_not_empty
+ p = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
+ VersionSpec.new("2.0"), RepositoryName.new("testrepo"))
+
+ m = DefaultEnvironment.instance.mask_reasons(p)
+ assert ! m.empty?
+ assert m.include?("keyword")
+ assert_equal ["keyword"], m.to_a
+ end
+
+ def test_mask_reasons_no_such_repo
+ p = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
+ VersionSpec.new("1.0"), RepositoryName.new("nosuchrepo"))
+
+ assert_raise RuntimeError do
+ DefaultEnvironment.instance.mask_reasons p
+ end
+ end
+
+ def test_mask_reasons_bad
+ assert_raise ArgumentError do
+ DefaultEnvironment.instance.mask_reasons(1, 2)
+ end
+ assert_raise TypeError do
+ DefaultEnvironment.instance.accept_license(123)
end
end
end
diff --git a/ruby/default_environment_TEST_setup.sh b/ruby/default_environment_TEST_setup.sh
index 9e8feb2..82e1624 100755
--- a/ruby/default_environment_TEST_setup.sh
+++ b/ruby/default_environment_TEST_setup.sh
@@ -6,10 +6,11 @@ cd default_environment_TEST_dir || exit 1
mkdir -p home/.paludis/repositories
-cat <<END > home/.paludis/repositories/nothing.conf
-format = nothing
-location = /var/empty
-name = nothing
+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
@@ -26,3 +27,37 @@ 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" > 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 ..
+
+
diff --git a/ruby/log.cc b/ruby/log.cc
new file mode 100644
index 0000000..c30e676
--- /dev/null
+++ b/ruby/log.cc
@@ -0,0 +1,66 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis 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., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis_ruby.hh>
+#include <paludis/util/log.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_log;
+ static VALUE c_log_log_level;
+
+ VALUE
+ log_log_level(VALUE)
+ {
+ return INT2FIX(Log::get_instance()->log_level());
+ }
+
+ VALUE
+ log_log_level_set(VALUE self, VALUE value)
+ {
+ Log::get_instance()->set_log_level(static_cast<LogLevel>(NUM2INT(value)));
+ return self;
+ }
+
+ void do_register_log()
+ {
+ rb_require("singleton");
+
+ c_log = rb_define_class("Log", rb_cObject);
+ rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_log);
+ rb_define_method(c_log, "log_level", RUBY_FUNC_CAST(&log_log_level), 0);
+ rb_define_method(c_log, "log_level=", RUBY_FUNC_CAST(&log_log_level_set), 1);
+// rb_define_method(c_log, "message", RUBY_FUNC_CAST(&log_message), 2);
+
+ c_log_log_level = rb_define_class_under(c_log, "LogLevel", rb_cObject);
+ for (LogLevel l(static_cast<LogLevel>(0)), l_end(last_ll) ; l != l_end ;
+ l = static_cast<LogLevel>(static_cast<int>(l) + 1))
+ rb_define_const(c_log_log_level, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_log PALUDIS_ATTRIBUTE((used)) (&do_register_log);
+
+
diff --git a/ruby/log_TEST.rb b/ruby/log_TEST.rb
new file mode 100644
index 0000000..c262846
--- /dev/null
+++ b/ruby/log_TEST.rb
@@ -0,0 +1,53 @@
+#!/usr/bin/ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+#
+# 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
+# Public License version 2, as published by the Free Software Foundation.
+#
+# Paludis 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., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+ENV["PALUDIS_HOME"] = Dir.getwd().to_s + "/default_environment_TEST_dir/home";
+
+require 'test/unit'
+require 'Paludis'
+
+class TestCase_Log < Test::Unit::TestCase
+ def test_instance
+ assert_equal Log.instance.__id__, Log.instance.__id__
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = Log.new()
+ end
+ end
+end
+
+class TestCase_LogLogLevel < Test::Unit::TestCase
+ def test_log_level
+ assert_equal Log.instance.log_level, Log.instance.log_level
+ assert Log.instance.log_level >= Log::LogLevel::Debug
+ assert Log.instance.log_level <= Log::LogLevel::Silent
+ end
+
+ def test_log_level_set
+ Log.instance.log_level = Log::LogLevel::Debug;
+ assert_equal Log::LogLevel::Debug, Log.instance.log_level
+
+ Log.instance.log_level = Log::LogLevel::Warning;
+ assert_equal Log::LogLevel::Warning, Log.instance.log_level
+ end
+end
+
diff --git a/ruby/mask_reasons.cc b/ruby/mask_reasons.cc
new file mode 100644
index 0000000..374d29b
--- /dev/null
+++ b/ruby/mask_reasons.cc
@@ -0,0 +1,103 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis 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., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis_ruby.hh>
+#include <paludis/mask_reasons.hh>
+#include <paludis/util/stringify.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_mask_reasons;
+
+ VALUE
+ mask_reasons_init(VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ mask_reasons_new(VALUE self)
+ {
+ MaskReasons * ptr(0);
+ try
+ {
+ ptr = new MaskReasons;
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<MaskReasons>::free, ptr));
+ rb_obj_call_init(tdata, 0, &self);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ mask_reasons_each(VALUE self)
+ {
+ MaskReasons * m_ptr;
+ Data_Get_Struct(self, MaskReasons, m_ptr);
+ for (MaskReason i(static_cast<MaskReason>(0)), i_end(last_mr) ; i != i_end ;
+ i = static_cast<MaskReason>(static_cast<int>(i) + 1))
+ if ((*m_ptr)[i])
+ rb_yield(rb_str_new2(stringify(i).c_str()));
+ return self;
+ }
+
+ VALUE
+ mask_reasons_empty(VALUE self)
+ {
+ MaskReasons * m_ptr;
+ Data_Get_Struct(self, MaskReasons, m_ptr);
+ return m_ptr->any() ? Qfalse : Qtrue;
+ return self;
+ }
+
+ void do_register_mask_reasons()
+ {
+ c_mask_reasons = rb_define_class("MaskReasons", rb_cObject);
+ rb_define_singleton_method(c_mask_reasons, "new", RUBY_FUNC_CAST(&mask_reasons_new), 0);
+ rb_define_method(c_mask_reasons, "initialize", RUBY_FUNC_CAST(&mask_reasons_init), 0);
+ rb_define_method(c_mask_reasons, "each", RUBY_FUNC_CAST(&mask_reasons_each), 0);
+ rb_include_module(c_mask_reasons, rb_mEnumerable);
+ rb_define_method(c_mask_reasons, "empty?", RUBY_FUNC_CAST(&mask_reasons_empty), 0);
+ }
+}
+
+VALUE
+paludis::ruby::create_mask_reasons(const MaskReasons & m)
+{
+ VALUE result(rb_funcall(c_mask_reasons, rb_intern("new"), 0));
+ MaskReasons * m_ptr;
+ Data_Get_Struct(result, MaskReasons, m_ptr);
+ *m_ptr = m;
+ return result;
+}
+
+RegisterRubyClass::Register paludis_ruby_register_mask_reasons PALUDIS_ATTRIBUTE((used))
+ (&do_register_mask_reasons);
+
+
diff --git a/ruby/mask_reasons_TEST.rb b/ruby/mask_reasons_TEST.rb
new file mode 100644
index 0000000..7f57adc
--- /dev/null
+++ b/ruby/mask_reasons_TEST.rb
@@ -0,0 +1,41 @@
+#!/usr/bin/ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+#
+# 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
+# Public License version 2, as published by the Free Software Foundation.
+#
+# Paludis 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., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+require 'test/unit'
+require 'Paludis'
+
+class TestCase_MaskReasons < Test::Unit::TestCase
+
+ def test_create
+ m = MaskReasons.new
+ end
+
+ def test_each
+ m = MaskReasons.new
+ assert_equal [], m.to_a
+ end
+
+ def test_empty
+ m = MaskReasons.new
+ assert m.empty?
+ end
+
+end
+
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index 7aa92c7..9e59f3b 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -21,6 +21,7 @@
#include <paludis_ruby.hh>
#include <ruby.h>
#include <list>
+#include <ctype.h>
using namespace paludis;
using namespace paludis::ruby;
@@ -69,6 +70,30 @@ void paludis::ruby::exception_to_ruby_exception(const std::exception & ee)
rb_raise(rb_eRuntimeError, "Unexpected std::exception: (%s)", ee.what());
}
+std::string
+paludis::ruby::value_case_to_RubyCase(const std::string & s)
+{
+ if (s.empty())
+ return s;
+
+ bool upper_next(true);
+ std::string result;
+ for (std::string::size_type p(0), p_end(s.length()) ; p != p_end ; ++p)
+ {
+ if ('_' == s[p])
+ upper_next = true;
+ else if (upper_next)
+ {
+ result.append(std::string(1, toupper(s[p])));
+ upper_next = false;
+ }
+ else
+ result.append(std::string(1, s[p]));
+ }
+
+ return result;
+}
+
extern "C"
{
void Init_Paludis()
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index 4650edc..8ca62d6 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -25,14 +25,25 @@
#include <paludis/util/attributes.hh>
#include <paludis/util/exception.hh>
#include <paludis/util/compare.hh>
+#include <paludis/mask_reasons.hh>
#include <ruby.h>
namespace paludis
{
namespace ruby
{
+ /* general utilities */
+
void exception_to_ruby_exception(const std::exception &) PALUDIS_ATTRIBUTE((noreturn));
+ std::string value_case_to_RubyCase(const std::string & s);
+
+ /* constructors */
+
+ VALUE create_mask_reasons(const MaskReasons &);
+
+ /* registration */
+
class RegisterRubyClass :
public InstantiationPolicy<RegisterRubyClass, instantiation_method::SingletonAsNeededTag>,
private PrivateImplementationPattern<RegisterRubyClass>
diff --git a/ruby/version_spec_TEST.rb b/ruby/version_spec_TEST.rb
new file mode 100644
index 0000000..f7afb6e
--- /dev/null
+++ b/ruby/version_spec_TEST.rb
@@ -0,0 +1,53 @@
+#!/usr/bin/ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+#
+# 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
+# Public License version 2, as published by the Free Software Foundation.
+#
+# Paludis 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., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+require 'test/unit'
+require 'Paludis'
+
+class TestCase_VersionSpec < Test::Unit::TestCase
+ def test_create
+ v = VersionSpec.new("0")
+ end
+
+ def test_create_error
+ assert_raise TypeError do
+ v = VersionSpec.new(0)
+ end
+ end
+
+ def test_compare
+ v0 = VersionSpec.new("0")
+ v1 = VersionSpec.new("0.1")
+ v2 = VersionSpec.new("1.0")
+
+ assert_operator v0, :<, v1
+ assert_operator v0, :<, v2
+ assert_operator v1, :<, v2
+
+ assert_operator v0, :<=, v0
+ assert_operator v0, :<=, v1
+ assert_operator v0, :<=, v2
+ assert_operator v1, :<=, v2
+ end
+
+ def test_to_s
+ assert_equal "0.1_alpha2", VersionSpec.new("0.1_alpha2").to_s
+ end
+end