From 9e644780195ebc3049674d0437cc0f3d9d940788 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Mon, 30 Jan 2006 21:08:10 -0800 Subject: [PATCH] Renamed false/true/nil/file_test test classes in bfts. Enhanced Exception and Struct tests. Implemented Exception. Completed Struct. pair:eric [git-p4: depot-paths = "//src/metaruby/dev/": change = 2311] --- Makefile | 50 +++++++++++++++++-------------------- exception.rb | 70 ++++++++++++++++++++++++++++------------------------ struct.rb | 40 +++++++----------------------- 3 files changed, 70 insertions(+), 90 deletions(-) diff --git a/Makefile b/Makefile index 16bcaef..a23c93d 100644 --- a/Makefile +++ b/Makefile @@ -4,24 +4,24 @@ FILTER?= RUBY2C?=$(shell cd ../../ruby_to_c/dev; pwd) PARSETREE?=$(shell cd ../../ParseTree/dev/lib; pwd) RUBYINLINE?=$(shell cd ../../RubyInline/dev; pwd) -RUBICON?=$(shell cd ../../rubicon/dev; pwd) -RUBY_FLAGS?=-w -Ilib:bin:$(RUBY2C):$(RUBYINLINE):$(PARSETREE):rubicon +BFTS?=$(shell cd ../../bfts/dev; pwd) +RUBY_FLAGS?=-w -Ilib:bin:$(RUBY2C):$(RUBYINLINE):$(PARSETREE):$(BFTS) RUBY?=$(RUBYBIN) $(RUBY_DEBUG) $(RUBY_FLAGS) CFLAGS ?= -I$(shell $(RUBYBIN) -rrbconfig -e 'puts Config::CONFIG["archdir"]') CLASSES = \ - TrueClass \ - FalseClass \ - NilClass \ - Time \ - Array \ - Range \ - Hash \ - String \ - Comparable \ - Exception \ - FileTest \ - Struct \ + true_class \ + false_class \ + nil_class \ + time \ + array \ + range \ + hash \ + string \ + comparable \ + exception \ + file_test \ + struct \ $(NULL) TESTFILES = $(patsubst %,%.pass,$(CLASSES)) @@ -33,15 +33,15 @@ SHLIB_EXT = $(shell ruby -rrbconfig -e 'puts Config::CONFIG["DLEXT"]') LINKER = $(shell ruby -rrbconfig -e 'puts Config::CONFIG["LDSHARED"]') %.pass: %.rb Makefile - (cd $(RUBICON)/builtin; $(RUBY) -I../../../metaruby/dev -r$* Test$<) && touch $@ + (cd $(BFTS); $(RUBY) -I../../metaruby/dev -r$* test_$<) && touch $@ -%.audit.rb: %.rb rubicon/builtin/Test%.rb Makefile - $(RUBY) ../../ZenTest/dev/ZenTest.rb $*.rb rubicon/builtin/Test$*.rb +%.audit.rb: %.rb bfts/Test%.rb Makefile + $(RUBY) ../../ZenTest/dev/ZenTest.rb $*.rb bfts/Test$*.rb %.c: %.rb %.pass Makefile $(RUBY) $(RUBY2C)/translate.rb -c=$* ./$< > $@ -all: rubicon tools $(TESTFILES) +all: bfts $(TESTFILES) allc: all $(CFILES) @@ -57,27 +57,23 @@ test: realclean FORCE: doc: FORCE - rm -rf doc ; rdoc -x rubicon . + rm -rf doc ; rdoc -x bfts . audit: $(AUDITFILES) # so you can type `make Time` to just run Time tests $(CLASSES): - (cd $(RUBICON)/builtin; $(RUBY) -I../../../metaruby/dev:.. -r$@ Test$@.rb $(FILTER)) + (cd $(BFTS); $(RUBY) -I../../../metaruby/dev:.. -r$@ Test$@.rb $(FILTER)) # shortcut to login, we can't find any way to default the input. argh. cvslogin: cvs -d:pserver:anonymous@rubyforge.org:/var/cvs/rubytests login -# checks out rubicon fresh and patches -rubicon: - ln -s ../../rubicon/dev rubicon - -tools: rubicon - (cd rubicon; $(MAKE) tools) +sort: + for f in *.rb; do egrep "^ *def [a-z]" $$f > x; sort x > y; echo $$f; echo; diff x y; done clean: rm -rf *~ *.c *.o *.$(SHLIB_EXT) ~/.ruby_inline *.a *.pass *.cache realclean: clean - rm -rf rubicon + rm -rf bfts diff --git a/exception.rb b/exception.rb index 63caade..34cfa48 100644 --- a/exception.rb +++ b/exception.rb @@ -2,14 +2,16 @@ class Exception ## # call-seq: - # exc.exception(string) -> an_exception or exc + # exc.exception(string = nil) -> an_exception or exc # # With no argument, or if the argument is the same as the receiver, return # the receiver. Otherwise, create a new exception object of the same class # as the receiver, but with a message equal to string.to_str. + # + # FIX: this is really just new and should say that - def self.exception(*args) - raise NotImplementedError, 'self.exception is not implemented' + def self.exception(string = nil) + return self.new(string) end ## @@ -18,8 +20,9 @@ def self.exception(*args) # # Construct a new Exception object, optionally passing in a message. - def initialize(*args) - raise NotImplementedError, 'initialize is not implemented' + def initialize(msg = nil) + @backtrace = nil + @message = msg end ## @@ -49,19 +52,20 @@ def initialize(*args) # prog.rb:10 def backtrace - raise NotImplementedError, 'backtrace is not implemented' + return @backtrace end ## # call-seq: - # exc.exception(string) -> an_exception or exc + # exc.exception(string = nil) -> an_exception or exc # # With no argument, or if the argument is the same as the receiver, return # the receiver. Otherwise, create a new exception object of the same class # as the receiver, but with a message equal to string.to_str. - def exception(*args) - raise NotImplementedError, 'exception is not implemented' + def exception(string = nil) + return self if string.nil? or string.equal? self + return self.class.exception(string) end ## @@ -71,20 +75,7 @@ def exception(*args) # Return this exception's class name an message def inspect - raise NotImplementedError, 'inspect is not implemented' - end - - ## - # call-seq: - # exception.message => string - # exception.to_str => string - # - # Returns the result of invoking exception.to_s. Normally this - # returns the exception's message or name. By supplying a to_str method, - # exceptions are agreeing to be used where Strings are expected. - - def message - raise NotImplementedError, 'message is not implemented' + "<#{self.class}: #{message}>" end ## @@ -95,23 +86,27 @@ def message # argument must be an array of String objects in the format # described in Exception#backtrace. - def set_backtrace(arg1) - raise NotImplementedError, 'set_backtrace is not implemented' + def set_backtrace(array) + @backtrace = array end ## # call-seq: - # exception.to_s => string + # exception.to_s => string + # exception.message => string + # exception.to_str => string # - # Returns exception's message (or the name of the exception if no message - # is set). + # Returns the result of invoking exception.to_s. Normally this + # returns the exception's message or name. By supplying a to_str method, + # exceptions are agreeing to be used where Strings are expected. def to_s - raise NotImplementedError, 'to_s is not implemented' + return @message end ## # call-seq: + # exception.to_s => string # exception.message => string # exception.to_str => string # @@ -119,8 +114,19 @@ def to_s # returns the exception's message or name. By supplying a to_str method, # exceptions are agreeing to be used where Strings are expected. - def to_str - raise NotImplementedError, 'to_str is not implemented' - end + alias to_str to_s + + ## + # call-seq: + # exception.to_s => string + # exception.message => string + # exception.to_str => string + # + # Returns the result of invoking exception.to_s. Normally this + # returns the exception's message or name. By supplying a to_str method, + # exceptions are agreeing to be used where Strings are expected. + + alias message to_s + end diff --git a/struct.rb b/struct.rb index 228b3d5..5a05ed6 100644 --- a/struct.rb +++ b/struct.rb @@ -224,18 +224,7 @@ def eql?(arg1) def hash raise NotImplementedError, 'hash is not implemented' end - - ## - # call-seq: - # struct.to_s => string - # struct.inspect => string - # - # Describe the contents of this struct in a string. - - def inspect - raise NotImplementedError, 'inspect is not implemented' - end - + ## # call-seq: # struct.length => fixnum @@ -251,6 +240,8 @@ def length return _attrs.length end + alias size length + ## # call-seq: # struct.members => array @@ -288,23 +279,8 @@ def members # l.select(-1, -3, -5) #=> [66, 44, 22] # l.select {|v| (v % 2).zero? } #=> [22, 44, 66] - def select(*args) - raise NotImplementedError, 'select is not implemented' - end - - ## - # call-seq: - # struct.length => fixnum - # struct.size => fixnum - # - # Returns the number of instance variables. - # - # Customer = Struct.new(:name, :address, :zip) - # joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) - # joe.length #=> 3 - - def size - raise NotImplementedError, 'size is not implemented' + def select(&block) + to_a.select(&block) end ## @@ -330,9 +306,11 @@ def to_a # Describe the contents of this struct in a string. def to_s - raise NotImplementedError, 'to_s is not implemented' + "#" end + alias inspect to_s + ## # call-seq: # struct.to_a => array @@ -361,7 +339,7 @@ def to_s # a.values_at(1..3, 2...5) def values_at(*args) - raise NotImplementedError, 'values_at is not implemented' + to_a.values_at(*args) end end