summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-05-14 23:04:13 +0900
committerYukihiro Matsumoto <[email protected]>2012-05-14 23:04:13 +0900
commit8085817cb5737ca0c2a4afb5e3d013a395e12eb4 (patch)
tree633371b8956a39b5c570d745bdfa963e42111158 /test
parent0c6ff97b8e88e6f848ba73a2bf799de98d27a526 (diff)
downloadmruby-8085817cb5737ca0c2a4afb5e3d013a395e12eb4.tar.gz
mruby-8085817cb5737ca0c2a4afb5e3d013a395e12eb4.zip
make test restructuring
Diffstat (limited to 'test')
-rw-r--r--test/Makefile65
-rw-r--r--test/driver.c59
-rw-r--r--test/init_mrbtest.c (renamed from test/init_mritlib.c)7
-rw-r--r--test/t/_assert.rb (renamed from test/_assert.rb)0
-rw-r--r--test/t/array.rb (renamed from test/array.rb)0
-rw-r--r--test/t/time.rb (renamed from test/time.rb)0
6 files changed, 112 insertions, 19 deletions
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/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 <string.h>
+
+#include <mruby.h>
+#include <mruby/proc.h>
+#include <mruby/data.h>
+#include <compile.h>
+
+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_mritlib.c b/test/init_mrbtest.c
index 73b926b87..5d977da34 100644
--- a/test/init_mritlib.c
+++ b/test/init_mrbtest.c
@@ -4,14 +4,13 @@
#include "mruby/string.h"
#include "mruby/proc.h"
-extern const char mritlib_irep[];
+extern const char mrbtest_irep[];
void
-mrb_init_mritlib(mrb_state *mrb)
+mrb_init_mrbtest(mrb_state *mrb)
{
- int n = mrb_read_irep(mrb, mritlib_irep);
+ int n = mrb_read_irep(mrb, mrbtest_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/_assert.rb b/test/t/_assert.rb
index 91751f769..91751f769 100644
--- a/test/_assert.rb
+++ b/test/t/_assert.rb
diff --git a/test/array.rb b/test/t/array.rb
index 3b65a80dd..3b65a80dd 100644
--- a/test/array.rb
+++ b/test/t/array.rb
diff --git a/test/time.rb b/test/t/time.rb
index f33cdde0d..f33cdde0d 100644
--- a/test/time.rb
+++ b/test/t/time.rb