aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-27 09:55:51 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-27 09:55:51 +0000
commit41b55b9cea20f2b1013d56706d15db8496f5a809 (patch)
treeb57f93f351b60515b72c69fa86bcc3a04e2cd7ad
parentce899e096d10d5cb3d5dc8aabbf6cc062102772a (diff)
downloadpaludis-41b55b9cea20f2b1013d56706d15db8496f5a809.tar.gz
paludis-41b55b9cea20f2b1013d56706d15db8496f5a809.tar.xz
Rubyify NoConfigEnvironment. Move demo code over to using NoConfigEnvironment
-rw-r--r--ruby/Makefile.am23
-rw-r--r--ruby/default_environment.cc182
-rwxr-xr-xruby/default_environment_TEST_cleanup.sh12
-rw-r--r--ruby/demos/version_spec_distributions.rb12
-rw-r--r--ruby/environment.cc275
-rw-r--r--ruby/environment_TEST.rb (renamed from ruby/default_environment_TEST.rb)121
-rwxr-xr-xruby/environment_TEST_cleanup.sh12
-rwxr-xr-xruby/environment_TEST_setup.sh (renamed from ruby/default_environment_TEST_setup.sh)7
8 files changed, 426 insertions, 218 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 38f210a..c3a15ed 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -17,7 +17,7 @@ MAINTAINERCLEANFILES = Makefile.in
IF_RUBY_TESTS = \
paludis_ruby_TEST.rb \
log_TEST.rb \
- default_environment_TEST.rb \
+ environment_TEST.rb \
package_database_entry_TEST.rb \
version_spec_TEST.rb \
mask_reasons_TEST.rb \
@@ -27,7 +27,7 @@ IF_RUBY_TESTS = \
IF_RUBY_SOURCES = \
paludis_ruby.cc paludis_ruby.hh \
- default_environment.cc \
+ environment.cc \
package_database_entry.cc \
version_spec.cc \
mask_reasons.cc \
@@ -37,7 +37,7 @@ IF_RUBY_SOURCES = \
repository.cc
EXTRA_DIST = $(IF_RUBY_TESTS) $(IF_RUBY_SOURCES) \
- default_environment_TEST_setup.sh default_environment_TEST_cleanup.sh \
+ environment_TEST_setup.sh environment_TEST_cleanup.sh \
package_database_TEST_setup.sh package_database_TEST_cleanup.sh \
repository_TEST_setup.sh repository_TEST_cleanup.sh
@@ -48,13 +48,16 @@ TESTS_ENVIRONMENT = env \
PALUDIS_EBUILD_DIR_FALLBACK="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/ebuild/`" \
PALUDIS_REPOSITORY_SO_DIR="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories`" \
SYSCONFDIR="$(sysconfdir)" \
- LD_LIBRARY_PATH="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/.libs`:`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/util/.libs`:`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/environment/default/.libs`" \
+ LD_LIBRARY_PATH="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/.libs`: \
+ `$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/util/.libs`: \
+ `$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/environment/default/.libs`: \
+ `$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/environment/no_config/.libs`" \
bash $(top_srcdir)/test/run_test.sh "ruby -I ./.libs/"
if ENABLE_RUBY
OUR_OBJECTS = \
- default_environment.o \
+ environment.o \
dep_atom.o \
log.o \
mask_reasons.o \
@@ -77,8 +80,8 @@ OUR_CXXCOMPILE = $(CXX) -fPIC $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
paludis_ruby.o : paludis_ruby.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/paludis_ruby.cc
-default_environment.o : default_environment.cc paludis_ruby.hh
- $(OUR_CXXCOMPILE) -o $@ $(srcdir)/default_environment.cc
+environment.o : environment.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/environment.cc
dep_atom.o : dep_atom.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/dep_atom.cc
@@ -111,7 +114,8 @@ repository.o : repository.cc paludis_ruby.hh
$^ \
$(top_builddir)/paludis/util/.libs/libpaludisutil.so \
$(top_builddir)/paludis/.libs/libpaludis.so \
- $(top_builddir)/paludis/environment/default/.libs/libpaludisdefaultenvironment.so
+ $(top_builddir)/paludis/environment/default/.libs/libpaludisdefaultenvironment.so \
+ $(top_builddir)/paludis/environment/no_config/.libs/libpaludisnoconfigenvironment.so
Paludis.so : $(OUR_OBJECTS)
mkdir -p .libs
@@ -123,7 +127,8 @@ Paludis.so : $(OUR_OBJECTS)
$^ \
-L$(top_builddir)/paludis/util/.libs/ -lpaludisutil \
-L$(top_builddir)/paludis/.libs/ -lpaludis \
- -L$(top_builddir)/paludis/environment/default/.libs/ -lpaludisdefaultenvironment
+ -L$(top_builddir)/paludis/environment/default/.libs/ -lpaludisdefaultenvironment \
+ -L$(top_builddir)/paludis/environment/no_config/.libs/ -lpaludisnoconfigenvironment
endif
diff --git a/ruby/default_environment.cc b/ruby/default_environment.cc
deleted file mode 100644
index ceb112f..0000000
--- a/ruby/default_environment.cc
+++ /dev/null
@@ -1,182 +0,0 @@
-/* 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/environment/default/default_environment.hh>
-#include <paludis/environment/default/default_config.hh>
-#include <ruby.h>
-
-using namespace paludis;
-using namespace paludis::ruby;
-
-#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
-
-namespace
-{
- static VALUE c_default_environment;
- static VALUE c_default_config;
-
- VALUE
- default_environment_query_use(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()->query_use(UseFlagName(
- STR2CSTR(argv[0])), pde_ptr) ? Qtrue : Qfalse;
- }
- else
- rb_raise(rb_eArgError, "DefaultEnvironment.query_use expects one or two arguments, but got %d", argc);
- }
- catch (const std::exception & e)
- {
- exception_to_ruby_exception(e);
- }
- }
-
- VALUE
- default_environment_accept_keyword(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_keyword(KeywordName(
- STR2CSTR(argv[0])), pde_ptr) ? Qtrue : Qfalse;
- }
- else
- rb_raise(rb_eArgError, "DefaultEnvironment.accept_keyword expects one or two arguments, but got %d", argc);
- }
- catch (const std::exception & e)
- {
- exception_to_ruby_exception(e);
- }
- }
-
- 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);
- }
- }
-
- VALUE
- default_environment_package_database(VALUE)
- {
- try
- {
- return create_package_database(DefaultEnvironment::get_instance()->package_database());
- }
- catch (const std::exception & e)
- {
- exception_to_ruby_exception(e);
- }
- }
-
- VALUE
- default_config_config_suffix(VALUE)
- {
- try
- {
- return rb_str_new2(DefaultConfig::config_suffix().c_str());
- }
- catch (const std::exception & e)
- {
- exception_to_ruby_exception(e);
- }
- }
-
- VALUE
- default_config_config_suffix_set(VALUE klass, VALUE str)
- {
- try
- {
- DefaultConfig::set_config_suffix(stringify(STR2CSTR(str)));
- return klass;
- }
- catch (const std::exception & e)
- {
- exception_to_ruby_exception(e);
- }
- }
-
- void do_register_default_environment()
- {
- rb_require("singleton");
-
- c_default_environment = rb_define_class_under(master_class(), "DefaultEnvironment", rb_cObject);
- 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);
- rb_define_method(c_default_environment, "package_database", RUBY_FUNC_CAST(&default_environment_package_database), 0);
-
- c_default_config = rb_define_class_under(master_class(), "DefaultConfig", rb_cObject);
- rb_funcall(c_default_config, rb_intern("private_class_method"), 1, rb_str_new2("new"));
- rb_define_singleton_method(c_default_config, "config_suffix",
- RUBY_FUNC_CAST(&default_config_config_suffix), 0);
- rb_define_singleton_method(c_default_config, "config_suffix=",
- RUBY_FUNC_CAST(&default_config_config_suffix_set), 1);
- }
-}
-
-RegisterRubyClass::Register paludis_ruby_register_default_environment PALUDIS_ATTRIBUTE((used)) (&do_register_default_environment);
-
diff --git a/ruby/default_environment_TEST_cleanup.sh b/ruby/default_environment_TEST_cleanup.sh
deleted file mode 100755
index eab3f2d..0000000
--- a/ruby/default_environment_TEST_cleanup.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-# vim: set ft=sh sw=4 sts=4 et :
-
-if [ -d default_environment_TEST_dir ] ; then
- rm -fr default_environment_TEST_dir
-else
- true
-fi
-
-
-
-
diff --git a/ruby/demos/version_spec_distributions.rb b/ruby/demos/version_spec_distributions.rb
index c4362f1..6de4568 100644
--- a/ruby/demos/version_spec_distributions.rb
+++ b/ruby/demos/version_spec_distributions.rb
@@ -68,10 +68,11 @@ opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--version', '-V', GetoptLong::NO_ARGUMENT ],
[ '--log-level', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--config-suffix', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--repository-dir', GetoptLong::REQUIRED_ARGUMENT ],
[ '--image', GetoptLong::REQUIRED_ARGUMENT ])
output_image = nil
+repository_dir = Dir.getwd
opts.each do | opt, arg |
case opt
when '--help'
@@ -82,7 +83,7 @@ opts.each do | opt, arg |
puts " --version Display program version"
puts
puts " --log-level level Set log level (debug, qa, warning, silent)"
- puts " --config-suffix dir Set configuration directory suffix"
+ puts " --repository-dir dir Set repository directory (default: cwd)"
puts
puts " --image foo.png Output as the specified image rather than as text"
exit 0
@@ -106,8 +107,8 @@ opts.each do | opt, arg |
exit 1
end
- when '--config-suffix'
- Paludis::DefaultConfig.config_suffix = arg
+ when '--repository-dir'
+ repository_dir = arg
when '--image'
output_image = arg
@@ -116,7 +117,8 @@ opts.each do | opt, arg |
end
distribution = Distribution.new
-Paludis::DefaultEnvironment.instance.package_database.repositories.each do | repo |
+env = Paludis::NoConfigEnvironment.new repository_dir
+env.package_database.repositories.each do | repo |
distribution.add_repository repo
end
if output_image
diff --git a/ruby/environment.cc b/ruby/environment.cc
new file mode 100644
index 0000000..69af47e
--- /dev/null
+++ b/ruby/environment.cc
@@ -0,0 +1,275 @@
+/* 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/environment/default/default_environment.hh>
+#include <paludis/environment/default/default_config.hh>
+#include <paludis/environment/no_config/no_config_environment.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_environment;
+ static VALUE c_default_environment;
+ static VALUE c_default_config;
+ static VALUE c_no_config_environment;
+
+ class EnvironmentData
+ {
+ private:
+ Environment * _e;
+
+ public:
+ Environment * const env_ptr;
+
+ EnvironmentData(Environment * const ee, Environment * const free_e = 0) :
+ _e(free_e),
+ env_ptr(ee)
+ {
+ }
+
+ ~EnvironmentData()
+ {
+ delete _e;
+ }
+ };
+
+ VALUE
+ environment_query_use(int argc, VALUE * argv, VALUE self)
+ {
+ EnvironmentData * env_data;
+ Data_Get_Struct(self, EnvironmentData, env_data);
+
+ try
+ {
+ if (1 == argc || 2 == argc)
+ {
+ PackageDatabaseEntry * pde_ptr(0);
+ if (2 == argc)
+ Data_Get_Struct(argv[1], PackageDatabaseEntry, pde_ptr);
+
+ return env_data->env_ptr->query_use(UseFlagName(STR2CSTR(argv[0])), pde_ptr) ? Qtrue : Qfalse;
+ }
+ else
+ rb_raise(rb_eArgError, "Environment.query_use expects one or two arguments, but got %d", argc);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ environment_accept_keyword(int argc, VALUE * argv, VALUE self)
+ {
+ EnvironmentData * env_data;
+ Data_Get_Struct(self, EnvironmentData, env_data);
+
+ try
+ {
+ if (1 == argc || 2 == argc)
+ {
+ PackageDatabaseEntry * pde_ptr(0);
+ if (2 == argc)
+ Data_Get_Struct(argv[1], PackageDatabaseEntry, pde_ptr);
+
+ return env_data->env_ptr->accept_keyword(KeywordName(
+ STR2CSTR(argv[0])), pde_ptr) ? Qtrue : Qfalse;
+ }
+ else
+ rb_raise(rb_eArgError, "Environment.accept_keyword expects one or two arguments, but got %d", argc);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ environment_accept_license(int argc, VALUE * argv, VALUE self)
+ {
+ EnvironmentData * env_data;
+ Data_Get_Struct(self, EnvironmentData, env_data);
+
+ try
+ {
+ if (1 == argc || 2 == argc)
+ {
+ PackageDatabaseEntry * pde_ptr(0);
+ if (2 == argc)
+ Data_Get_Struct(argv[1], PackageDatabaseEntry, pde_ptr);
+
+ return env_data->env_ptr->accept_license(
+ std::string(STR2CSTR(argv[0])), pde_ptr) ? Qtrue : Qfalse;
+ }
+ else
+ rb_raise(rb_eArgError, "Environment.accept_license expects one or two arguments, but got %d", argc);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ environment_mask_reasons(VALUE self, VALUE pde)
+ {
+ EnvironmentData * env_data;
+ Data_Get_Struct(self, EnvironmentData, env_data);
+
+ PackageDatabaseEntry * pde_ptr(0);
+ Data_Get_Struct(pde, PackageDatabaseEntry, pde_ptr);
+ try
+ {
+ MaskReasons r(env_data->env_ptr->mask_reasons(*pde_ptr));
+ return create_mask_reasons(r);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ environment_package_database(VALUE self)
+ {
+ EnvironmentData * env_data;
+ Data_Get_Struct(self, EnvironmentData, env_data);
+
+ try
+ {
+ return create_package_database(env_data->env_ptr->package_database());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ default_config_config_suffix(VALUE)
+ {
+ try
+ {
+ return rb_str_new2(DefaultConfig::config_suffix().c_str());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ default_config_config_suffix_set(VALUE klass, VALUE str)
+ {
+ try
+ {
+ DefaultConfig::set_config_suffix(stringify(STR2CSTR(str)));
+ return klass;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ no_config_environment_init(VALUE self, VALUE)
+ {
+ return self;
+ }
+
+ VALUE
+ no_config_environment_new(VALUE self, VALUE s)
+ {
+ std::string path;
+ try
+ {
+ if (T_STRING == TYPE(s))
+ path = STR2CSTR(s);
+ else if (rb_obj_is_kind_of(s, rb_cDir))
+ path = STR2CSTR(rb_funcall(s, rb_intern("path"), 0));
+ else
+ rb_raise(rb_eTypeError, "NoConfigEnvironment.new expects a string or Dir");
+
+ NoConfigEnvironment * e(new NoConfigEnvironment(NoConfigEnvironmentParams::create()
+ .repository_dir(FSEntry(path))
+ .accept_unstable(false)));
+ EnvironmentData * ptr(new EnvironmentData(e, e));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<EnvironmentData>::free, ptr));
+ rb_obj_call_init(tdata, 1, &s);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ default_environment_new(VALUE self)
+ {
+ try
+ {
+ EnvironmentData * ptr(new EnvironmentData(DefaultEnvironment::get_instance()));
+ return Data_Wrap_Struct(self, 0, &Common<EnvironmentData>::free, ptr);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_environment()
+ {
+ rb_require("singleton");
+
+ c_environment = rb_define_class_under(master_class(), "Environment", rb_cObject);
+ rb_funcall(c_environment, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_environment, "query_use", RUBY_FUNC_CAST(&environment_query_use), -1);
+ rb_define_method(c_environment, "accept_keyword", RUBY_FUNC_CAST(&environment_accept_keyword), -1);
+ rb_define_method(c_environment, "accept_license", RUBY_FUNC_CAST(&environment_accept_license), -1);
+ rb_define_method(c_environment, "mask_reasons", RUBY_FUNC_CAST(&environment_mask_reasons), 1);
+ rb_define_method(c_environment, "package_database", RUBY_FUNC_CAST(&environment_package_database), 0);
+
+ c_default_environment = rb_define_class_under(master_class(), "DefaultEnvironment", c_environment);
+ rb_define_singleton_method(c_default_environment, "new", RUBY_FUNC_CAST(&default_environment_new), 0);
+ rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_default_environment);
+
+ c_default_config = rb_define_class_under(master_class(), "DefaultConfig", rb_cObject);
+ rb_funcall(c_default_config, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_singleton_method(c_default_config, "config_suffix",
+ RUBY_FUNC_CAST(&default_config_config_suffix), 0);
+ rb_define_singleton_method(c_default_config, "config_suffix=",
+ RUBY_FUNC_CAST(&default_config_config_suffix_set), 1);
+
+ c_no_config_environment = rb_define_class_under(master_class(), "NoConfigEnvironment", c_environment);
+ rb_define_singleton_method(c_no_config_environment, "new", RUBY_FUNC_CAST(&no_config_environment_new), 1);
+ rb_define_method(c_no_config_environment, "initialize", RUBY_FUNC_CAST(&no_config_environment_init), 1);
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_environment PALUDIS_ATTRIBUTE((used))
+ (&do_register_environment);
+
diff --git a/ruby/default_environment_TEST.rb b/ruby/environment_TEST.rb
index c9c7ba3..5eba5f7 100644
--- a/ruby/default_environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -18,7 +18,7 @@
# Place, Suite 330, Boston, MA 02111-1307 USA
#
-ENV["PALUDIS_HOME"] = Dir.getwd().to_s + "/default_environment_TEST_dir/home";
+ENV["PALUDIS_HOME"] = Dir.getwd().to_s + "/environment_TEST_dir/home";
require 'test/unit'
require 'Paludis'
@@ -30,6 +30,8 @@ class Paludis
class TestCase_DefaultEnvironment < Test::Unit::TestCase
def test_instance
assert_equal DefaultEnvironment.instance.__id__, DefaultEnvironment.instance.__id__
+ assert_kind_of Environment, DefaultEnvironment.instance
+ assert_kind_of DefaultEnvironment, DefaultEnvironment.instance
end
def test_no_create
@@ -39,6 +41,22 @@ class Paludis
end
end
+ class TestCase_NoConfigEnvironment < Test::Unit::TestCase
+ def test_create
+ e = NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
+ assert_kind_of Environment, e
+ assert_kind_of NoConfigEnvironment, e
+
+ e = NoConfigEnvironment.new(Dir.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo"))
+ assert_kind_of Environment, e
+ assert_kind_of NoConfigEnvironment, e
+
+ assert_raise TypeError do
+ e = NoConfigEnvironment.new(123)
+ end
+ end
+ end
+
class TestCase_DefaultEnvironmentUse < Test::Unit::TestCase
def test_query_use
assert DefaultEnvironment.instance.query_use("enabled")
@@ -60,7 +78,27 @@ class Paludis
DefaultEnvironment.instance.query_use(123)
end
end
+ end
+
+ class TestCase_NoConfigEnvironmentUse < Test::Unit::TestCase
+ def env
+ NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
+ end
+
+ def test_query_use
+ assert ! env.query_use("foo")
+ pde = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "testrepo")
+ assert ! env.query_use("foo", pde)
+ end
+ def test_query_use_bad
+ assert_raise ArgumentError do
+ env.query_use(1, 2, 3)
+ end
+ assert_raise TypeError do
+ env.query_use(123)
+ end
+ end
end
class TestCase_DefaultEnvironmentAcceptKeyword < Test::Unit::TestCase
@@ -86,6 +124,33 @@ class Paludis
end
end
+ class TestCase_NoConfigEnvironmentAcceptKeyword < Test::Unit::TestCase
+ def env
+ NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
+ end
+
+ def test_accept_keyword
+ assert env.accept_keyword("test")
+ assert ! env.accept_keyword("bad")
+ assert ! env.accept_keyword("~test")
+
+ pde = PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo")
+
+ assert env.accept_keyword("test", pde)
+ assert ! env.accept_keyword("bad", pde)
+ assert ! env.accept_keyword("~test", pde)
+ end
+
+ def test_accept_keyword_bad
+ assert_raise ArgumentError do
+ env.accept_keyword(1, 2, 3)
+ end
+ assert_raise TypeError do
+ env.accept_keyword(123)
+ end
+ end
+ end
+
class TestCase_DefaultEnvironmentAcceptLicense < Test::Unit::TestCase
def test_accept_license
assert DefaultEnvironment.instance.accept_license("test")
@@ -105,18 +170,43 @@ class Paludis
end
end
- class TestCase_DefaultEnvironmentMaskReasons < Test::Unit::TestCase
+ class TestCase_NoConfigEnvironmentAcceptLicense < Test::Unit::TestCase
+ def env
+ NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
+ end
+
+ def test_accept_license
+ assert env.accept_license("test")
+ pde = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "testrepo")
+ assert env.accept_license("test", pde)
+ end
+
+ def test_accept_license_bad
+ assert_raise ArgumentError do
+ env.accept_license(1, 2, 3)
+ end
+ assert_raise TypeError do
+ env.accept_license(123)
+ end
+ end
+ end
+
+ class TestCase_NoConfigEnvironmentMaskReasons < Test::Unit::TestCase
+ def env
+ NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
+ end
+
def test_mask_reasons
p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "testrepo")
- m = DefaultEnvironment.instance.mask_reasons(p)
+ m = env.mask_reasons(p)
assert m.empty?
end
def test_mask_reasons_not_empty
p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("2.0"), "testrepo")
- m = DefaultEnvironment.instance.mask_reasons(p)
+ m = env.mask_reasons(p)
assert ! m.empty?
assert m.include?("keyword")
assert_equal ["keyword"], m.to_a
@@ -126,29 +216,44 @@ class Paludis
p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "nosuchrepo")
assert_raise RuntimeError do
- DefaultEnvironment.instance.mask_reasons p
+ env.mask_reasons p
end
end
def test_mask_reasons_bad
assert_raise ArgumentError do
- DefaultEnvironment.instance.mask_reasons(1, 2)
+ env.mask_reasons(1, 2)
end
assert_raise TypeError do
- DefaultEnvironment.instance.accept_license(123)
+ env.mask_reasons(123)
end
end
end
- class TestCase_PackageDatabase < Test::Unit::TestCase
+ class TestCase_DefaultEnvironmentPackageDatabase < Test::Unit::TestCase
def db
DefaultEnvironment.instance.package_database
end
def test_package_database
assert_kind_of PackageDatabase, db
+ assert_equal "testrepo", db.fetch_repository("testrepo").name
end
end
+ class TestCase_NoConfigEnvironmentPackageDatabase < Test::Unit::TestCase
+ def env
+ NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
+ end
+
+ def db
+ env.package_database
+ end
+
+ def test_package_database
+ assert_kind_of PackageDatabase, db
+ assert_equal "testrepo", db.fetch_repository("testrepo").name
+ end
+ end
end
diff --git a/ruby/environment_TEST_cleanup.sh b/ruby/environment_TEST_cleanup.sh
new file mode 100755
index 0000000..2efc8a2
--- /dev/null
+++ b/ruby/environment_TEST_cleanup.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d environment_TEST_dir ] ; then
+ rm -fr environment_TEST_dir
+else
+ true
+fi
+
+
+
+
diff --git a/ruby/default_environment_TEST_setup.sh b/ruby/environment_TEST_setup.sh
index 82e1624..0be171c 100755
--- a/ruby/default_environment_TEST_setup.sh
+++ b/ruby/environment_TEST_setup.sh
@@ -1,8 +1,8 @@
#!/bin/bash
# vim: set ft=sh sw=4 sts=4 et :
-mkdir default_environment_TEST_dir || exit 1
-cd default_environment_TEST_dir || exit 1
+mkdir environment_TEST_dir || exit 1
+cd environment_TEST_dir || exit 1
mkdir -p home/.paludis/repositories
@@ -38,6 +38,9 @@ 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"