Commit 769a7e0e authored by Daniel Bovensiepen's avatar Daniel Bovensiepen

handle exceptions in tests and reduce syntax features in assert code

parent f202658d
$ok_test = 0 $ok_test = 0
$ko_test = 0 $ko_test = 0
$kill_test = 0
$asserts = [] $asserts = []
$exceptions = []
##
# Print the assertion in a readable way
def print_assertion_string(str, iso)
print(str)
if(iso != '')
print(' [')
print(iso)
print(']')
end
end
## ##
# Verify a code block. # Verify a code block.
...@@ -11,13 +24,18 @@ $asserts = [] ...@@ -11,13 +24,18 @@ $asserts = []
# which will be tested by this # which will be tested by this
# assertion # assertion
def assert(str = 'Assertion failed', iso = '') def assert(str = 'Assertion failed', iso = '')
begin
if(!yield) if(!yield)
$asserts.push([str, iso]) $asserts.push([str, iso])
$ko_test += 1 $ko_test += 1
print "F" print('F')
else else
$ok_test += 1 $ok_test += 1
print "." print('.')
end
rescue
$kill_test += 1
print('X')
end end
end end
...@@ -27,18 +45,23 @@ end ...@@ -27,18 +45,23 @@ end
def report() def report()
print "\n" print "\n"
$asserts.each do |str, iso| $asserts.each do |str, iso|
print("Test Failed: #{str} [#{iso}]\n"); print('Fail: ');
print_assertion_string(str, iso)
print("\n")
end end
$total_test = $ok_test + $ko_test $total_test = $ok_test.+($ko_test)
print 'Total tests:' print('Total: ')
print $total_test print($total_test)
print "\n" print("\n")
print ' OK: ' print(' OK: ')
print $ok_test print($ok_test)
print "\n" print("\n")
print ' KO: ' print(' KO: ')
print $ko_test print($ko_test)
print "\n" print("\n")
print(' Crash: ')
print($kill_test)
print("\n")
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment