Skip to content
Newer
Older
100644 93 lines (85 sloc) 1.69 KB
c8c0ef8 @bovi mrit - Embeddable Ruby ISO Test
bovi authored
1 $ok_test = 0
2 $ko_test = 0
769a7e0 @bovi handle exceptions in tests and reduce syntax features in assert code
bovi authored
3 $kill_test = 0
c8c0ef8 @bovi mrit - Embeddable Ruby ISO Test
bovi authored
4 $asserts = []
2ae84f7 @bovi Add execution time to tests
bovi authored
5 $test_start = Time.now if Object.const_defined?(:Time)
769a7e0 @bovi handle exceptions in tests and reduce syntax features in assert code
bovi authored
6
7 ##
8 # Print the assertion in a readable way
9 def print_assertion_string(str, iso)
10 print(str)
11 if(iso != '')
12 print(' [')
13 print(iso)
14 print(']')
15 end
16 end
c8c0ef8 @bovi mrit - Embeddable Ruby ISO Test
bovi authored
17
18 ##
19 # Verify a code block.
20 #
21 # str : A remark which will be printed in case
22 # this assertion fails
23 # iso : The ISO reference code of the feature
24 # which will be tested by this
25 # assertion
21bd5d7 @matz print description on exceptions
matz authored
26 def assert(str = 'Assertion failed', iso = '')
769a7e0 @bovi handle exceptions in tests and reduce syntax features in assert code
bovi authored
27 begin
28 if(!yield)
21bd5d7 @matz print description on exceptions
matz authored
29 $asserts.push(['Fail: ', str, iso])
769a7e0 @bovi handle exceptions in tests and reduce syntax features in assert code
bovi authored
30 $ko_test += 1
31 print('F')
32 else
33 $ok_test += 1
34 print('.')
35 end
bddbf20 @monaka Assert should handle all exceptions.
monaka authored
36 rescue Exception => e
21bd5d7 @matz print description on exceptions
matz authored
37 $asserts.push(['Error: ', str, iso, e])
769a7e0 @bovi handle exceptions in tests and reduce syntax features in assert code
bovi authored
38 $kill_test += 1
39 print('X')
c8c0ef8 @bovi mrit - Embeddable Ruby ISO Test
bovi authored
40 end
41 end
42
43 ##
44 # Report the test result and print all assertions
45 # which were reported broken.
46 def report()
47 print "\n"
21bd5d7 @matz print description on exceptions
matz authored
48 $asserts.each do |err, str, iso, e|
49 print(err);
769a7e0 @bovi handle exceptions in tests and reduce syntax features in assert code
bovi authored
50 print_assertion_string(str, iso)
21bd5d7 @matz print description on exceptions
matz authored
51 if e
52 print(" => ")
53 print(e.message)
54 end
769a7e0 @bovi handle exceptions in tests and reduce syntax features in assert code
bovi authored
55 print("\n")
c8c0ef8 @bovi mrit - Embeddable Ruby ISO Test
bovi authored
56 end
57
769a7e0 @bovi handle exceptions in tests and reduce syntax features in assert code
bovi authored
58 $total_test = $ok_test.+($ko_test)
59 print('Total: ')
60 print($total_test)
61 print("\n")
c8c0ef8 @bovi mrit - Embeddable Ruby ISO Test
bovi authored
62
dacecdb @bovi Better indention of assert report
bovi authored
63 print(' OK: ')
769a7e0 @bovi handle exceptions in tests and reduce syntax features in assert code
bovi authored
64 print($ok_test)
65 print("\n")
dacecdb @bovi Better indention of assert report
bovi authored
66 print(' KO: ')
769a7e0 @bovi handle exceptions in tests and reduce syntax features in assert code
bovi authored
67 print($ko_test)
68 print("\n")
dacecdb @bovi Better indention of assert report
bovi authored
69 print('Crash: ')
769a7e0 @bovi handle exceptions in tests and reduce syntax features in assert code
bovi authored
70 print($kill_test)
71 print("\n")
2ae84f7 @bovi Add execution time to tests
bovi authored
72
73 if Object.const_defined?(:Time)
74 print(' Time: ')
75 print(Time.now - $test_start)
76 print(" seconds\n")
77 end
c8c0ef8 @bovi mrit - Embeddable Ruby ISO Test
bovi authored
78 end
dd6af6d @bovi Add newline in the end of test case files so that the concat of all f…
bovi authored
79
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
80 ##
81 # Performs fuzzy check for equality on methods returning floats
82 # on the basis of the Math::TOLERANCE constant.
83 def check_float(a, b)
34cf056 @matz add Math::TOLERANCE
matz authored
84 tolerance = Math::TOLERANCE
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
85 a = a.to_f
86 b = b.to_f
87 if a.finite? and b.finite?
501f7f6 @matz stop introducing Math::TORELANCE
matz authored
88 (a-b).abs < tolerance
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
89 else
90 true
91 end
92 end
Something went wrong with that request. Please try again.