From ece017fa86ea2ec0fd240042d8196b103a99f959 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 17 Dec 2016 00:15:27 +0200 Subject: [PATCH] small shuffle of test helpers, also guard helpers --- Guardfile | 1 + test/helper.rb | 8 ++++++++ test/register/interpreter/helper.rb | 7 ++++++- test/typed/statements/helper.rb | 7 ++----- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Guardfile b/Guardfile index 9461c70c..32eaef56 100644 --- a/Guardfile +++ b/Guardfile @@ -4,6 +4,7 @@ guard :minitest do # with Minitest::Unit watch(%r{^test/(.*)\/?test_(.*)\.rb$}) + watch(%r{^test/(.*/)?helper.rb$}) { |m| "test/#{m[1]}test_all.rb" } watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" } watch(%r{^test/test_helper\.rb$}) { 'test' } diff --git a/test/helper.rb b/test/helper.rb index 0e0167f9..9fdd961b 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -19,6 +19,14 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'test')) require 'salama' +module Compiling + def clean_compile(clazz_name , method_name , args , statements) + compiler = Typed::Compiler.new.create_method(clazz_name,method_name,args ).init_method + compiler.process( Typed.ast_to_code( statements ) ) + end + +end + class Ignored def == other return false unless other.class == self.class diff --git a/test/register/interpreter/helper.rb b/test/register/interpreter/helper.rb index 92a087ca..e3e6dbf7 100644 --- a/test/register/interpreter/helper.rb +++ b/test/register/interpreter/helper.rb @@ -1,4 +1,4 @@ -require_relative "../../helper" +require_relative "../helper" require "register/interpreter" module Ticker @@ -6,12 +6,17 @@ module Ticker def setup machine = Register.machine.boot + do_clean_compile Typed.compile( @input ) machine.collect @interpreter = Register::Interpreter.new @interpreter.start Register.machine.init end + # must be after boot, but before main compile, to define method + def do_clean_compile + end + def check_chain should should.each_with_index do |name , index| got = ticks(1) diff --git a/test/typed/statements/helper.rb b/test/typed/statements/helper.rb index fa3afc7b..f2e59efd 100644 --- a/test/typed/statements/helper.rb +++ b/test/typed/statements/helper.rb @@ -3,19 +3,16 @@ require_relative '../helper' module Statements include AST::Sexp + include Compiling def setup Register.machine.boot # force boot to reset main end - def clean_compile(clazz_name , method_name , args , statements) - compiler = Typed::Compiler.new.create_method(clazz_name,method_name,args ).init_method - compiler.process( Typed.ast_to_code( statements ) ) - end def check assert @expect , "No output given" - compiler = Typed::Compiler.new Register.machine.space.get_main + compiler = Typed::Compiler.new produced = compiler.process( Typed.ast_to_code( @input) ) produced = Register.machine.space.get_main.instructions compare_instructions produced , @expect