From 530537de1ac331ffc6e5eeff9c5fad7c0059789e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 9 Oct 2015 21:53:22 +0300 Subject: [PATCH] improve fragment checks --- test/compiler/code_checker.rb | 3 ++- test/fragments/helper.rb | 18 ++++++++++++------ test/fragments/test_class.rb | 2 +- test/fragments/test_foo.rb | 3 ++- test/fragments/test_functions.rb | 3 ++- test/fragments/test_hello.rb | 3 ++- test/fragments/test_if.rb | 9 ++++++--- test/fragments/test_putint.rb | 3 ++- test/fragments/test_recursive_fibo.rb | 3 ++- test/fragments/test_while_fibo.rb | 3 ++- 10 files changed, 33 insertions(+), 17 deletions(-) diff --git a/test/compiler/code_checker.rb b/test/compiler/code_checker.rb index cce9073a..72c96d9f 100644 --- a/test/compiler/code_checker.rb +++ b/test/compiler/code_checker.rb @@ -1,6 +1,7 @@ module CodeChecker def check - Virtual.machine.boot.parse_and_compile @string_input + machine = Virtual.machine.boot + machine.parse_and_compile @string_input produced = Virtual.machine.space.get_main.source assert @output , "No output given" assert_equal @output.length , produced.blocks.length , "Block length" diff --git a/test/fragments/helper.rb b/test/fragments/helper.rb index 07b92e76..ecfbd6d0 100644 --- a/test/fragments/helper.rb +++ b/test/fragments/helper.rb @@ -7,13 +7,19 @@ require_relative '../helper' module Fragments def check - statements = Virtual.machine.boot.parse_and_compile @string_input - @expect.each_with_index do | should , i | - exp_i = statements[i] - assert exp_i.is_a?(Virtual::Slot) , "compiles should return #{should}, not #{exp_i}" - assert_equal should , exp_i.class + machine = Virtual.machine.boot + machine.parse_and_compile @string_input + produced = Virtual.machine.space.get_main.source + assert @expect , "No output given" + assert_equal @expect.length , produced.blocks.length , "Block length" + produced.blocks.each_with_index do |b,i| + codes = @expect[i] + assert codes , "No codes for block #{i}" + assert_equal b.codes.length , codes.length , "Code length for block #{i+1}" + b.codes.each_with_index do |c , ii | + assert_equal codes[ii] , c.class , "Block #{i+1} , code #{ii+1}" + end end -# Virtual.machine.run_passes end # helper to write the file diff --git a/test/fragments/test_class.rb b/test/fragments/test_class.rb index 4f31efcf..43dbe7b6 100644 --- a/test/fragments/test_class.rb +++ b/test/fragments/test_class.rb @@ -11,7 +11,7 @@ class Bar end end HERE - @expect = [ Virtual::Return ] + @expect = [ [Virtual::MethodEnter] ,[Virtual::MethodReturn]] check end diff --git a/test/fragments/test_foo.rb b/test/fragments/test_foo.rb index ce1fba1a..de851ddb 100644 --- a/test/fragments/test_foo.rb +++ b/test/fragments/test_foo.rb @@ -16,7 +16,8 @@ class Object end end HERE - @expect = [ Virtual::Return ] + @expect = [ [Virtual::MethodEnter,Virtual::NewMessage,Virtual::Set,Virtual::Set, + Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] check end diff --git a/test/fragments/test_functions.rb b/test/fragments/test_functions.rb index 7834b242..01f22c0d 100644 --- a/test/fragments/test_functions.rb +++ b/test/fragments/test_functions.rb @@ -35,7 +35,8 @@ class Object end end HERE - @expect = [Virtual::Return ] + @expect = [[Virtual::MethodEnter,Virtual::NewMessage,Virtual::Set,Virtual::Set,Virtual::MethodCall] , + [Virtual::MethodReturn]] check end diff --git a/test/fragments/test_hello.rb b/test/fragments/test_hello.rb index ca9187c4..f3d0cdd2 100644 --- a/test/fragments/test_hello.rb +++ b/test/fragments/test_hello.rb @@ -11,7 +11,8 @@ class Object end end HERE - @expect = [] + @expect = [[Virtual::MethodEnter,Virtual::Set,Virtual::NewMessage,Virtual::Set, + Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn]] check end end diff --git a/test/fragments/test_if.rb b/test/fragments/test_if.rb index 8364900d..2d9910c7 100644 --- a/test/fragments/test_if.rb +++ b/test/fragments/test_if.rb @@ -16,7 +16,9 @@ class Object end end HERE - @expect = [Virtual::Return ] + @expect = [[Virtual::MethodEnter,Virtual::Set,Virtual::Set,Register::GetSlot, + Register::GetSlot,Register::OperatorInstruction,Register::IsZeroBranch] , + [Virtual::Set,Register::AlwaysBranch] ,[Virtual::Set] ,[] ,[Virtual::MethodReturn] ] check end @@ -28,7 +30,7 @@ class Object end end HERE - @expect = [Virtual::Return ] + @expect = [[Virtual::MethodEnter,Virtual::Set] , [Virtual::MethodReturn]] check end @@ -49,7 +51,8 @@ class Object end end HERE - @expect = [Virtual::Return ] + @expect = [ [Virtual::MethodEnter,Virtual::NewMessage,Virtual::Set,Virtual::Set, + Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] check end end diff --git a/test/fragments/test_putint.rb b/test/fragments/test_putint.rb index ee46d4b3..508a44a4 100644 --- a/test/fragments/test_putint.rb +++ b/test/fragments/test_putint.rb @@ -11,7 +11,8 @@ class Object end end HERE - @expect = [] + @expect = [ [Virtual::MethodEnter,Virtual::Set,Virtual::NewMessage,Virtual::Set, + Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] check end end diff --git a/test/fragments/test_recursive_fibo.rb b/test/fragments/test_recursive_fibo.rb index bcf02240..a478374e 100644 --- a/test/fragments/test_recursive_fibo.rb +++ b/test/fragments/test_recursive_fibo.rb @@ -27,7 +27,8 @@ class Object end end HERE - @expect = [Virtual::Return ] + @expect = [[Virtual::MethodEnter,Virtual::NewMessage,Virtual::Set,Virtual::Set, + Virtual::Set,Virtual::Set,Virtual::MethodCall] , [Virtual::MethodReturn]] check end end diff --git a/test/fragments/test_while_fibo.rb b/test/fragments/test_while_fibo.rb index 8ae79dce..6dd8e846 100644 --- a/test/fragments/test_while_fibo.rb +++ b/test/fragments/test_while_fibo.rb @@ -24,7 +24,8 @@ class Object end end HERE - @expect = [Virtual::Return ] + @expect = [ [Virtual::MethodEnter,Virtual::NewMessage,Virtual::Set,Virtual::Set, + Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] check end