summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorDaniel Bovensiepen <[email protected]>2012-05-16 15:47:22 +0800
committerDaniel Bovensiepen <[email protected]>2012-05-16 15:47:22 +0800
commit769a7e0ed3a33c5ec4925491202c09db35e3c485 (patch)
tree1bcfc8fed7898997a4a688b40b2b230a12f18a48 /test
parentf202658d80105755fd56a664c4d4013fa71b21d4 (diff)
downloadmruby-769a7e0ed3a33c5ec4925491202c09db35e3c485.tar.gz
mruby-769a7e0ed3a33c5ec4925491202c09db35e3c485.zip
handle exceptions in tests and reduce syntax features in assert code
Diffstat (limited to 'test')
-rw-r--r--test/t/_assert.rb59
1 files changed, 41 insertions, 18 deletions
diff --git a/test/t/_assert.rb b/test/t/_assert.rb
index 91751f769..d132e4a30 100644
--- a/test/t/_assert.rb
+++ b/test/t/_assert.rb
@@ -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