source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/test/unit/testresult.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 2.0 KB
Line 
1#--
2# Author:: Nathaniel Talbott.
3# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
4# License:: Ruby license.
5
6require 'test/unit/util/observable'
7
8module Test
9 module Unit
10
11 # Collects Test::Unit::Failure and Test::Unit::Error so that
12 # they can be displayed to the user. To this end, observers
13 # can be added to it, allowing the dynamic updating of, say, a
14 # UI.
15 class TestResult
16 include Util::Observable
17
18 CHANGED = "CHANGED"
19 FAULT = "FAULT"
20
21 attr_reader(:run_count, :assertion_count)
22
23 # Constructs a new, empty TestResult.
24 def initialize
25 @run_count, @assertion_count = 0, 0
26 @failures, @errors = Array.new, Array.new
27 end
28
29 # Records a test run.
30 def add_run
31 @run_count += 1
32 notify_listeners(CHANGED, self)
33 end
34
35 # Records a Test::Unit::Failure.
36 def add_failure(failure)
37 @failures << failure
38 notify_listeners(FAULT, failure)
39 notify_listeners(CHANGED, self)
40 end
41
42 # Records a Test::Unit::Error.
43 def add_error(error)
44 @errors << error
45 notify_listeners(FAULT, error)
46 notify_listeners(CHANGED, self)
47 end
48
49 # Records an individual assertion.
50 def add_assertion
51 @assertion_count += 1
52 notify_listeners(CHANGED, self)
53 end
54
55 # Returns a string contain the recorded runs, assertions,
56 # failures and errors in this TestResult.
57 def to_s
58 "#{run_count} tests, #{assertion_count} assertions, #{failure_count} failures, #{error_count} errors"
59 end
60
61 # Returns whether or not this TestResult represents
62 # successful completion.
63 def passed?
64 return @failures.empty? && @errors.empty?
65 end
66
67 # Returns the number of failures this TestResult has
68 # recorded.
69 def failure_count
70 return @failures.size
71 end
72
73 # Returns the number of errors this TestResult has
74 # recorded.
75 def error_count
76 return @errors.size
77 end
78 end
79 end
80end
Note: See TracBrowser for help on using the repository browser.