mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
handle exceptions in tests and reduce syntax features in assert code
This commit is contained in:
+41
-18
@@ -1,6 +1,19 @@
|
||||
$ok_test = 0
|
||||
$ko_test = 0
|
||||
$kill_test = 0
|
||||
$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.
|
||||
@@ -11,13 +24,18 @@ $asserts = []
|
||||
# which will be tested by this
|
||||
# assertion
|
||||
def assert(str = 'Assertion failed', iso = '')
|
||||
if(!yield)
|
||||
$asserts.push([str, iso])
|
||||
$ko_test += 1
|
||||
print "F"
|
||||
else
|
||||
$ok_test += 1
|
||||
print "."
|
||||
begin
|
||||
if(!yield)
|
||||
$asserts.push([str, iso])
|
||||
$ko_test += 1
|
||||
print('F')
|
||||
else
|
||||
$ok_test += 1
|
||||
print('.')
|
||||
end
|
||||
rescue
|
||||
$kill_test += 1
|
||||
print('X')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,18 +45,23 @@ end
|
||||
def report()
|
||||
print "\n"
|
||||
$asserts.each do |str, iso|
|
||||
print("Test Failed: #{str} [#{iso}]\n");
|
||||
print('Fail: ');
|
||||
print_assertion_string(str, iso)
|
||||
print("\n")
|
||||
end
|
||||
|
||||
$total_test = $ok_test + $ko_test
|
||||
print 'Total tests:'
|
||||
print $total_test
|
||||
print "\n"
|
||||
$total_test = $ok_test.+($ko_test)
|
||||
print('Total: ')
|
||||
print($total_test)
|
||||
print("\n")
|
||||
|
||||
print ' OK: '
|
||||
print $ok_test
|
||||
print "\n"
|
||||
print ' KO: '
|
||||
print $ko_test
|
||||
print "\n"
|
||||
print(' OK: ')
|
||||
print($ok_test)
|
||||
print("\n")
|
||||
print(' KO: ')
|
||||
print($ko_test)
|
||||
print("\n")
|
||||
print(' Crash: ')
|
||||
print($kill_test)
|
||||
print("\n")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user