From 769a7e0ed3a33c5ec4925491202c09db35e3c485 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 16 May 2012 15:47:22 +0800 Subject: handle exceptions in tests and reduce syntax features in assert code --- test/t/_assert.rb | 59 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 18 deletions(-) (limited to 'test/t/_assert.rb') 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 -- cgit v1.2.3 From 254023f1e795491cacd31944526c7c4d037599cf Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 16 May 2012 15:49:40 +0800 Subject: Remove array for now due to the reason that they are lost after exception was raised --- test/t/_assert.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'test/t/_assert.rb') diff --git a/test/t/_assert.rb b/test/t/_assert.rb index d132e4a30..ecca78656 100644 --- a/test/t/_assert.rb +++ b/test/t/_assert.rb @@ -2,7 +2,6 @@ $ok_test = 0 $ko_test = 0 $kill_test = 0 $asserts = [] -$exceptions = [] ## # Print the assertion in a readable way -- cgit v1.2.3 From dd6af6d2ec17c88c87844e75cd973fb4569c4c88 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 16 May 2012 16:00:05 +0800 Subject: Add newline in the end of test case files so that the concat of all files works in all cases proper --- test/t/_assert.rb | 1 + test/t/bs_block.rb | 1 + test/t/bs_class.rb | 1 + test/t/bs_exception.rb | 3 ++- test/t/bs_literal.rb | 3 ++- test/t/time.rb | 1 + 6 files changed, 8 insertions(+), 2 deletions(-) (limited to 'test/t/_assert.rb') diff --git a/test/t/_assert.rb b/test/t/_assert.rb index ecca78656..b2ce616e0 100644 --- a/test/t/_assert.rb +++ b/test/t/_assert.rb @@ -64,3 +64,4 @@ def report() print($kill_test) print("\n") end + diff --git a/test/t/bs_block.rb b/test/t/bs_block.rb index b290cb914..acbade449 100644 --- a/test/t/bs_block.rb +++ b/test/t/bs_block.rb @@ -388,3 +388,4 @@ assert('BS Block [ruby-core:14395]') do t = Controller.new t.test_for_bug end + diff --git a/test/t/bs_class.rb b/test/t/bs_class.rb index ae8668230..d8bb63c05 100644 --- a/test/t/bs_class.rb +++ b/test/t/bs_class.rb @@ -118,3 +118,4 @@ end assert('BS Class Dup 2') do module M; end; M.dup.class == Module end + diff --git a/test/t/bs_exception.rb b/test/t/bs_exception.rb index 406c07467..6ab2cee2a 100644 --- a/test/t/bs_exception.rb +++ b/test/t/bs_exception.rb @@ -154,4 +154,5 @@ assert('BS Exception 10') do ensure 7+7 end == 12 -end +end + diff --git a/test/t/bs_literal.rb b/test/t/bs_literal.rb index a79b0b045..b1ae3a5d6 100644 --- a/test/t/bs_literal.rb +++ b/test/t/bs_literal.rb @@ -35,4 +35,5 @@ end assert('BS Literal 9') do Fixnum == 1234.class -end \ No newline at end of file +end + diff --git a/test/t/time.rb b/test/t/time.rb index f33cdde0d..98b99f2c2 100644 --- a/test/t/time.rb +++ b/test/t/time.rb @@ -71,3 +71,4 @@ end assert('Time#new') do Time.new.class == Time end + -- cgit v1.2.3 From 26c6031a53867011eb33b624ed245d5603b778cf Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 16 May 2012 16:07:55 +0800 Subject: Move assert lib for tests one directory up and add it always in the beginning --- test/Makefile | 3 ++- test/assert.rb | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/t/_assert.rb | 67 ------------------------------------------------------- 3 files changed, 69 insertions(+), 68 deletions(-) create mode 100644 test/assert.rb delete mode 100644 test/t/_assert.rb (limited to 'test/t/_assert.rb') diff --git a/test/Makefile b/test/Makefile index 26c898704..7f5c16980 100644 --- a/test/Makefile +++ b/test/Makefile @@ -12,6 +12,7 @@ INIT := init_$(TARGET).c DLIB := $(TARGET).ctmp RLIB := $(TARGET).rbtmp DEPLIB := $(TARGET).d driver.d +ASSLIB := $(BASEDIR)/assert.rb MRBS := $(BASEDIR)/t/*.rb OBJS := driver.o $(MLIB) @@ -95,7 +96,7 @@ $(MRBC) : ../src/opcode.h ../src/codegen.c ../src/parse.y $(MAKE) -C ../tools/mrbc $(MAKE_FLAGS) # merge mruby sources -$(RLIB) : $(MRBS) +$(RLIB) : $(ASSLIB) $(MRBS) cat $? > $@ # clean up diff --git a/test/assert.rb b/test/assert.rb new file mode 100644 index 000000000..b2ce616e0 --- /dev/null +++ b/test/assert.rb @@ -0,0 +1,67 @@ +$ok_test = 0 +$ko_test = 0 +$kill_test = 0 +$asserts = [] + +## +# 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. +# +# str : A remark which will be printed in case +# this assertion fails +# iso : The ISO reference code of the feature +# which will be tested by this +# assertion +def assert(str = 'Assertion failed', iso = '') + 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 + +## +# Report the test result and print all assertions +# which were reported broken. +def report() + print "\n" + $asserts.each do |str, iso| + print('Fail: '); + print_assertion_string(str, iso) + print("\n") + end + + $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(' Crash: ') + print($kill_test) + print("\n") +end + diff --git a/test/t/_assert.rb b/test/t/_assert.rb deleted file mode 100644 index b2ce616e0..000000000 --- a/test/t/_assert.rb +++ /dev/null @@ -1,67 +0,0 @@ -$ok_test = 0 -$ko_test = 0 -$kill_test = 0 -$asserts = [] - -## -# 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. -# -# str : A remark which will be printed in case -# this assertion fails -# iso : The ISO reference code of the feature -# which will be tested by this -# assertion -def assert(str = 'Assertion failed', iso = '') - 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 - -## -# Report the test result and print all assertions -# which were reported broken. -def report() - print "\n" - $asserts.each do |str, iso| - print('Fail: '); - print_assertion_string(str, iso) - print("\n") - end - - $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(' Crash: ') - print($kill_test) - print("\n") -end - -- cgit v1.2.3