activeldap 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +10 -0
- data/README +3 -2
- data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
- data/examples/al-admin/po/en/al-admin.po +1 -1
- data/examples/al-admin/po/ja/al-admin.po +1 -1
- data/examples/al-admin/po/nl/al-admin.po +1 -1
- data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier.rb +7 -8
- data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier_helper.rb +2 -1
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml +1 -1
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_request.rhtml +2 -1
- data/lib/active_ldap.rb +9 -3
- data/lib/active_ldap/action_controller/ldap_benchmarking.rb +36 -0
- data/lib/active_ldap/adapter/jndi.rb +1 -1
- data/lib/active_ldap/adapter/jndi_connection.rb +2 -1
- data/lib/active_ldap/association/belongs_to_many.rb +10 -2
- data/lib/active_ldap/association/collection.rb +10 -0
- data/lib/active_ldap/association/has_many_utils.rb +13 -9
- data/lib/active_ldap/association/has_many_wrap.rb +10 -2
- data/lib/active_ldap/associations.rb +3 -3
- data/lib/active_ldap/base.rb +95 -32
- data/lib/active_ldap/connection.rb +1 -1
- data/lib/active_ldap/distinguished_name.rb +3 -0
- data/lib/active_ldap/entry_attribute.rb +2 -2
- data/lib/active_ldap/ldif.rb +2 -2
- data/lib/active_ldap/operations.rb +7 -3
- data/lib/active_ldap/user_password.rb +0 -1
- data/lib/active_ldap/validations.rb +2 -0
- data/po/en/active-ldap.po +1 -1
- data/po/ja/active-ldap.po +1 -1
- data/rails/plugin/active_ldap/init.rb +3 -34
- data/test-unit/History.txt +32 -0
- data/test-unit/Manifest.txt +70 -0
- data/test-unit/README.txt +32 -0
- data/test-unit/Rakefile +22 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/lib/test/unit.rb +280 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
- data/test-unit/lib/test/unit/assertions.rb +722 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +250 -0
- data/test-unit/lib/test/unit/collector.rb +43 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +135 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color.rb +61 -0
- data/test-unit/lib/test/unit/diff.rb +524 -0
- data/test-unit/lib/test/unit/error.rb +124 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +110 -0
- data/test-unit/lib/test/unit/fixture.rb +185 -0
- data/test-unit/lib/test/unit/notification.rb +116 -0
- data/test-unit/lib/test/unit/omission.rb +129 -0
- data/test-unit/lib/test/unit/pending.rb +130 -0
- data/test-unit/lib/test/unit/priority.rb +146 -0
- data/test-unit/lib/test/unit/runner/console.rb +46 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +174 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +195 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/tc_adder.rb +18 -0
- data/test-unit/sample/tc_subtracter.rb +18 -0
- data/test-unit/sample/ts_examples.rb +7 -0
- data/test-unit/test/collector/test_descendant.rb +135 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_load.rb +333 -0
- data/test-unit/test/collector/test_objectspace.rb +98 -0
- data/test-unit/test/run-test.rb +13 -0
- data/test-unit/test/test_assertions.rb +693 -0
- data/test-unit/test/test_attribute.rb +86 -0
- data/{test-unit-ext → test-unit}/test/test_color.rb +3 -5
- data/{test-unit-ext → test-unit}/test/test_diff.rb +18 -16
- data/test-unit/test/test_emacs_runner.rb +60 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_fixture.rb +275 -0
- data/{test-unit-ext → test-unit}/test/test_notification.rb +7 -6
- data/test-unit/test/test_omission.rb +81 -0
- data/{test-unit-ext → test-unit}/test/test_pending.rb +15 -15
- data/{test-unit-ext → test-unit}/test/test_priority.rb +4 -3
- data/test-unit/test/test_testcase.rb +411 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit_test_util.rb +12 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/al-test-utils.rb +4 -4
- data/test/command.rb +1 -1
- data/test/run-test.rb +5 -4
- data/test/test_associations.rb +143 -9
- data/test/test_base.rb +25 -1
- data/test/test_dn.rb +2 -0
- data/test/test_find.rb +8 -1
- data/test/test_ldif.rb +51 -114
- data/test/test_reflection.rb +4 -8
- data/test/test_usermod-lang-add.rb +2 -1
- data/test/test_validation.rb +4 -3
- metadata +76 -31
- data/test-unit-ext/NEWS.en +0 -28
- data/test-unit-ext/NEWS.ja +0 -28
- data/test-unit-ext/README.en +0 -247
- data/test-unit-ext/README.ja +0 -246
- data/test-unit-ext/Rakefile +0 -111
- data/test-unit-ext/lib/test-unit-ext.rb +0 -16
- data/test-unit-ext/lib/test-unit-ext/always-show-result.rb +0 -28
- data/test-unit-ext/lib/test-unit-ext/assertions.rb +0 -40
- data/test-unit-ext/lib/test-unit-ext/attributes.rb +0 -129
- data/test-unit-ext/lib/test-unit-ext/backtrace-filter.rb +0 -17
- data/test-unit-ext/lib/test-unit-ext/color.rb +0 -59
- data/test-unit-ext/lib/test-unit-ext/colorized-runner.rb +0 -111
- data/test-unit-ext/lib/test-unit-ext/diff.rb +0 -516
- data/test-unit-ext/lib/test-unit-ext/long-display-for-emacs.rb +0 -25
- data/test-unit-ext/lib/test-unit-ext/notification.rb +0 -79
- data/test-unit-ext/lib/test-unit-ext/omission.rb +0 -96
- data/test-unit-ext/lib/test-unit-ext/pending.rb +0 -97
- data/test-unit-ext/lib/test-unit-ext/priority.rb +0 -158
- data/test-unit-ext/lib/test-unit-ext/version.rb +0 -3
- data/test-unit-ext/lib/test-unit-ext/xml-report.rb +0 -224
- data/test-unit-ext/test/run-test.rb +0 -14
- data/test-unit-ext/test/test_attributes.rb +0 -139
- data/test-unit-ext/test/test_omission.rb +0 -64
- data/test-unit-ext/test/test_xml_report.rb +0 -161
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
class TestUnitAttribute < Test::Unit::TestCase
|
|
2
|
+
class TestStack < Test::Unit::TestCase
|
|
3
|
+
class << self
|
|
4
|
+
def suite
|
|
5
|
+
Test::Unit::TestSuite.new(name)
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class Stack
|
|
10
|
+
def initialize
|
|
11
|
+
@data = []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def push(data)
|
|
15
|
+
@data.push(data)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def peek
|
|
19
|
+
@data[-2]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def empty?
|
|
23
|
+
@data.empty?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def size
|
|
27
|
+
@data.size + 11
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def setup
|
|
32
|
+
@stack = Stack.new
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
attribute :category, :accessor
|
|
36
|
+
def test_peek
|
|
37
|
+
@stack.push(1)
|
|
38
|
+
@stack.push(2)
|
|
39
|
+
assert_equal(2, @stack.peek)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
attribute :bug, 1234
|
|
43
|
+
def test_bug_1234
|
|
44
|
+
assert_equal(0, @stack.size)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_no_attributes
|
|
48
|
+
assert(@stack.empty?)
|
|
49
|
+
@stack.push(1)
|
|
50
|
+
assert(!@stack.empty?)
|
|
51
|
+
assert_equal(1, @stack.size)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_set_attributes
|
|
56
|
+
test_for_accessor_category = TestStack.new("test_peek")
|
|
57
|
+
assert_equal({"category" => :accessor},
|
|
58
|
+
test_for_accessor_category.attributes)
|
|
59
|
+
|
|
60
|
+
test_for_bug_1234 = TestStack.new("test_bug_1234")
|
|
61
|
+
assert_equal({"bug" => 1234}, test_for_bug_1234.attributes)
|
|
62
|
+
|
|
63
|
+
test_no_attributes = TestStack.new("test_no_attributes")
|
|
64
|
+
assert_equal({}, test_no_attributes.attributes)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_callback
|
|
68
|
+
changed_attributes = []
|
|
69
|
+
observer = Proc.new do |test_case, key, old_value, value, method_name|
|
|
70
|
+
changed_attributes << [test_case, key, old_value, value, method_name]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test_case = Class.new(TestStack) do
|
|
74
|
+
register_attribute_observer(:bug, &observer)
|
|
75
|
+
attribute("bug", 9876, "test_bug_1234")
|
|
76
|
+
attribute(:description, "Test for peek", "test_peek")
|
|
77
|
+
attribute(:bug, 29, "test_peek")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
assert_equal([
|
|
81
|
+
[test_case, "bug", 1234, 9876, "test_bug_1234"],
|
|
82
|
+
[test_case, "bug", nil, 29, "test_peek"],
|
|
83
|
+
],
|
|
84
|
+
changed_attributes)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class TestColor < Test::Unit::TestCase
|
|
1
|
+
class TestUnitColor < Test::Unit::TestCase
|
|
4
2
|
def test_color_escape_sequence
|
|
5
3
|
assert_escape_sequence(["31"], color("red"))
|
|
6
4
|
assert_escape_sequence(["32", "1"], color("green", :bold => true))
|
|
@@ -24,11 +22,11 @@ class TestColor < Test::Unit::TestCase
|
|
|
24
22
|
|
|
25
23
|
private
|
|
26
24
|
def color(name, options={})
|
|
27
|
-
Test::Color.new(name, options)
|
|
25
|
+
Test::Unit::Color.new(name, options)
|
|
28
26
|
end
|
|
29
27
|
|
|
30
28
|
def mix_color(colors)
|
|
31
|
-
Test::MixColor.new(colors)
|
|
29
|
+
Test::Unit::MixColor.new(colors)
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
def assert_escape_sequence(expected, color)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class TestUnitDiff < Test::Unit::TestCase
|
|
2
2
|
def test_to_indexes
|
|
3
3
|
assert_to_indexes({"abc def" => [0, 2], "abc" => [1]},
|
|
4
4
|
["abc def", "abc", "abc def"])
|
|
@@ -388,14 +388,14 @@ class TestDiff < Test::Unit::TestCase
|
|
|
388
388
|
|
|
389
389
|
private
|
|
390
390
|
def assert_to_indexes(expected, to, &junk_predicate)
|
|
391
|
-
matcher = Test::Diff::SequenceMatcher.new([""], to, &junk_predicate)
|
|
391
|
+
matcher = Test::Unit::Diff::SequenceMatcher.new([""], to, &junk_predicate)
|
|
392
392
|
assert_equal(expected, matcher.instance_variable_get("@to_indexes"))
|
|
393
393
|
end
|
|
394
394
|
|
|
395
395
|
def assert_find_best_match_position(expected, from, to,
|
|
396
396
|
from_start, from_end,
|
|
397
397
|
to_start, to_end, &junk_predicate)
|
|
398
|
-
matcher = Test::Diff::SequenceMatcher.new(from, to, &junk_predicate)
|
|
398
|
+
matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)
|
|
399
399
|
assert_equal(expected, matcher.send(:find_best_match_position,
|
|
400
400
|
from_start, from_end,
|
|
401
401
|
to_start, to_end))
|
|
@@ -404,70 +404,72 @@ class TestDiff < Test::Unit::TestCase
|
|
|
404
404
|
def assert_longest_match(expected, from, to,
|
|
405
405
|
from_start, from_end,
|
|
406
406
|
to_start, to_end, &junk_predicate)
|
|
407
|
-
matcher = Test::Diff::SequenceMatcher.new(from, to, &junk_predicate)
|
|
407
|
+
matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)
|
|
408
408
|
assert_equal(expected, matcher.longest_match(from_start, from_end,
|
|
409
409
|
to_start, to_end))
|
|
410
410
|
end
|
|
411
411
|
|
|
412
412
|
def assert_matches(expected, from, to, &junk_predicate)
|
|
413
|
-
matcher = Test::Diff::SequenceMatcher.new(from, to, &junk_predicate)
|
|
413
|
+
matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)
|
|
414
414
|
assert_equal(expected, matcher.send(:matches))
|
|
415
415
|
end
|
|
416
416
|
|
|
417
417
|
def assert_blocks(expected, from, to, &junk_predicate)
|
|
418
|
-
matcher = Test::Diff::SequenceMatcher.new(from, to, &junk_predicate)
|
|
418
|
+
matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)
|
|
419
419
|
assert_equal(expected, matcher.blocks)
|
|
420
420
|
end
|
|
421
421
|
|
|
422
422
|
def assert_operations(expected, from, to, &junk_predicate)
|
|
423
|
-
matcher = Test::Diff::SequenceMatcher.new(from, to, &junk_predicate)
|
|
423
|
+
matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)
|
|
424
424
|
assert_equal(expected, matcher.operations)
|
|
425
425
|
end
|
|
426
426
|
|
|
427
427
|
def assert_grouped_operations(expected, from, to)
|
|
428
|
-
matcher = Test::Diff::SequenceMatcher.new(from, to)
|
|
428
|
+
matcher = Test::Unit::Diff::SequenceMatcher.new(from, to)
|
|
429
429
|
assert_equal(expected, matcher.grouped_operations)
|
|
430
430
|
end
|
|
431
431
|
|
|
432
432
|
def assert_ratio(expected, from, to)
|
|
433
|
-
matcher = Test::Diff::SequenceMatcher.new(from, to)
|
|
433
|
+
matcher = Test::Unit::Diff::SequenceMatcher.new(from, to)
|
|
434
434
|
assert_in_delta(expected, 0.001, matcher.ratio)
|
|
435
435
|
end
|
|
436
436
|
|
|
437
437
|
def assert_readable_diff(expected, from, to)
|
|
438
|
-
assert_equal(expected,
|
|
438
|
+
assert_equal(expected,
|
|
439
|
+
Test::Unit::Diff.readable(from.join("\n"), to.join("\n")))
|
|
439
440
|
end
|
|
440
441
|
|
|
441
442
|
def assert_unified_diff(expected, from, to, from_label, to_label, options={})
|
|
442
443
|
options = options.merge(:from_label => from_label,
|
|
443
444
|
:to_label => to_label)
|
|
444
|
-
assert_equal(expected,
|
|
445
|
-
|
|
445
|
+
assert_equal(expected,
|
|
446
|
+
Test::Unit::Diff.unified(from.join("\n"), to.join("\n"),
|
|
447
|
+
options))
|
|
446
448
|
end
|
|
447
449
|
|
|
448
450
|
def assert_diff_lines(expected, from, to,
|
|
449
451
|
from_start, from_end,
|
|
450
452
|
to_start, to_end)
|
|
451
|
-
differ = Test::Diff::ReadableDiffer.new(from, to)
|
|
453
|
+
differ = Test::Unit::Diff::ReadableDiffer.new(from, to)
|
|
452
454
|
assert_equal(expected, differ.send(:diff_lines,
|
|
453
455
|
from_start, from_end,
|
|
454
456
|
to_start, to_end))
|
|
455
457
|
end
|
|
456
458
|
|
|
457
459
|
def assert_diff_line(expected, from_line, to_line)
|
|
458
|
-
differ = Test::Diff::ReadableDiffer.new([""], [""])
|
|
460
|
+
differ = Test::Unit::Diff::ReadableDiffer.new([""], [""])
|
|
459
461
|
assert_equal(expected, differ.send(:diff_line, from_line, to_line))
|
|
460
462
|
end
|
|
461
463
|
|
|
462
464
|
def assert_format_diff_point(expected, from_line, to_line, from_tags, to_tags)
|
|
463
|
-
differ = Test::Diff::ReadableDiffer.new([""], [""])
|
|
465
|
+
differ = Test::Unit::Diff::ReadableDiffer.new([""], [""])
|
|
464
466
|
assert_equal(expected, differ.send(:format_diff_point,
|
|
465
467
|
from_line, to_line,
|
|
466
468
|
from_tags, to_tags))
|
|
467
469
|
end
|
|
468
470
|
|
|
469
471
|
def assert_interesting_line(expected, from, to, from_start, to_start)
|
|
470
|
-
differ = Test::Diff::UnifiedDiffer.new(from, to)
|
|
472
|
+
differ = Test::Unit::Diff::UnifiedDiffer.new(from, to)
|
|
471
473
|
assert_equal(expected, differ.send(:find_interesting_line,
|
|
472
474
|
from_start, to_start,
|
|
473
475
|
:define_line?))
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'test/unit/ui/emacs/testrunner'
|
|
3
|
+
|
|
4
|
+
class TestUnitEmacsRunner < Test::Unit::TestCase
|
|
5
|
+
def test_format_failure_with_a_location
|
|
6
|
+
runner = create_runner
|
|
7
|
+
test_name = "test_failure"
|
|
8
|
+
file = "/home/user/test_xxx.rb"
|
|
9
|
+
line = "3"
|
|
10
|
+
info = "in `xxx'"
|
|
11
|
+
location = "#{file}:#{line}: #{info}"
|
|
12
|
+
message = "FAIL!!!"
|
|
13
|
+
failure = Test::Unit::Failure.new(test_name, [location], message)
|
|
14
|
+
assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure))
|
|
15
|
+
Failure:
|
|
16
|
+
#{test_name} [#{file}:#{line}]:
|
|
17
|
+
#{message}
|
|
18
|
+
EOM
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_format_failure_with_locations
|
|
22
|
+
runner = create_runner
|
|
23
|
+
test_name = "test_failure"
|
|
24
|
+
locations = ["/home/user/test_xxx.rb:3: in `xxx'",
|
|
25
|
+
"/home/user/yyy/test_yyy.rb:999: in `yyy'",
|
|
26
|
+
"/home/user/xyz/zzz.rb:29: in `zzz'"]
|
|
27
|
+
message = "Many backtrace!!!"
|
|
28
|
+
failure = Test::Unit::Failure.new(test_name, locations, message)
|
|
29
|
+
assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure))
|
|
30
|
+
Failure:
|
|
31
|
+
#{test_name}
|
|
32
|
+
#{locations.join("\n")}:
|
|
33
|
+
#{message}
|
|
34
|
+
EOM
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_format_error
|
|
38
|
+
runner = create_runner
|
|
39
|
+
test_name = "test_error"
|
|
40
|
+
message = "Error Message!!!"
|
|
41
|
+
backtrace = ["/home/user/test_xxx.rb:3: in `xxx'",
|
|
42
|
+
"/home/user/yyy/test_yyy.rb:999: in `yyy'",
|
|
43
|
+
"/home/user/xyz/zzz.rb:29: in `zzz'"]
|
|
44
|
+
exception = RuntimeError.new(message)
|
|
45
|
+
exception.set_backtrace(backtrace)
|
|
46
|
+
error = Test::Unit::Error.new(test_name, exception)
|
|
47
|
+
assert_equal(<<-EOM.chomp, runner.send(:format_fault, error))
|
|
48
|
+
Error:
|
|
49
|
+
#{test_name}:
|
|
50
|
+
#{exception.class.name}: #{message}
|
|
51
|
+
#{backtrace.join("\n")}
|
|
52
|
+
EOM
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
def create_runner(suite=nil)
|
|
57
|
+
suite ||= Test::Unit::TestSuite.new
|
|
58
|
+
Test::Unit::UI::Emacs::TestRunner.new(suite)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Author:: Nathaniel Talbott.
|
|
2
|
+
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
|
3
|
+
# License:: Ruby license.
|
|
4
|
+
|
|
5
|
+
require 'test/unit'
|
|
6
|
+
|
|
7
|
+
module Test
|
|
8
|
+
module Unit
|
|
9
|
+
class TC_Error < TestCase
|
|
10
|
+
TF_Exception = Struct.new('TF_Exception', :message, :backtrace)
|
|
11
|
+
def test_display
|
|
12
|
+
ex = TF_Exception.new("message1\nmessage2", ['line1', 'line2'])
|
|
13
|
+
e = Error.new("name", ex)
|
|
14
|
+
assert_equal("name: #{TF_Exception.name}: message1", e.short_display)
|
|
15
|
+
assert_equal(<<EOM.strip, e.long_display)
|
|
16
|
+
Error:
|
|
17
|
+
name:
|
|
18
|
+
Struct::TF_Exception: message1
|
|
19
|
+
message2
|
|
20
|
+
line1
|
|
21
|
+
line2
|
|
22
|
+
EOM
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Author:: Nathaniel Talbott.
|
|
2
|
+
# Copyright:: Copyright (c) 2003 Nathaniel Talbott. All rights reserved.
|
|
3
|
+
# License:: Ruby license.
|
|
4
|
+
|
|
5
|
+
require 'test/unit'
|
|
6
|
+
require 'test/unit/failure'
|
|
7
|
+
|
|
8
|
+
module Test::Unit
|
|
9
|
+
class TestFailure < TestCase
|
|
10
|
+
def test_display
|
|
11
|
+
f = Failure.new("name", [%q{location:1 in 'l'}], "message1\nmessage2")
|
|
12
|
+
assert_equal("name: message1", f.short_display)
|
|
13
|
+
assert_equal(<<EOM.strip, f.long_display)
|
|
14
|
+
Failure:
|
|
15
|
+
name [location:1]:
|
|
16
|
+
message1
|
|
17
|
+
message2
|
|
18
|
+
EOM
|
|
19
|
+
|
|
20
|
+
f = Failure.new("name", [%q{location1:2 in 'l1'}, 'location2:1', %q{location3:3 in 'l3'}], "message1\nmessage2")
|
|
21
|
+
assert_equal("name: message1", f.short_display)
|
|
22
|
+
assert_equal(<<EOM.strip, f.long_display)
|
|
23
|
+
Failure:
|
|
24
|
+
name
|
|
25
|
+
[location1:2 in 'l1'
|
|
26
|
+
location2:1
|
|
27
|
+
location3:3 in 'l3']:
|
|
28
|
+
message1
|
|
29
|
+
message2
|
|
30
|
+
EOM
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
class TestUnitFixture < Test::Unit::TestCase
|
|
2
|
+
def test_setup_without_option
|
|
3
|
+
test_case = assert_setup([:setup,
|
|
4
|
+
:custom_setup_method0,
|
|
5
|
+
:custom_setup_method1,
|
|
6
|
+
:custom_setup_method3],
|
|
7
|
+
[])
|
|
8
|
+
assert_inherited_setup([:setup,
|
|
9
|
+
:custom_setup_method0,
|
|
10
|
+
:custom_setup_method1,
|
|
11
|
+
:custom_setup_method3],
|
|
12
|
+
test_case)
|
|
13
|
+
assert_inherited_setup([:setup], nil)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_setup_with_before_option
|
|
17
|
+
test_case = assert_setup([:custom_setup_method3,
|
|
18
|
+
:custom_setup_method0,
|
|
19
|
+
:custom_setup_method1,
|
|
20
|
+
:setup],
|
|
21
|
+
[[{:before => :append}],
|
|
22
|
+
[{:before => :append}],
|
|
23
|
+
[{:before => :prepend}],
|
|
24
|
+
[{:before => :prepend}]])
|
|
25
|
+
assert_inherited_setup([:custom_setup_method3,
|
|
26
|
+
:custom_setup_method0,
|
|
27
|
+
:custom_setup_method1,
|
|
28
|
+
:setup],
|
|
29
|
+
test_case)
|
|
30
|
+
assert_inherited_setup([:setup], nil)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_setup_with_after_option
|
|
34
|
+
test_case = assert_setup([:setup,
|
|
35
|
+
:custom_setup_method3,
|
|
36
|
+
:custom_setup_method0,
|
|
37
|
+
:custom_setup_method1],
|
|
38
|
+
[[{:after => :append}],
|
|
39
|
+
[{:after => :append}],
|
|
40
|
+
[{:after => :prepend}],
|
|
41
|
+
[{:after => :prepend}]])
|
|
42
|
+
assert_inherited_setup([:setup,
|
|
43
|
+
:custom_setup_method3,
|
|
44
|
+
:custom_setup_method0,
|
|
45
|
+
:custom_setup_method1],
|
|
46
|
+
test_case)
|
|
47
|
+
assert_inherited_setup([:setup], nil)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_setup_with_invalid_option
|
|
51
|
+
assert_invalid_setup_option(:unknown => true)
|
|
52
|
+
assert_invalid_setup_option(:before => :unknown)
|
|
53
|
+
assert_invalid_setup_option(:after => :unknown)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_teardown_without_option
|
|
57
|
+
test_case = assert_teardown([:custom_teardown_method3,
|
|
58
|
+
:custom_teardown_method1,
|
|
59
|
+
:custom_teardown_method0,
|
|
60
|
+
:teardown],
|
|
61
|
+
[])
|
|
62
|
+
assert_inherited_teardown([:custom_teardown_method3,
|
|
63
|
+
:custom_teardown_method1,
|
|
64
|
+
:custom_teardown_method0,
|
|
65
|
+
:teardown],
|
|
66
|
+
test_case)
|
|
67
|
+
assert_inherited_teardown([:teardown], nil)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_teardown_with_before_option
|
|
71
|
+
test_case = assert_teardown([:custom_teardown_method3,
|
|
72
|
+
:custom_teardown_method0,
|
|
73
|
+
:custom_teardown_method1,
|
|
74
|
+
:teardown],
|
|
75
|
+
[[{:before => :append}],
|
|
76
|
+
[{:before => :append}],
|
|
77
|
+
[{:before => :prepend}],
|
|
78
|
+
[{:before => :prepend}]])
|
|
79
|
+
assert_inherited_teardown([:custom_teardown_method3,
|
|
80
|
+
:custom_teardown_method0,
|
|
81
|
+
:custom_teardown_method1,
|
|
82
|
+
:teardown],
|
|
83
|
+
test_case)
|
|
84
|
+
assert_inherited_teardown([:teardown], nil)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_teardown_with_after_option
|
|
88
|
+
test_case = assert_teardown([:teardown,
|
|
89
|
+
:custom_teardown_method3,
|
|
90
|
+
:custom_teardown_method0,
|
|
91
|
+
:custom_teardown_method1],
|
|
92
|
+
[[{:after => :append}],
|
|
93
|
+
[{:after => :append}],
|
|
94
|
+
[{:after => :prepend}],
|
|
95
|
+
[{:after => :prepend}]])
|
|
96
|
+
assert_inherited_teardown([:teardown,
|
|
97
|
+
:custom_teardown_method3,
|
|
98
|
+
:custom_teardown_method0,
|
|
99
|
+
:custom_teardown_method1],
|
|
100
|
+
test_case)
|
|
101
|
+
assert_inherited_teardown([:teardown], nil)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_teardown_with_invalid_option
|
|
105
|
+
assert_invalid_teardown_option(:unknown => true)
|
|
106
|
+
assert_invalid_teardown_option(:before => :unknown)
|
|
107
|
+
assert_invalid_teardown_option(:after => :unknown)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
private
|
|
111
|
+
def assert_setup(expected, setup_options)
|
|
112
|
+
called = []
|
|
113
|
+
test_case = Class.new(Test::Unit::TestCase) do
|
|
114
|
+
@@called = called
|
|
115
|
+
def setup
|
|
116
|
+
@@called << :setup
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
setup(*(setup_options[0] || []))
|
|
120
|
+
def custom_setup_method0
|
|
121
|
+
@@called << :custom_setup_method0
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def custom_setup_method1
|
|
125
|
+
@@called << :custom_setup_method1
|
|
126
|
+
end
|
|
127
|
+
setup(*[:custom_setup_method1, *(setup_options[1] || [])])
|
|
128
|
+
|
|
129
|
+
setup(*(setup_options[2] || []))
|
|
130
|
+
def custom_setup_method2
|
|
131
|
+
@@called << :custom_setup_method2
|
|
132
|
+
end
|
|
133
|
+
unregister_setup(:custom_setup_method2)
|
|
134
|
+
|
|
135
|
+
setup(*(setup_options[3] || []))
|
|
136
|
+
def custom_setup_method3
|
|
137
|
+
@@called << :custom_setup_method3
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def test_nothing
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
test_case.new("test_nothing").run(Test::Unit::TestResult.new) {}
|
|
145
|
+
assert_equal(expected, called)
|
|
146
|
+
test_case
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def assert_inherited_setup(expected, parent)
|
|
150
|
+
called = []
|
|
151
|
+
inherited_test_case = Class.new(parent || Test::Unit::TestCase) do
|
|
152
|
+
@@called = called
|
|
153
|
+
def setup
|
|
154
|
+
@@called << :setup
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def custom_setup_method0
|
|
158
|
+
@@called << :custom_setup_method0
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def custom_setup_method1
|
|
162
|
+
@@called << :custom_setup_method1
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def custom_setup_method2
|
|
166
|
+
@@called << :custom_setup_method2
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def custom_setup_method3
|
|
170
|
+
@@called << :custom_setup_method3
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def test_nothing
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
inherited_test_case.new("test_nothing").run(Test::Unit::TestResult.new) {}
|
|
178
|
+
assert_equal(expected, called)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def assert_teardown(expected, teardown_options)
|
|
182
|
+
called = []
|
|
183
|
+
test_case = Class.new(Test::Unit::TestCase) do
|
|
184
|
+
@@called = called
|
|
185
|
+
def teardown
|
|
186
|
+
@@called << :teardown
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
teardown(*(teardown_options[0] || []))
|
|
190
|
+
def custom_teardown_method0
|
|
191
|
+
@@called << :custom_teardown_method0
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def custom_teardown_method1
|
|
195
|
+
@@called << :custom_teardown_method1
|
|
196
|
+
end
|
|
197
|
+
teardown(*[:custom_teardown_method1, *(teardown_options[1] || [])])
|
|
198
|
+
|
|
199
|
+
teardown(*(teardown_options[2] || []))
|
|
200
|
+
def custom_teardown_method2
|
|
201
|
+
@@called << :custom_teardown_method2
|
|
202
|
+
end
|
|
203
|
+
unregister_teardown(:custom_teardown_method2)
|
|
204
|
+
|
|
205
|
+
teardown(*(teardown_options[3] || []))
|
|
206
|
+
def custom_teardown_method3
|
|
207
|
+
@@called << :custom_teardown_method3
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def test_nothing
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
test_case.new("test_nothing").run(Test::Unit::TestResult.new) {}
|
|
215
|
+
assert_equal(expected, called)
|
|
216
|
+
test_case
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def assert_inherited_teardown(expected, parent)
|
|
220
|
+
called = []
|
|
221
|
+
inherited_test_case = Class.new(parent || Test::Unit::TestCase) do
|
|
222
|
+
@@called = called
|
|
223
|
+
def teardown
|
|
224
|
+
@@called << :teardown
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def custom_teardown_method0
|
|
228
|
+
@@called << :custom_teardown_method0
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def custom_teardown_method1
|
|
232
|
+
@@called << :custom_teardown_method1
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
def custom_teardown_method2
|
|
236
|
+
@@called << :custom_teardown_method2
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def custom_teardown_method3
|
|
240
|
+
@@called << :custom_teardown_method3
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def test_nothing
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
inherited_test_case.new("test_nothing").run(Test::Unit::TestResult.new) {}
|
|
248
|
+
assert_equal(expected, called)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def assert_invalid_option(fixture_type, option)
|
|
252
|
+
exception = assert_raise(ArgumentError) do
|
|
253
|
+
Class.new(Test::Unit::TestCase) do
|
|
254
|
+
def test_nothing
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
send(fixture_type, option)
|
|
258
|
+
def fixture
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
assert_equal("must be {:before => :prepend}, {:before => :append}, " +
|
|
263
|
+
"{:after => :prepend} or {:after => :append}" +
|
|
264
|
+
": #{option.inspect}",
|
|
265
|
+
exception.message)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def assert_invalid_setup_option(option)
|
|
269
|
+
assert_invalid_option(:setup, option)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def assert_invalid_teardown_option(option)
|
|
273
|
+
assert_invalid_option(:teardown, option)
|
|
274
|
+
end
|
|
275
|
+
end
|