Skip to content

Commit

Permalink
Renamed false/true/nil/file_test test classes in bfts.
Browse files Browse the repository at this point in the history
Enhanced Exception and Struct tests.
Implemented Exception.
Completed Struct.
pair:eric

[git-p4: depot-paths = "//src/metaruby/dev/": change = 2311]
  • Loading branch information
zenspider committed Jan 31, 2006
1 parent 6b6a6e0 commit 9e64478
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 90 deletions.
50 changes: 23 additions & 27 deletions Makefile
Expand Up @@ -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))
Expand All @@ -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)

Expand All @@ -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
70 changes: 38 additions & 32 deletions exception.rb
Expand Up @@ -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 <tt>string.to_str</tt>.
#
# 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

##
Expand All @@ -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

##
Expand Down Expand Up @@ -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 <tt>string.to_str</tt>.

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

##
Expand All @@ -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 <tt>exception.to_s</tt>. 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

##
Expand All @@ -95,32 +86,47 @@ def message
# argument must be an array of <tt>String</tt> objects in the format
# described in <tt>Exception#backtrace</tt>.

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 <tt>exception.to_s</tt>. 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
#
# Returns the result of invoking <tt>exception.to_s</tt>. 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_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 <tt>exception.to_s</tt>. 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

40 changes: 9 additions & 31 deletions struct.rb
Expand Up @@ -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
Expand All @@ -251,6 +240,8 @@ def length
return _attrs.length
end

alias size length

##
# call-seq:
# struct.members => array
Expand Down Expand Up @@ -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

##
Expand All @@ -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'
"#<struct #{self.class} #{_attrs.zip(self.to_a).map{|o| o[1] = o[1].inspect; o.join('=')}.join(', ') }>"
end

alias inspect to_s

##
# call-seq:
# struct.to_a => array
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9e64478

Please sign in to comment.