summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorDaniel Bovensiepen <[email protected]>2012-11-08 17:23:51 +0900
committerDaniel Bovensiepen <[email protected]>2012-11-08 17:23:51 +0900
commite1e369470eb41453cb79abdbbbdb9158489e2d26 (patch)
tree0e4dce8c16af6f8519869a71c9c44f3ee2f3595b /test
parentcdb72a05a294eb8521dd40c011160228496312cb (diff)
parent1c95f4eb82d525d7d5eacd214904d262554bf93d (diff)
downloadmruby-e1e369470eb41453cb79abdbbbdb9158489e2d26.tar.gz
mruby-e1e369470eb41453cb79abdbbbdb9158489e2d26.zip
Merge new change
Diffstat (limited to 'test')
-rw-r--r--test/Makefile35
-rw-r--r--test/driver.c2
-rw-r--r--test/report.rb4
-rw-r--r--test/t/string.rb17
-rw-r--r--test/t/syntax.rb13
5 files changed, 69 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index 183e03438..b06343084 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -18,6 +18,13 @@ ASSLIB := $(BASEDIR)/assert.rb
MRBS := $(BASEDIR)/t/*.rb
OBJS := driver.o $(MLIB)
+# for mruby/mrbc test
+REPLIB := $(BASEDIR)/report.rb
+TESTRB := mrubytest.rb
+TESTMRB := mrubytest.mrb
+TESTRB_REP := mrubytest.rb.report
+TESTMRB_REP := mrubytest.mrb.report
+
# libraries, includes
LIBS = -lm
INCLUDES = -I$(BASEDIR)/../src -I$(BASEDIR)/../include
@@ -44,19 +51,37 @@ endif
# mruby compiler and test driver
ifeq ($(OS),Windows_NT)
+<<<<<<< HEAD
MRBC = ../bin/mrbc.exe
EXE := $(TARGET).exe
else
MRBC = ../bin/mrbc
EXE := $(TARGET)
+=======
+MRBC = ../bin/mrbc.exe
+MRUBY= ../bin/mruby.exe
+EXE := $(TARGET).exe
+else
+MRBC = ../bin/mrbc
+MRUBY= ../bin/mruby
+EXE := $(TARGET)
+>>>>>>> upstream/master
endif
##############################
# generic build targets, rules
.PHONY : test
-all : $(EXE)
+all : $(EXE) $(MRUBY) $(TESTRB) $(TESTMRB)
+ @echo "# exec mrbtest"
./$(EXE)
+ @echo
+ @echo "# exec mruby test with ruby script"
+ @($(MRUBY) $(TESTRB) > $(TESTRB_REP) && echo "mrubytest.rb success.") || $(CAT) $(TESTRB_REP)
+ @echo
+ @echo "# exec mruby test with mrb file"
+ @($(MRUBY) -b $(TESTMRB) > $(TESTMRB_REP) && echo "mrubytest.mrb success.") || $(CAT) $(TESTMRB_REP)
+ @echo
# executable constructed using linker from object files
$(EXE) : $(OBJS) $(LIBR)
@@ -80,8 +105,16 @@ $(DLIB) : $(RLIB) $(MRBC)
$(RLIB) : $(ASSLIB) $(MRBS)
$(CAT) $(ASSLIB) $(MRBS) > $@
+# Compile mrb file from mruby source
+$(TESTMRB) : $(MRBC) $(TESTRB)
+ $(MRBC) $(TESTRB)
+
+$(TESTRB) : $(ASSLIB) $(MRBS) $(REPLIB)
+ $(CAT) $(ASSLIB) $(MRBS) $(REPLIB) > $@
+
# clean up
.PHONY : clean
clean :
@echo "make: removing targets, objects and depend files of `pwd`"
-$(RM_F) $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(OBJS) $(EXE)
+ -$(RM_F) $(TESTRB) $(TESTMRB) $(TESTRB_REP) $(TESTMRB_REP)
diff --git a/test/driver.c b/test/driver.c
index d2ad31b26..788a77b2d 100644
--- a/test/driver.c
+++ b/test/driver.c
@@ -32,7 +32,7 @@ check_error(mrb_state *mrb)
mrb_value ko_test = mrb_gv_get(mrb, mrb_intern(mrb, "$ko_test"));
mrb_value kill_test = mrb_gv_get(mrb, mrb_intern(mrb, "$kill_test"));
- return FIXNUM_P(ko_test) && mrb_fixnum(ko_test) == 0 && FIXNUM_P(kill_test) && mrb_fixnum(kill_test) == 0;
+ return mrb_fixnum_p(ko_test) && mrb_fixnum(ko_test) == 0 && mrb_fixnum_p(kill_test) && mrb_fixnum(kill_test) == 0;
}
int
diff --git a/test/report.rb b/test/report.rb
new file mode 100644
index 000000000..fb77fd0aa
--- /dev/null
+++ b/test/report.rb
@@ -0,0 +1,4 @@
+report
+if $ko_test > 0 or $kill_test > 0
+ raise "mrbtest failed (KO:#{$ko_test}, Crash:#{$kill_test})"
+end
diff --git a/test/t/string.rb b/test/t/string.rb
index 27af38a4c..26b7df584 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -339,3 +339,20 @@ assert('Check the usage of a NUL character') do
"qqq\0ppp"
end
+assert('String#bytes') do
+ str1 = "hello"
+ bytes1 = [104, 101, 108, 108, 111]
+
+ str1.bytes == bytes1
+end
+
+assert('String#each_byte') do
+ str1 = "hello"
+ bytes1 = [104, 101, 108, 108, 111]
+ bytes2 = []
+
+ str1.each_byte {|b| bytes2 << b }
+
+ bytes1 == bytes2
+end
+
diff --git a/test/t/syntax.rb b/test/t/syntax.rb
index 7898a0b7d..47221d425 100644
--- a/test/t/syntax.rb
+++ b/test/t/syntax.rb
@@ -45,3 +45,16 @@ assert('Abbreviated variable assignment', '11.4.2.3.2') do
c += 2
a == 1 and b == nil and c == 3
end
+
+assert('Nested const reference') do
+ module Syntax4Const
+ CONST1 = "hello world"
+ class Const2
+ def const1
+ CONST1
+ end
+ end
+ end
+ Syntax4Const::CONST1 == "hello world" and
+ Syntax4Const::Const2.new.const1 == "hello world"
+end