aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-01-09 00:51:11 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-01-09 00:51:11 +0000
commitca2476d2a815ad16f801c4080673ef268970f561 (patch)
treef67bf4aa8702b17b023868a57ecee1cc6f4ee046
parent971f38bd190210ecfd7d9d4950eef895e8d19947 (diff)
downloadpaludis-ca2476d2a815ad16f801c4080673ef268970f561.tar.gz
paludis-ca2476d2a815ad16f801c4080673ef268970f561.tar.xz
More blocks and arrays in ruby. Tidied check_TEST.
-rw-r--r--ruby/check.cc14
-rw-r--r--ruby/check_TEST.rb302
-rw-r--r--ruby/check_result.cc11
-rw-r--r--ruby/check_result_TEST.rb7
-rw-r--r--ruby/demos/qualudis.rb4
5 files changed, 78 insertions, 260 deletions
diff --git a/ruby/check.cc b/ruby/check.cc
index e3ebe14..5445c22 100644
--- a/ruby/check.cc
+++ b/ruby/check.cc
@@ -342,8 +342,9 @@ namespace
*
* call-seq:
* keys -> Array
+ * keys {|check_name| block } -> Qnil
*
- * Fetch the check names for this class.
+ * Returns the names of all checks in this maker, either as an Array or as the parameters to a block.
*/
template <typename T_>
struct CheckMakerStruct
@@ -353,12 +354,17 @@ namespace
{
std::list<std::string> checks;
T_::get_instance()->copy_keys(std::back_inserter(checks));
+ if (rb_block_given_p())
+ {
+ for (std::list<std::string>::const_iterator i(checks.begin()),
+ i_end(checks.end()) ; i != i_end ; ++i)
+ rb_yield(rb_str_new2((*i).c_str()));
+ return Qnil;
+ }
VALUE result(rb_ary_new());
for (std::list<std::string>::const_iterator i(checks.begin()),
i_end(checks.end()) ; i != i_end ; ++i)
- {
- rb_ary_push(result, rb_str_new2((*i).c_str()));
- }
+ rb_ary_push(result, rb_str_new2((*i).c_str()));
return result;
}
};
diff --git a/ruby/check_TEST.rb b/ruby/check_TEST.rb
index 85ca993..e7c25c4 100644
--- a/ruby/check_TEST.rb
+++ b/ruby/check_TEST.rb
@@ -25,38 +25,38 @@ Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
module Paludis
module QA
- class TestCase_FileCheckMaker < Test::Unit::TestCase
+ module MakerTests
def instance
- FileCheckMaker.instance
+ maker_class.instance
end
def test_instance
- assert_equal FileCheckMaker.instance.__id__, FileCheckMaker.instance.__id__
- assert_kind_of FileCheckMaker, FileCheckMaker.instance
+ assert_equal instance.__id__, instance.__id__
+ assert_kind_of maker_class, instance
end
def test_no_create
assert_raise NoMethodError do
- x = FileCheckMaker.new()
+ x = maker_class.new()
end
end
def test_respond_to
- assert_respond_to instance, :keys
- assert_respond_to instance, :find_maker
- assert_respond_to instance, :check_names
- assert_respond_to instance, :find_check
+ [:keys, :find_maker, :check_names, :find_check].each {|sym| assert_respond_to instance, sym}
end
def test_keys
assert_kind_of Array, instance.keys
assert_not_equal 0, instance.keys
+
+ assert_equal(nil, instance.keys {|x| x})
end
def test_find_maker
name = instance.keys.first
- assert_kind_of FileCheck, instance.find_maker(name)
+ assert_kind_of made_class, instance.find_maker(name)
end
+
def test_check_names
assert_kind_of Array, instance.check_names
assert_equal instance.keys, instance.check_names
@@ -68,219 +68,40 @@ module Paludis
end
end
- class TestCase_PackageDirCheckMaker < Test::Unit::TestCase
- def instance
- PackageDirCheckMaker.instance
- end
-
- def test_instance
- assert_equal PackageDirCheckMaker.instance.__id__, PackageDirCheckMaker.instance.__id__
- assert_kind_of PackageDirCheckMaker, PackageDirCheckMaker.instance
- end
-
- def test_no_create
- assert_raise NoMethodError do
- x = PackageDirCheckMaker.new()
- end
- end
-
- def test_respond_to
- assert_respond_to instance, :keys
- assert_respond_to instance, :find_maker
- assert_respond_to instance, :check_names
- assert_respond_to instance, :find_check
- end
-
- def test_keys
- assert_kind_of Array, instance.keys
- assert_not_equal 0, instance.keys
- end
-
- def test_find_maker
- name = instance.keys.first
- assert_kind_of PackageDirCheck, instance.find_maker(name)
- end
- def test_check_names
- assert_kind_of Array, instance.check_names
- assert_equal instance.keys, instance.check_names
- end
+ class TestCase_FileCheckMaker < Test::Unit::TestCase
+ include MakerTests
+ def made_class; FileCheck; end
+ def maker_class; FileCheckMaker; end
+ end
- def test_find_check
- name = instance.keys.first
- assert_equal instance.find_maker(name).describe, instance.find_check(name).describe
- end
+ class TestCase_PackageDirCheckMaker < Test::Unit::TestCase
+ include MakerTests
+ def made_class; PackageDirCheck; end
+ def maker_class; PackageDirCheckMaker; end
end
class TestCase_EbuildCheckMaker < Test::Unit::TestCase
- def instance
- EbuildCheckMaker.instance
- end
-
- def test_instance
- assert_equal EbuildCheckMaker.instance.__id__, EbuildCheckMaker.instance.__id__
- assert_kind_of EbuildCheckMaker, EbuildCheckMaker.instance
- end
-
- def test_no_create
- assert_raise NoMethodError do
- x = EbuildCheckMaker.new()
- end
- end
-
- def test_respond_to
- assert_respond_to instance, :keys
- assert_respond_to instance, :find_maker
- assert_respond_to instance, :check_names
- assert_respond_to instance, :find_check
- end
-
- def test_keys
- assert_kind_of Array, instance.keys
- assert_not_equal 0, instance.keys
- end
-
- def test_find_maker
- name = instance.keys.first
- assert_kind_of EbuildCheck, instance.find_maker(name)
- end
- def test_check_names
- assert_kind_of Array, instance.check_names
- assert_equal instance.keys, instance.check_names
- end
-
- def test_find_check
- name = instance.keys.first
- assert_equal instance.find_maker(name).describe, instance.find_check(name).describe
- end
+ include MakerTests
+ def made_class; EbuildCheck; end
+ def maker_class; EbuildCheckMaker; end
end
class TestCase_PerProfileEbuildCheckMaker < Test::Unit::TestCase
- def instance
- PerProfileEbuildCheckMaker.instance
- end
-
- def test_instance
- assert_equal PerProfileEbuildCheckMaker.instance.__id__, PerProfileEbuildCheckMaker.instance.__id__
- assert_kind_of PerProfileEbuildCheckMaker, PerProfileEbuildCheckMaker.instance
- end
-
- def test_no_create
- assert_raise NoMethodError do
- x = PerProfileEbuildCheckMaker.new()
- end
- end
-
- def test_respond_to
- assert_respond_to instance, :keys
- assert_respond_to instance, :find_maker
- assert_respond_to instance, :check_names
- assert_respond_to instance, :find_check
- end
-
- def test_keys
- assert_kind_of Array, instance.keys
- assert_not_equal 0, instance.keys
- end
-
- def test_find_maker
- name = instance.keys.first
- assert_kind_of PerProfileEbuildCheck, instance.find_maker(name)
- end
- def test_check_names
- assert_kind_of Array, instance.check_names
- assert_equal instance.keys, instance.check_names
- end
-
- def test_find_check
- name = instance.keys.first
- assert_equal instance.find_maker(name).describe, instance.find_check(name).describe
- end
+ include MakerTests
+ def made_class; PerProfileEbuildCheck; end
+ def maker_class; PerProfileEbuildCheckMaker; end
end
class TestCase_ProfilesCheckMaker < Test::Unit::TestCase
- def instance
- ProfilesCheckMaker.instance
- end
-
- def test_instance
- assert_equal ProfilesCheckMaker.instance.__id__, ProfilesCheckMaker.instance.__id__
- assert_kind_of ProfilesCheckMaker, ProfilesCheckMaker.instance
- end
-
- def test_no_create
- assert_raise NoMethodError do
- x = ProfilesCheckMaker.new()
- end
- end
-
- def test_respond_to
- assert_respond_to instance, :keys
- assert_respond_to instance, :find_maker
- assert_respond_to instance, :check_names
- assert_respond_to instance, :find_check
- end
-
- def test_keys
- assert_kind_of Array, instance.keys
- assert_not_equal 0, instance.keys
- end
-
- def test_find_maker
- name = instance.keys.first
- assert_kind_of ProfilesCheck, instance.find_maker(name)
- end
- def test_check_names
- assert_kind_of Array, instance.check_names
- assert_equal instance.keys, instance.check_names
- end
-
- def test_find_check
- name = instance.keys.first
- assert_equal instance.find_maker(name).describe, instance.find_check(name).describe
- end
+ include MakerTests
+ def made_class; ProfilesCheck; end
+ def maker_class; ProfilesCheckMaker; end
end
class TestCase_ProfileCheckMaker < Test::Unit::TestCase
- def instance
- ProfileCheckMaker.instance
- end
-
- def test_instance
- assert_equal ProfileCheckMaker.instance.__id__, ProfileCheckMaker.instance.__id__
- assert_kind_of ProfileCheckMaker, ProfileCheckMaker.instance
- end
-
- def test_no_create
- assert_raise NoMethodError do
- x = ProfileCheckMaker.new()
- end
- end
-
- def test_respond_to
- assert_respond_to instance, :keys
- assert_respond_to instance, :find_maker
- assert_respond_to instance, :check_names
- assert_respond_to instance, :find_check
- end
-
- def test_keys
- assert_kind_of Array, instance.keys
- assert_not_equal 0, instance.keys
- end
-
- def test_find_maker
- name = instance.keys.first
- assert_kind_of ProfileCheck, instance.find_maker(name)
- end
- def test_check_names
- assert_kind_of Array, instance.check_names
- assert_equal instance.keys, instance.check_names
- end
-
- def test_find_check
- name = instance.keys.first
- assert_equal instance.find_maker(name).describe, instance.find_check(name).describe
- end
+ include MakerTests
+ def made_class; ProfileCheck; end
+ def maker_class; ProfileCheckMaker; end
end
class TestCase_EbuildCheckData < Test::Unit::TestCase
@@ -307,7 +128,16 @@ module Paludis
end
end
+ module CheckTests
+ def test_respond_to
+ check = get_check
+ [:describe, :is_important?, :check].each {|sym| assert_respond_to get_check, sym}
+ end
+ end
+
class TestCase_PackageDirCheck < Test::Unit::TestCase
+ include CheckTests
+
def get_check
PackageDirCheckMaker.instance.find_maker('package_name')
end
@@ -318,13 +148,6 @@ module Paludis
end
end
- def test_respond_to
- check = get_check
- assert_respond_to check, :describe
- assert_respond_to check, :is_important?
- assert_respond_to check, :check
- end
-
def test_describe
check = get_check
assert_equal "Checks that the category/package name is valid", check.describe
@@ -344,6 +167,8 @@ module Paludis
end
class TestCase_FileCheck < Test::Unit::TestCase
+ include CheckTests
+
def get_check
FileCheckMaker.instance.find_maker('whitespace')
end
@@ -354,13 +179,6 @@ module Paludis
end
end
- def test_respond_to
- check = get_check
- assert_respond_to check, :describe
- assert_respond_to check, :is_important?
- assert_respond_to check, :check
- end
-
def test_describe
check = get_check
assert_equal "Checks whitespace", check.describe
@@ -380,6 +198,8 @@ module Paludis
end
class TestCase_EbuildCheck < Test::Unit::TestCase
+ include CheckTests
+
def get_ecd
env = QAEnvironment.new('check_TEST_dir/repo1')
ecd = EbuildCheckData.new('cat-one/pkg-one', "1", env)
@@ -395,13 +215,6 @@ module Paludis
end
end
- def test_respond_to
- check = get_check
- assert_respond_to check, :describe
- assert_respond_to check, :is_important?
- assert_respond_to check, :check
- end
-
def test_describe
check = get_check
assert_equal "Checks that the metadata can be generated", check.describe
@@ -421,6 +234,8 @@ module Paludis
end
class TestCase_PerProfileEbuildCheck < Test::Unit::TestCase
+ include CheckTests
+
def get_ecd
env = QAEnvironment.new('check_TEST_dir/repo1')
PerProfileEbuildCheckData.new('cat-one/pkg-one', "1", env, 'check_TEST_dir/repo1/profiles/profile')
@@ -436,13 +251,6 @@ module Paludis
end
end
- def test_respond_to
- check = get_check
- assert_respond_to check, :describe
- assert_respond_to check, :is_important?
- assert_respond_to check, :check
- end
-
def test_describe
check = get_check
assert_equal "Checks that packages in *DEPEND are visible", check.describe
@@ -462,6 +270,8 @@ module Paludis
end
class TestCase_ProfilesCheck < Test::Unit::TestCase
+ include CheckTests
+
def get_check
ProfilesCheckMaker.instance.find_maker('repo_name')
end
@@ -472,13 +282,6 @@ module Paludis
end
end
- def test_respond_to
- check = get_check
- assert_respond_to check, :describe
- assert_respond_to check, :is_important?
- assert_respond_to check, :check
- end
-
def test_describe
check = get_check
assert_equal "Checks that repo_name is sane", check.describe
@@ -498,6 +301,8 @@ module Paludis
end
class TestCase_ProfileCheck < Test::Unit::TestCase
+ include CheckTests
+
def get_pcd
env = QAEnvironment.new('check_TEST_dir/repo1')
ProfileCheckData.new('check_TEST_dir/repo1/profiles', env.portage_repository.profiles.first)
@@ -513,13 +318,6 @@ module Paludis
end
end
- def test_respond_to
- check = get_check
- assert_respond_to check, :describe
- assert_respond_to check, :is_important?
- assert_respond_to check, :check
- end
-
def test_describe
check = get_check
assert_equal "Checks that profile paths exist", check.describe
diff --git a/ruby/check_result.cc b/ruby/check_result.cc
index 2ced140..15d865b 100644
--- a/ruby/check_result.cc
+++ b/ruby/check_result.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006 Richard Brown <mynamewasgone@gmail.com>
+ * Copyright (c) 2006, 2007 Richard Brown <mynamewasgone@gmail.com>
*
* 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
@@ -111,8 +111,9 @@ namespace
/*
* call-seq:
* messages -> Array
+ * messages -> {|message| block } -> Qnil
*
- * Array with all result Messages in.
+ * Returns all the Messages in the CheckResult, either as an Array, or as the parameters to a block.
*/
VALUE
check_result_messages(VALUE self)
@@ -120,6 +121,12 @@ namespace
CheckResult * ptr;
Data_Get_Struct(self, CheckResult, ptr);
+ if (rb_block_given_p())
+ {
+ for (CheckResult::Iterator i (ptr->begin()), i_end(ptr->end()) ; i != i_end; ++i)
+ rb_yield(message_to_value(*i));
+ return Qnil;
+ }
VALUE result(rb_ary_new());
for (CheckResult::Iterator i (ptr->begin()), i_end(ptr->end()) ; i != i_end; ++i)
rb_ary_push(result, message_to_value(*i));
diff --git a/ruby/check_result_TEST.rb b/ruby/check_result_TEST.rb
index 4db80da..0d9b296 100644
--- a/ruby/check_result_TEST.rb
+++ b/ruby/check_result_TEST.rb
@@ -99,6 +99,13 @@ module Paludis
Message.new(QALevel::Fatal, 'test2')
]
cr << msgs[0]
+
+ assert_nothing_raised do
+ cr.messages do |message|
+ assert_equal msgs.first.to_s, message.to_s
+ end
+ end
+
cr << msgs[1]
assert_equal msgs.to_s, cr.messages.to_s
end
diff --git a/ruby/demos/qualudis.rb b/ruby/demos/qualudis.rb
index 931cf04..887f7ed 100644
--- a/ruby/demos/qualudis.rb
+++ b/ruby/demos/qualudis.rb
@@ -38,7 +38,7 @@ end
def display_errors(result)
done_out = false
- result.messages.each do |message|
+ result.messages do |message|
next if message.level < @min_level
case message.level
when QALevel::Info
@@ -278,7 +278,7 @@ end
def describe_check(title, maker)
puts "#{title}:"
- maker.check_names.each do |check_name|
+ maker.check_names do |check_name|
$stderr.puts " #{check_name}:"
$stderr.puts " #{maker.find_check(check_name).describe}"
end