From 8085817cb5737ca0c2a4afb5e3d013a395e12eb4 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 14 May 2012 23:04:13 +0900 Subject: make test restructuring --- Makefile | 8 ++---- test/Makefile | 65 ++++++++++++++++++++++++++++++++---------- test/_assert.rb | 44 ---------------------------- test/array.rb | 40 -------------------------- test/driver.c | 59 ++++++++++++++++++++++++++++++++++++++ test/init_mrbtest.c | 16 +++++++++++ test/init_mritlib.c | 17 ----------- test/t/_assert.rb | 44 ++++++++++++++++++++++++++++ test/t/array.rb | 40 ++++++++++++++++++++++++++ test/t/time.rb | 73 +++++++++++++++++++++++++++++++++++++++++++++++ test/time.rb | 73 ----------------------------------------------- tools/mrit/Makefile | 82 ----------------------------------------------------- tools/mrit/mrit.c | 59 -------------------------------------- 13 files changed, 285 insertions(+), 335 deletions(-) delete mode 100644 test/_assert.rb delete mode 100644 test/array.rb create mode 100644 test/driver.c create mode 100644 test/init_mrbtest.c delete mode 100644 test/init_mritlib.c create mode 100644 test/t/_assert.rb create mode 100644 test/t/array.rb create mode 100644 test/t/time.rb delete mode 100644 test/time.rb delete mode 100644 tools/mrit/Makefile delete mode 100644 tools/mrit/mrit.c diff --git a/Makefile b/Makefile index 5b605131a..2870dcf29 100644 --- a/Makefile +++ b/Makefile @@ -27,11 +27,10 @@ all : @$(MAKE) -C tools/mruby $(MAKE_FLAGS) @$(MAKE) -C tools/mirb $(MAKE_FLAGS) -# mruby iso test -.PHONY : mrit -mrit : +# mruby test +.PHONY : test +test : @$(MAKE) -C test $(MAKE_FLAGS) - @$(MAKE) -C tools/mrit $(MAKE_FLAGS) # clean up .PHONY : clean @@ -39,5 +38,4 @@ clean : @$(MAKE) clean -C src $(MAKE_FLAGS) @$(MAKE) clean -C tools/mruby $(MAKE_FLAGS) @$(MAKE) clean -C tools/mirb $(MAKE_FLAGS) - @$(MAKE) clean -C tools/mrit $(MAKE_FLAGS) @$(MAKE) clean -C test $(MAKE_FLAGS) diff --git a/test/Makefile b/test/Makefile index b7a6572c8..26c898704 100644 --- a/test/Makefile +++ b/test/Makefile @@ -4,15 +4,16 @@ # project-specific macros # extension of the executable-file is modifiable(.exe .out ...) BASEDIR = . -TARGET := mritlib +TARGET := mrbtest +LIBR := ../lib/libmruby.a MLIB := $(TARGET).o CLIB := $(TARGET).c +INIT := init_$(TARGET).c DLIB := $(TARGET).ctmp RLIB := $(TARGET).rbtmp -DEPLIB := $(TARGET).d -MRB1 := $(BASEDIR)/*.rb -MRBS := $(MRB1) -LIBR := ../lib/libmrit.a +DEPLIB := $(TARGET).d driver.d +MRBS := $(BASEDIR)/t/*.rb +OBJS := driver.o $(MLIB) # C compiler (gcc) CC = gcc @@ -32,28 +33,63 @@ else MAKE_FLAGS = CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' endif -# mruby compiler +# mruby compiler and test driver ifeq ($(OS),Windows_NT) MRBC = ../bin/mrbc.exe +EXE := $(TARGET).exe else MRBC = ../bin/mrbc +EXE := $(TARGET) +endif + +# libraries, includes +LIBS = -lm + +# compiler, linker (gcc) +CC = gcc +LL = gcc +YACC = bison +DEBUG_MODE = 1 +ifeq ($(DEBUG_MODE),1) +CFLAGS = -g -O3 +else +CFLAGS = -O3 +endif +ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) +ifeq ($(OS),Windows_NT) + MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" +else + MAKE_FLAGS = CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' endif ############################## # generic build targets, rules .PHONY : all -all : $(MRBC) $(MLIB) - $(AR) r $(LIBR) $(MLIB) +all : $(LIBR) $(EXE) @echo "make: built targets of `pwd`" -# Compile mrblib source -$(MLIB) : $(CLIB) - $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $(CLIB) -o $(MLIB) +.PHONY : test +all : $(LIBR) $(EXE) + ./$(EXE) + +# executable constructed using linker from object files +$(EXE) : $(LIBR) $(OBJS) + $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBR) $(LIBS) + +-include $(OBJS:.o=.d) + +# objects compiled from source +$(OBJS) : %.o : %.c + $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ + +# C library compile +$(LIBR) : + @$(MAKE) -C $(BASEDIR) $(MAKE_FLAGS) # Compile C source from merged mruby source -$(CLIB) : $(RLIB) $(MRBC) - $(MRBC) -Bmritlib_irep -o$(DLIB) $(RLIB); cat init_$(TARGET).c $(DLIB) > $@ +$(CLIB) : $(RLIB) $(MRBC) $(INIT) + $(MRBC) -Bmrbtest_irep -o$(DLIB) $(RLIB); cat $(INIT) $(DLIB) > $@ $(MRBC) : ../src/opcode.h ../src/codegen.c ../src/parse.y $(MAKE) -C ../tools/mrbc $(MAKE_FLAGS) @@ -66,5 +102,4 @@ $(RLIB) : $(MRBS) .PHONY : clean clean : @echo "make: removing targets, objects and depend files of `pwd`" - -rm -f $(MRBC) $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(LIBR) - + -rm -f $(MRBC) $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(OBJS) $(EXE) diff --git a/test/_assert.rb b/test/_assert.rb deleted file mode 100644 index 91751f769..000000000 --- a/test/_assert.rb +++ /dev/null @@ -1,44 +0,0 @@ -$ok_test = 0 -$ko_test = 0 -$asserts = [] - -## -# 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 = '') - if(!yield) - $asserts.push([str, iso]) - $ko_test += 1 - print "F" - else - $ok_test += 1 - print "." - end -end - -## -# Report the test result and print all assertions -# which were reported broken. -def report() - print "\n" - $asserts.each do |str, iso| - print("Test Failed: #{str} [#{iso}]\n"); - end - - $total_test = $ok_test + $ko_test - print 'Total tests:' - print $total_test - print "\n" - - print ' OK: ' - print $ok_test - print "\n" - print ' KO: ' - print $ko_test - print "\n" -end diff --git a/test/array.rb b/test/array.rb deleted file mode 100644 index 3b65a80dd..000000000 --- a/test/array.rb +++ /dev/null @@ -1,40 +0,0 @@ -## -# Array ISO Test - -assert('Array', '15.2.12') do - Array.class == Class -end - -assert('Array.[]', '15.2.12.4.1') do - Array.[](1,2,3) == [1, 2, 3] -end - -assert('Array#*', '15.2.12.5.1') do - [1].*(3) == [1, 1, 1] -end - -assert('Array#+', '15.2.12.5.2') do - [1].+([1]) == [1, 1] -end - -assert('Array#<<', '15.2.12.5.3') do - [1].<<(1) == [1, 1] -end - -assert('Array#[]', '15.2.12.5.4') do - [1,2,3].[](1) == 2 -end - -assert('Array#[]=', '15.2.12.5.5') do - [1,2,3].[]=(1,4) == [1, 4, 3] -end - -assert('Array#clear', '15.2.12.5.6') do - a = [1] - a.clear - a == [] -end - -# Not ISO specified - - diff --git a/test/driver.c b/test/driver.c new file mode 100644 index 000000000..90fa6a6d0 --- /dev/null +++ b/test/driver.c @@ -0,0 +1,59 @@ +/* +** mrbtest - Test for Embeddable Ruby +** +** This program runs Ruby test programs in test/t directory +** against the current mruby implementation. +*/ + +#include + +#include +#include +#include +#include + +void +mrb_init_mrbtest(mrb_state *); + +/* Print a short remark for the user */ +void print_hint(void) +{ + printf("mrbtest - Embeddable Ruby Test\n"); + printf("\nThis is a very early version, please test and report errors.\n"); + printf("Thanks :)\n\n"); +} + +int +main(void) +{ + struct mrb_parser_state *parser; + mrb_state *mrb_interpreter; + mrb_value mrb_return_value; + int byte_code; + + print_hint(); + + /* new interpreter instance */ + mrb_interpreter = mrb_open(); + mrb_init_mrbtest(mrb_interpreter); + parser = mrb_parse_nstring_ext(mrb_interpreter, "report()", strlen("report()")); + + /* generate bytecode */ + byte_code = mrb_generate_code(mrb_interpreter, parser->tree); + + /* evaluate the bytecode */ + mrb_return_value = mrb_run(mrb_interpreter, + /* pass a proc for evaulation */ + mrb_proc_new(mrb_interpreter, mrb_interpreter->irep[byte_code]), + mrb_top_self(mrb_interpreter)); + /* did an exception occur? */ + if (mrb_interpreter->exc) { + mrb_p(mrb_interpreter, mrb_return_value); + mrb_interpreter->exc = 0; + } + else { + /* no */ + } + + return 0; +} diff --git a/test/init_mrbtest.c b/test/init_mrbtest.c new file mode 100644 index 000000000..5d977da34 --- /dev/null +++ b/test/init_mrbtest.c @@ -0,0 +1,16 @@ +#include "mruby.h" +#include "mruby/irep.h" +#include "mruby/dump.h" +#include "mruby/string.h" +#include "mruby/proc.h" + +extern const char mrbtest_irep[]; + +void +mrb_init_mrbtest(mrb_state *mrb) +{ + int n = mrb_read_irep(mrb, mrbtest_irep); + + mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); +} + diff --git a/test/init_mritlib.c b/test/init_mritlib.c deleted file mode 100644 index 73b926b87..000000000 --- a/test/init_mritlib.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "mruby.h" -#include "mruby/irep.h" -#include "mruby/dump.h" -#include "mruby/string.h" -#include "mruby/proc.h" - -extern const char mritlib_irep[]; - -void -mrb_init_mritlib(mrb_state *mrb) -{ - int n = mrb_read_irep(mrb, mritlib_irep); - - extern mrb_value mrb_top_self(mrb_state *mrb); - mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); -} - diff --git a/test/t/_assert.rb b/test/t/_assert.rb new file mode 100644 index 000000000..91751f769 --- /dev/null +++ b/test/t/_assert.rb @@ -0,0 +1,44 @@ +$ok_test = 0 +$ko_test = 0 +$asserts = [] + +## +# 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 = '') + if(!yield) + $asserts.push([str, iso]) + $ko_test += 1 + print "F" + else + $ok_test += 1 + print "." + end +end + +## +# Report the test result and print all assertions +# which were reported broken. +def report() + print "\n" + $asserts.each do |str, iso| + print("Test Failed: #{str} [#{iso}]\n"); + end + + $total_test = $ok_test + $ko_test + print 'Total tests:' + print $total_test + print "\n" + + print ' OK: ' + print $ok_test + print "\n" + print ' KO: ' + print $ko_test + print "\n" +end diff --git a/test/t/array.rb b/test/t/array.rb new file mode 100644 index 000000000..3b65a80dd --- /dev/null +++ b/test/t/array.rb @@ -0,0 +1,40 @@ +## +# Array ISO Test + +assert('Array', '15.2.12') do + Array.class == Class +end + +assert('Array.[]', '15.2.12.4.1') do + Array.[](1,2,3) == [1, 2, 3] +end + +assert('Array#*', '15.2.12.5.1') do + [1].*(3) == [1, 1, 1] +end + +assert('Array#+', '15.2.12.5.2') do + [1].+([1]) == [1, 1] +end + +assert('Array#<<', '15.2.12.5.3') do + [1].<<(1) == [1, 1] +end + +assert('Array#[]', '15.2.12.5.4') do + [1,2,3].[](1) == 2 +end + +assert('Array#[]=', '15.2.12.5.5') do + [1,2,3].[]=(1,4) == [1, 4, 3] +end + +assert('Array#clear', '15.2.12.5.6') do + a = [1] + a.clear + a == [] +end + +# Not ISO specified + + diff --git a/test/t/time.rb b/test/t/time.rb new file mode 100644 index 000000000..f33cdde0d --- /dev/null +++ b/test/t/time.rb @@ -0,0 +1,73 @@ +## +# Time ISO Test + +assert('Time', '15.2.19') do + Time.class == Class +end + +assert('Time.at', '15.2.19.6.1') do + Time.at(1300000000.0) +end + +assert('Time.gm', '15.2.19.6.2') do + Time.gm(2012, 12, 23) +end + +assert('Time#asctime', '15.2.19.7.4') do + Time.at(1300000000.0).utc.asctime == "Sun Mar 13 07:06:40 UTC 2011" +end + +assert('Time#initialize_copy', '15.2.19.7.17') do + time_tmp_2 = Time.at(7.0e6) + time_tmp_2.clone == time_tmp_2 +end + +assert('Time#mday', '15.2.19.7.19') do + Time.gm(2012, 12, 23).mday == 23 +end + +assert('Time#month', '15.2.19.7.22') do + Time.gm(2012, 12, 23).month == 12 +end + +assert('Time#to_f', '15.2.19.7.24') do + Time.at(1300000000.0).to_f == 1300000000.0 +end + +assert('Time#to_i', '15.2.19.7.25') do + Time.at(1300000000.0).to_i == 1300000000 +end + +assert('Time#usec', '15.2.19.7.26') do + Time.at(1300000000.0).usec == 0 +end + +assert('Time#utc', '15.2.19.7.27') do + Time.at(1300000000.0).utc +end + +assert('Time#utc?', '15.2.19.7.28') do + Time.at(1300000000.0).utc.utc? +end + +assert('Time#wday', '15.2.19.7.30') do + Time.at(1300000000.0).utc.wday == 0 +end + +assert('Time#yday', '15.2.19.7.31') do + Time.at(1300000000.0).utc.yday == 71 +end + +assert('Time#year', '15.2.19.7.32') do + Time.gm(2012, 12, 23).year == 2012 +end + +assert('Time#zone', '15.2.19.7.33') do + Time.at(1300000000.0).utc.zone == 'UTC' +end + +# Not ISO specified + +assert('Time#new') do + Time.new.class == Time +end diff --git a/test/time.rb b/test/time.rb deleted file mode 100644 index f33cdde0d..000000000 --- a/test/time.rb +++ /dev/null @@ -1,73 +0,0 @@ -## -# Time ISO Test - -assert('Time', '15.2.19') do - Time.class == Class -end - -assert('Time.at', '15.2.19.6.1') do - Time.at(1300000000.0) -end - -assert('Time.gm', '15.2.19.6.2') do - Time.gm(2012, 12, 23) -end - -assert('Time#asctime', '15.2.19.7.4') do - Time.at(1300000000.0).utc.asctime == "Sun Mar 13 07:06:40 UTC 2011" -end - -assert('Time#initialize_copy', '15.2.19.7.17') do - time_tmp_2 = Time.at(7.0e6) - time_tmp_2.clone == time_tmp_2 -end - -assert('Time#mday', '15.2.19.7.19') do - Time.gm(2012, 12, 23).mday == 23 -end - -assert('Time#month', '15.2.19.7.22') do - Time.gm(2012, 12, 23).month == 12 -end - -assert('Time#to_f', '15.2.19.7.24') do - Time.at(1300000000.0).to_f == 1300000000.0 -end - -assert('Time#to_i', '15.2.19.7.25') do - Time.at(1300000000.0).to_i == 1300000000 -end - -assert('Time#usec', '15.2.19.7.26') do - Time.at(1300000000.0).usec == 0 -end - -assert('Time#utc', '15.2.19.7.27') do - Time.at(1300000000.0).utc -end - -assert('Time#utc?', '15.2.19.7.28') do - Time.at(1300000000.0).utc.utc? -end - -assert('Time#wday', '15.2.19.7.30') do - Time.at(1300000000.0).utc.wday == 0 -end - -assert('Time#yday', '15.2.19.7.31') do - Time.at(1300000000.0).utc.yday == 71 -end - -assert('Time#year', '15.2.19.7.32') do - Time.gm(2012, 12, 23).year == 2012 -end - -assert('Time#zone', '15.2.19.7.33') do - Time.at(1300000000.0).utc.zone == 'UTC' -end - -# Not ISO specified - -assert('Time#new') do - Time.new.class == Time -end diff --git a/tools/mrit/Makefile b/tools/mrit/Makefile deleted file mode 100644 index af973d9de..000000000 --- a/tools/mrit/Makefile +++ /dev/null @@ -1,82 +0,0 @@ -# makefile discription. -# basic build file for mrit executable - -# project-specific macros -# extension of the executable-file is modifiable(.exe .out ...) -BASEDIR = ../../src -TARGET := ../../bin/mrit -LIBR := ../../lib/libmruby.a -LIBRIT := ../../lib/libmrit.a -ifeq ($(OS),Windows_NT) -EXE := $(TARGET).exe -else -EXE := $(TARGET) -endif -OBJ0 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/../tools/mrit/*.c)) -#OBJ1 := $(patsubst %.c,%.o,$(filter-out $(EXCEPT1),$(wildcard $(BASEDIR)/*.c))) -#OBJ2 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/regex/*.c)) -#OBJ3 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/enc/*.c)) -OBJS := $(OBJ0) - -# ext libraries -#EXT1 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/../ext/socket/*.c)) -EXTS := $(EXT1) - -# libraries, includes -LIBS = -lm -INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include - -# compiler, linker (gcc) -CC = gcc -LL = gcc -YACC = bison -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -O3 -else -CFLAGS = -O3 -endif -ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) -ifeq ($(OS),Windows_NT) - MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" -else - MAKE_FLAGS = CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' -endif - -############################## -# generic build targets, rules - -.PHONY : all -all : $(LIBRIT) $(LIBR) $(EXE) - @echo "make: built targets of `pwd`" - -# executable constructed using linker from object files -$(EXE) : $(LIBRIT) $(LIBR) $(OBJS) $(EXTS) - $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBRIT) $(LIBR) $(EXTS) $(LIBS) - --include $(OBJS:.o=.d) - -# objects compiled from source -$(OBJS) : %.o : %.c - $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ - -# C library compile -$(LIBR) : - @$(MAKE) -C $(BASEDIR) $(MAKE_FLAGS) -$(LIBRIT) : - @$(MAKE) -C $(BASEDIR) $(MAKE_FLAGS) - -# mrit library compile -# extend libraries complile -$(EXTS) : %.o : %.c - $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ - -# clean up -.PHONY : clean #cleandep -clean : - $(MAKE) clean -C ../../test $(MAKE_FLAGS) - $(MAKE) clean -C ../../mrblib $(MAKE_FLAGS) - $(MAKE) clean -C ../mrbc $(MAKE_FLAGS) - @echo "make: removing targets, objects and depend files of `pwd`" - -rm -f $(EXE) $(OBJS) - -rm -f $(OBJS:.o=.d) diff --git a/tools/mrit/mrit.c b/tools/mrit/mrit.c deleted file mode 100644 index 594ab012d..000000000 --- a/tools/mrit/mrit.c +++ /dev/null @@ -1,59 +0,0 @@ -/* -** mrit - Embeddable Ruby ISO Test -** -** This program verifies ISO/IEC 30170:2012 -** against the current mruby implementation. -*/ - -#include - -#include -#include -#include -#include - -void -mrb_init_mritlib(mrb_state *); - -/* Print a short remark for the user */ -void print_hint(void) -{ - printf("mrit - Embeddable Ruby ISO Test\n"); - printf("\nThis is a very early version, please test and report errors.\n"); - printf("Thanks :)\n\n"); -} - -int -main(void) -{ - struct mrb_parser_state *parser; - mrb_state *mrb_interpreter; - mrb_value mrb_return_value; - int byte_code; - - print_hint(); - - /* new interpreter instance */ - mrb_interpreter = mrb_open(); - mrb_init_mritlib(mrb_interpreter); - parser = mrb_parse_nstring_ext(mrb_interpreter, "report()", strlen("report()")); - - /* generate bytecode */ - byte_code = mrb_generate_code(mrb_interpreter, parser->tree); - - /* evaluate the bytecode */ - mrb_return_value = mrb_run(mrb_interpreter, - /* pass a proc for evaulation */ - mrb_proc_new(mrb_interpreter, mrb_interpreter->irep[byte_code]), - mrb_top_self(mrb_interpreter)); - /* did an exception occur? */ - if (mrb_interpreter->exc) { - mrb_p(mrb_interpreter, mrb_obj_value(mrb_interpreter->exc)); - mrb_interpreter->exc = 0; - } - else { - /* no */ - } - - return 0; -} -- cgit v1.2.3