diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-07-10 04:49:24 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-07-10 04:49:24 +0000 |
commit | c67a74570dd056569763f5015e0aafa7d454fca7 (patch) | |
tree | f1dda39296b6911752cd4b6446a21f2e54ff68e1 | |
parent | 3043170b14875ce53f3a951d665279b12c2c63a8 (diff) |
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 25 | ||||
-rw-r--r-- | README.EXT | 12 | ||||
-rw-r--r-- | README.EXT.jp | 14 | ||||
-rw-r--r-- | error.c | 1 | ||||
-rw-r--r-- | eval.c | 10 | ||||
-rw-r--r-- | ext/socket/addrinfo.h | 5 | ||||
-rw-r--r-- | ext/socket/extconf.rb | 2 | ||||
-rw-r--r-- | ext/socket/getaddrinfo.c | 12 | ||||
-rw-r--r-- | ext/socket/getnameinfo.c | 12 | ||||
-rw-r--r-- | ext/socket/socket.c | 6 | ||||
-rw-r--r-- | ext/socket/sockport.h | 24 | ||||
-rw-r--r-- | lib/date.rb | 8 | ||||
-rw-r--r-- | lib/date2.rb | 14 | ||||
-rw-r--r-- | lib/jcode.rb | 2 | ||||
-rw-r--r-- | lib/matrix.rb | 58 | ||||
-rw-r--r-- | lib/net/ftp.rb | 4 | ||||
-rw-r--r-- | lib/tracer.rb | 8 | ||||
-rw-r--r-- | lib/weakref.rb | 28 | ||||
-rw-r--r-- | sample/biorhythm.rb | 14 | ||||
-rw-r--r-- | sample/cal.rb | 2 | ||||
-rw-r--r-- | sample/test.rb | 747 | ||||
-rw-r--r-- | version.h | 4 |
22 files changed, 566 insertions, 446 deletions
@@ -1,3 +1,28 @@ +Mon Jul 10 09:07:54 2000 Yukihiro Matsumoto <matz@netlab.co.jp> + + * error.c (rb_bug): print version number and such too. + +Sat Jul 8 23:08:40 2000 Yukihiro Matsumoto <matz@netlab.co.jp> + + * eval.c (rb_thread_start_0): should copy previous scopes to + prevent rb_gc_force_recylce(). + +Fri Jul 7 23:36:36 2000 Katsuyuki Komatsu <komatsu@sarion.co.jp> + + * ext/socket/addrinfo.h: move IN_EXPERIMENTAL and IN_LOOPBACKNET + definitions to ext/socket/sockport.h. + + * ext/socket/extconf.rb: add getservbyport() and arpa/inet.h check. + + * ext/socket/getaddrinfo.c (getaddrinfo): SOCK_RAW may not be + defined (ex. BeOS, Palm OS 2.x or before). + + * ext/socket/getnameinfo.c (getnameinfo): getservbyport() may not + exist (ex. BeOS, Palm OS). + + * ext/socket/sockport.h: add IN_EXPERIMENTAL, IN_CLASSA_NSHIFT, + IN_LOOPBACKNET, AF_UNSPEC, PF_UNSPEC and PF_INET. + Fri Jul 7 03:30:00 2000 Yukihiro Matsumoto <matz@netlab.co.jp> * parse.y (aref_args): should allow Hash[:a=>2] etc. diff --git a/README.EXT b/README.EXT index dc5126efaf..12d379e09b 100644 --- a/README.EXT +++ b/README.EXT @@ -150,6 +150,15 @@ interpreter. Useful functions are listed below (not all): Creates a new Ruby string from C string. This is equivalent to rb_str_new(ptr, strlen(ptr)). + rb_tainted_str_new(char *ptr, int len) + + Creates a new tainted Ruby string. Strings from external data + should be tainted. + + rb_tainted_str_new2(char *ptr) + + Creates a new tainted Ruby string from C string. + rb_str_cat(VALUE str, char *ptr, int len) Appends len bytes data from ptr to the Ruby string. @@ -266,6 +275,9 @@ in Kernel module, can be defined using: void rb_define_global_function(char *name, VALUE (*func)(), int argc) +To define alias to the method, + + void rb_define_alias(VALUE module, const char* new, const char* old); 2.1.3 Constant definition diff --git a/README.EXT.jp b/README.EXT.jp index ac4f3adca9..e8be946d68 100644 --- a/README.EXT.jp +++ b/README.EXT.jp @@ -180,6 +180,16 @@ Rubyが用意している関数を用いてください. Cの文字列からRubyの文字列を生成する.この関数の機能は rb_str_new(ptr, strlen(ptr))と同等である. + rb_tainted_str_new(char *ptr, int len) + + 汚染マークが付加された新しいRubyの文字列を生成する.外部 + からのデータに基づく文字列には汚染マークが付加されるべき + である. + + rb_tainted_str_new2(char *ptr) + + Cの文字列から汚染マークが付加されたRubyの文字列を生成する. + rb_str_cat(VALUE str, char *ptr, int len) Rubyの文字列strにlenバイトの文字列ptrを追加する. @@ -307,6 +317,10 @@ privateメソッドとは関数形式でしか呼び出すことの出来ないメソッ void rb_define_global_function(char *name, VALUE (*func)(), int argc) +メソッドの別名を定義するための関数は以下の通りです。 + + void rb_define_alias(VALUE module, const char* new, const char* old); + 2.1.3 定数定義 拡張ライブラリが必要な定数はあらかじめ定義しておいた方が良い @@ -159,6 +159,7 @@ rb_bug(fmt, va_alist) va_init_list(args, fmt); err_print(buf, args); va_end(args); + ruby_show_version(); abort(); } @@ -778,6 +778,9 @@ static VALUE ruby_wrapper; /* security wrapper */ ruby_scope = _scope; \ scope_vmode = SCOPE_PUBLIC; +typedef struct thread * rb_thread_t; +static rb_thread_t curr_thread = 0; + #define SCOPE_DONT_RECYCLE FL_USER2 #define POP_SCOPE() \ if (FL_TEST(ruby_scope, SCOPE_DONT_RECYCLE)) {\ @@ -6315,7 +6318,7 @@ enum thread_status { /* +infty, for this purpose */ #define DELAY_INFTY 1E30 -typedef struct thread * rb_thread_t; +/* typedef struct thread * rb_thread_t; */ struct thread { struct thread *next, *prev; @@ -6372,7 +6375,7 @@ struct thread { #define THREAD_RAISED 0x200 static rb_thread_t main_thread; -static rb_thread_t curr_thread = 0; +/*static rb_thread_t curr_thread = 0;*/ #define FOREACH_THREAD_FROM(f,x) x = f; do { x = x->next; #define END_FOREACH_FROM(f,x) } while (x != f) @@ -7513,6 +7516,9 @@ rb_thread_start_0(fn, arg, th) } #endif + if (ruby_block) { /* should nail down higher scopes */ + blk_copy_prev(ruby_block); + } scope_dup(ruby_scope); FL_SET(ruby_scope, SCOPE_SHARED); if (THREAD_SAVE_CONTEXT(curr_thread)) { diff --git a/ext/socket/addrinfo.h b/ext/socket/addrinfo.h index 74fae207b9..6000a466ba 100644 --- a/ext/socket/addrinfo.h +++ b/ext/socket/addrinfo.h @@ -127,11 +127,6 @@ #define NI_NUMERICSERV 0x00000008 #define NI_DGRAM 0x00000010 -#ifdef NT -#define IN_EXPERIMENTAL(x) 0 -#define IN_LOOPBACKNET 0 -#endif - struct addrinfo { int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ int ai_family; /* PF_xxx */ diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb index b0b44180c9..d1ce000f5e 100644 --- a/ext/socket/extconf.rb +++ b/ext/socket/extconf.rb @@ -306,6 +306,8 @@ else $objs += ["getnameinfo.#{$OBJEXT}"] have_func("inet_ntop") or have_func("inet_ntoa") have_func("inet_pton") or have_func("inet_aton") + have_func("getservbyport") + have_header("arpa/inet.h") have_header("arpa/nameser.h") have_header("resolv.h") end diff --git a/ext/socket/getaddrinfo.c b/ext/socket/getaddrinfo.c index c312b92705..d518017bc8 100644 --- a/ext/socket/getaddrinfo.c +++ b/ext/socket/getaddrinfo.c @@ -42,9 +42,15 @@ #include <sys/types.h> #ifndef NT #include <sys/param.h> -#include <sys/socket.h> +#if defined(__BEOS__) +# include <net/socket.h> +#else +# include <sys/socket.h> +#endif #include <netinet/in.h> +#if defined(HAVE_ARPA_INET_H) #include <arpa/inet.h> +#endif #if defined(HAVE_ARPA_NAMESER_H) #include <arpa/nameser.h> #endif @@ -330,12 +336,16 @@ getaddrinfo(hostname, servname, hints, res) pai->ai_socktype = SOCK_STREAM; break; default: +#if defined(SOCK_RAW) pai->ai_socktype = SOCK_RAW; +#endif break; } break; +#if defined(SOCK_RAW) case SOCK_RAW: break; +#endif case SOCK_DGRAM: if (pai->ai_protocol != IPPROTO_UDP && pai->ai_protocol != ANY) diff --git a/ext/socket/getnameinfo.c b/ext/socket/getnameinfo.c index 60bd71bac6..bd3bd129bf 100644 --- a/ext/socket/getnameinfo.c +++ b/ext/socket/getnameinfo.c @@ -37,9 +37,15 @@ #include "config.h" #include <sys/types.h> #ifndef NT -#include <sys/socket.h> +#if defined(__BEOS__) +# include <net/socket.h> +#else +# include <sys/socket.h> +#endif #include <netinet/in.h> +#if defined(HAVE_ARPA_INET_H) #include <arpa/inet.h> +#endif #if defined(HAVE_ARPA_NAMESER_H) #include <arpa/nameser.h> #endif @@ -178,6 +184,7 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) return ENI_MEMORY; strcpy(serv, numserv); } else { +#if defined(HAVE_GETSERVBYPORT) sp = getservbyport(port, (flags & NI_DGRAM) ? "udp" : "tcp"); if (sp) { if (strlen(sp->s_name) > servlen) @@ -185,6 +192,9 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) strcpy(serv, sp->s_name); } else return ENI_NOSERVNAME; +#else + return ENI_NOSERVNAME; +#endif } switch (sa->sa_family) { diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 8cf8f8d37f..c65de566e4 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -21,7 +21,11 @@ #endif #ifndef NT -#include <sys/socket.h> +#if defined(__BEOS__) +# include <net/socket.h> +#else +# include <sys/socket.h> +#endif #include <netinet/in.h> #ifdef HAVE_NETINET_TCP_H # include <netinet/tcp.h> diff --git a/ext/socket/sockport.h b/ext/socket/sockport.h index e3750816c6..d19b1e1dba 100644 --- a/ext/socket/sockport.h +++ b/ext/socket/sockport.h @@ -45,4 +45,28 @@ # define IN_MULTICAST(i) IN_CLASSD(i) #endif +#ifndef IN_EXPERIMENTAL +# define IN_EXPERIMENTAL(i) ((((long)(i)) & 0xe0000000) == 0xe0000000) +#endif + +#ifndef IN_CLASSA_NSHIFT +# define IN_CLASSA_NSHIFT 24 +#endif + +#ifndef IN_LOOPBACKNET +# define IN_LOOPBACKNET 127 +#endif + +#ifndef AF_UNSPEC +# define AF_UNSPEC 0 +#endif + +#ifndef PF_UNSPEC +# define PF_UNSPEC AF_UNSPEC +#endif + +#ifndef PF_INET +# define PF_INET AF_INET +#endif + #endif diff --git a/lib/date.rb b/lib/date.rb index 3a7d3c7b1b..dbb47f0af2 100644 --- a/lib/date.rb +++ b/lib/date.rb @@ -1,8 +1,8 @@ # # Date.rb - # $Release Version: $ -# $Revision: 1.1.1.2 $ -# $Date: 1999/01/20 04:59:35 $ +# $Revision: 1.2 $ +# $Date: 2000/07/06 07:21:23 $ # by Yasuo OHBA(SHL Japan Inc. Technology Dept.) # # -- @@ -168,12 +168,10 @@ class Date m = Date.daylist(@year) if @month < 1 || @month > 12 raise ArgumentError, "argument(month) out of range." - return nil end if @year == 1752 && @month == 9 if @day >= 3 && @day <= 13 raise ArgumentError, "argument(1752/09/3-13) out of range." - return nil end d = 30 else @@ -181,7 +179,6 @@ class Date end if @day < 1 || @day > d raise ArgumentError, "argument(day) out of range." - return nil end return self end @@ -299,4 +296,3 @@ def Date.jan1!(y) end return (d % 7) end - diff --git a/lib/date2.rb b/lib/date2.rb index e1badcd3f7..ad631456f2 100644 --- a/lib/date2.rb +++ b/lib/date2.rb @@ -147,7 +147,7 @@ class Date def new3(y=-4712, m=1, d=1, sg=ITALY) unless jd = exist3?(y, m, d, sg) - fail ArgumentError, 'invalid date' + raise ArgumentError, 'invalid date' end new(jd, sg) end @@ -169,7 +169,7 @@ class Date def new2(y=-4712, d=1, sg=ITALY) unless jd = exist2?(y, d, sg) - fail ArgumentError, 'invalid date' + raise ArgumentError, 'invalid date' end new(jd, sg) end @@ -189,7 +189,7 @@ class Date def neww(y=1582, w=41, d=5, sg=ITALY) unless jd = existw?(y, w, d, sg) - fail ArgumentError, 'invalid date' + raise ArgumentError, 'invalid date' end new(jd, sg) end @@ -280,7 +280,7 @@ class Date case n when Numeric; return type.new(@rjd + n, @sg) end - fail TypeError, 'expected numeric' + raise TypeError, 'expected numeric' end def - (x) @@ -288,7 +288,7 @@ class Date when Numeric; return type.new(@rjd - x, @sg) when Date; return @rjd - x.rjd end - fail TypeError, 'expected numeric or date' + raise TypeError, 'expected numeric or date' end def <=> (other) @@ -296,7 +296,7 @@ class Date when Numeric; return @rjd <=> other when Date; return @rjd <=> other.rjd end - fail TypeError, 'expected numeric or date' + raise TypeError, 'expected numeric or date' end def === (other) @@ -304,7 +304,7 @@ class Date when Numeric; return jd == other when Date; return jd == other.jd end - fail TypeError, 'expected numeric or date' + raise TypeError, 'expected numeric or date' end def >> (n) diff --git a/lib/jcode.rb b/lib/jcode.rb index 193f3042ff..923153a637 100644 --- a/lib/jcode.rb +++ b/lib/jcode.rb @@ -1,6 +1,6 @@ # jcode.rb - ruby code to handle japanese (EUC/SJIS) string -$vsave, $VERBOSE = $VERBOSE, FALSE +$vsave, $VERBOSE = $VERBOSE, false class String printf STDERR, "feel free for some warnings:\n" if $VERBOSE diff --git a/lib/matrix.rb b/lib/matrix.rb index 9de7dcb3a2..223bf70869 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -37,7 +37,7 @@ # creates a matrix where `rows' indicates rows. # `rows' is an array of arrays, # e.g, Matrix[[11, 12], [21, 22]] -# Matrix.rows(rows, copy = TRUE) +# Matrix.rows(rows, copy = true) # creates a matrix where `rows' indicates rows. # if optional argument `copy' is false, use the array as # internal structure of the metrix without copying. @@ -143,7 +143,7 @@ # # INSTANCE CREATION: # Vector.[](*array) -# Vector.elements(array, copy = TRUE) +# Vector.elements(array, copy = true) # ACCSESSING: # [](i) # size @@ -193,10 +193,10 @@ class Matrix private_class_method :new def Matrix.[](*rows) - new(:init_rows, rows, FALSE) + new(:init_rows, rows, false) end - def Matrix.rows(rows, copy = TRUE) + def Matrix.rows(rows, copy = true) new(:init_rows, rows, copy) end @@ -208,7 +208,7 @@ class Matrix columns[j][i] } } - Matrix.rows(rows, FALSE) + Matrix.rows(rows, false) end def Matrix.diagonal(*values) @@ -220,7 +220,7 @@ class Matrix row } self - rows(rows, FALSE) + rows(rows, false) end def Matrix.scalar(n, value) @@ -242,11 +242,11 @@ class Matrix def Matrix.row_vector(row) case row when Vector - Matrix.rows([row.to_a], FALSE) + Matrix.rows([row.to_a], false) when Array - Matrix.rows([row.dup], FALSE) + Matrix.rows([row.dup], false) else - Matrix.row([[row]], FALSE) + Matrix.row([[row]], false) end end @@ -311,13 +311,13 @@ class Matrix |i| @rows[i][j] } - Vector.elements(col, FALSE) + Vector.elements(col, false) end end def collect rows = @rows.collect{|row| row.collect{|e| yield e}} - Matrix.rows(rows, FALSE) + Matrix.rows(rows, false) end alias map collect @@ -345,7 +345,7 @@ class Matrix |row| row[from_col, size_col] } - Matrix.rows(rows, FALSE) + Matrix.rows(rows, false) end # TESTING @@ -363,20 +363,20 @@ class Matrix # COMPARING def ==(other) - return FALSE unless Matrix === other + return false unless Matrix === other other.compare_by_row_vectors(@rows) end alias eql? == def compare_by_row_vectors(rows) - return FALSE unless @rows.size == rows.size + return false unless @rows.size == rows.size 0.upto(@rows.size - 1) do |i| - return FALSE unless @rows[i] == rows[i] + return false unless @rows[i] == rows[i] end - TRUE + true end def clone @@ -405,7 +405,7 @@ class Matrix e * m } } - return Matrix.rows(rows, FALSE) + return Matrix.rows(rows, false) when Vector m = Matrix.column_vector(m) r = self * m @@ -425,7 +425,7 @@ class Matrix vij } } - return Matrix.rows(rows, FALSE) + return Matrix.rows(rows, false) else x, y = m.coerce(self) return x * y @@ -453,7 +453,7 @@ class Matrix self[i, j] + m[i, j] } } - Matrix.rows(rows, FALSE) + Matrix.rows(rows, false) end def -(m) @@ -477,7 +477,7 @@ class Matrix self[i, j] - m[i, j] } } - Matrix.rows(rows, FALSE) + Matrix.rows(rows, false) end def /(other) @@ -490,7 +490,7 @@ class Matrix e / other } } - return Matrix.rows(rows, FALSE) + return Matrix.rows(rows, false) when Matrix return self * other.inverse else @@ -825,10 +825,10 @@ class Vector private_class_method :new def Vector.[](*array) - new(:init_elements, array, copy = FALSE) + new(:init_elements, array, copy = false) end - def Vector.elements(array, copy = TRUE) + def Vector.elements(array, copy = true) new(:init_elements, array, copy) end @@ -873,7 +873,7 @@ class Vector # COMPARING def ==(other) - return FALSE unless Vector === other + return false unless Vector === other other.compare_by(@elements) end @@ -897,7 +897,7 @@ class Vector case x when Numeric els = @elements.collect{|e| e * x} - Vector.elements(els, FALSE) + Vector.elements(els, false) when Matrix self.covector * x else @@ -914,7 +914,7 @@ class Vector |v1, v2| v1 + v2 } - Vector.elements(els, FALSE) + Vector.elements(els, false) when Matrix Matrix.column_vector(self) + v else @@ -931,7 +931,7 @@ class Vector |v1, v2| v1 - v2 } - Vector.elements(els, FALSE) + Vector.elements(els, false) when Matrix Matrix.column_vector(self) - v else @@ -958,7 +958,7 @@ class Vector |v| yield v } - Vector.elements(els, FALSE) + Vector.elements(els, false) end alias map collect @@ -967,7 +967,7 @@ class Vector |v1, v2| yield v1, v2 } - Vector.elements(els, FALSE) + Vector.elements(els, false) end def r diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index 3c2d97c3b3..a40b3532b1 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -377,7 +377,7 @@ module Net end end - def putbinaryfile(localfile, remotefile, blocksize, callback = nil) + def putbinaryfile(localfile, remotefile, blocksize = 4096, callback = nil) if iterator? callback = Proc.new end @@ -635,7 +635,7 @@ module Net host = (@sock.peeraddr())[3] return host, port end - private :parse228 + private :parse229 def parse257(resp) if resp[0, 3] != "257" diff --git a/lib/tracer.rb b/lib/tracer.rb index 8ee14ce378..78bada9a65 100644 --- a/lib/tracer.rb +++ b/lib/tracer.rb @@ -17,10 +17,10 @@ class Tracer @RCS_ID='-$Id: tracer.rb,v 1.8 1998/05/19 03:42:49 keiju Exp keiju $-' class << self - attr :verbose, TRUE + attr :verbose, true alias verbose? verbose end - verbose = TRUE + verbose = true MY_FILE_NAME = caller(0)[0].scan(/^(.*):[0-9]+$/)[0][0] @@ -114,14 +114,14 @@ class Tracer return unless p.call event, file, line, id, binding end - Thread.critical = TRUE + Thread.critical = true printf("#%d:%s:%d:%s: %s", get_thread_no, file, line, EVENT_SYMBOL[event], get_line(file, line)) - Thread.critical = FALSE + Thread.critical = false end Single = new diff --git a/lib/weakref.rb b/lib/weakref.rb index 18b530f2ae..a6519e64c0 100644 --- a/lib/weakref.rb +++ b/lib/weakref.rb @@ -19,18 +19,24 @@ class WeakRef<Delegator ID_MAP = {} # obj -> [ref,...] ID_REV_MAP = {} # ref -> obj ObjectSpace.add_finalizer(lambda{|id| - rids = ID_MAP[id] - if rids - for rid in rids - ID_REV_MAP[rid] = nil + __old_status = Thread.critical + Thread.critical = true + begin + rids = ID_MAP[id] + if rids + for rid in rids + ID_REV_MAP[rid] = nil + end + ID_MAP[id] = nil end - ID_MAP[id] = nil - end - rid = ID_REV_MAP[id] - if rid - ID_REV_MAP[id] = nil - ID_MAP[rid].delete(id) - ID_MAP[rid] = nil if ID_MAP[rid].empty? + rid = ID_REV_MAP[id] + if rid + ID_REV_MAP[id] = nil + ID_MAP[rid].delete(id) + ID_MAP[rid] = nil if ID_MAP[rid].empty? + end + ensure + Thread.critical = __old_status end }) diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb index d2cbb113ec..146e5da244 100644 --- a/sample/biorhythm.rb +++ b/sample/biorhythm.rb @@ -11,6 +11,20 @@ # # +# probably based on: +# +# Newsgroups: comp.sources.misc,de.comp.sources.os9 +# From: fkk@stasys.sta.sub.org (Frank Kaefer) +# Subject: v41i126: br - Biorhythm v3.0, Part01/01 +# Message-ID: <1994Feb1.070616.15982@sparky.sterling.com> +# Sender: kent@sparky.sterling.com (Kent Landfield) +# Organization: Sterling Software +# Date: Tue, 1 Feb 1994 07:06:16 GMT +# +# Posting-number: Volume 41, Issue 126 +# Archive-name: br/part01 +# Environment: basic, dos, os9 + include Math require "date.rb" require "parsearg.rb" diff --git a/sample/cal.rb b/sample/cal.rb index c15bb29fc6..f256a01a39 100644 --- a/sample/cal.rb +++ b/sample/cal.rb @@ -1,4 +1,4 @@ -#! /usr/local/bin/ruby +#! /usr/bin/env ruby # cal.rb: Written by Tadayoshi Funaba 1998-2000 # $Id: cal.rb,v 1.10 2000/05/20 02:09:47 tadf Exp $ diff --git a/sample/test.rb b/sample/test.rb index 87106330cc..1106053c10 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -1,16 +1,16 @@ -#! /usr/local/bin/ruby +#! /usr/bin/env ruby $testnum=0 $ntest=0 $failed = 0 -def check(what) +def test_check(what) printf "%s\n", what $what = what $testnum = 0 end -def ok(cond) +def test_ok(cond) $testnum+=1 $ntest+=1 if cond @@ -24,84 +24,84 @@ end # make sure conditional operators work -check "assignment" +test_check "assignment" a=[]; a[0] ||= "bar"; -ok(a[0] == "bar") +test_ok(a[0] == "bar") h={}; h["foo"] ||= "bar"; -ok(h["foo"] == "bar") +test_ok(h["foo"] == "bar") aa = 5 aa ||= 25 -ok(aa == 5) +test_ok(aa == 5) bb ||= 25 -ok(bb == 25) +test_ok(bb == 25) cc &&=33 -ok(cc == nil) +test_ok(cc == nil) cc = 5 cc &&=44 -ok(cc == 44) +test_ok(cc == 44) -check "condition" +test_check "condition" $x = '0'; -$x == $x && ok(true) -$x != $x && ok(false) -$x == $x || ok(false) -$x != $x || ok(true) +$x == $x && test_ok(true) +$x != $x && test_ok(false) +$x == $x || test_ok(false) +$x != $x || test_ok(true) # first test to see if we can run the tests. -check "if/unless"; +test_check "if/unless"; $x = 'test'; -ok(if $x == $x then true else false end) +test_ok(if $x == $x then true else false end) $bad = false unless $x == $x $bad = true end -ok(!$bad) -ok(unless $x != $x then true else false end) +test_ok(!$bad) +test_ok(unless $x != $x then true else false end) -check "case" +test_check "case" case 5 when 1, 2, 3, 4, 6, 7, 8 - ok(false) + test_ok(false) when 5 - ok(true) + test_ok(true) end case 5 when 5 - ok(true) + test_ok(true) when 1..10 - ok(false) + test_ok(false) end case 5 when 1..10 - ok(true) + test_ok(true) else - ok(false) + test_ok(false) end case 5 when 5 - ok(true) + test_ok(true) else - ok(false) + test_ok(false) end case "foobar" when /^f.*r$/ - ok(true) + test_ok(true) else - ok(false) + test_ok(false) end -check "while/until"; +test_check "while/until"; tmp = open("while_tmp", "w") tmp.print "tvi925\n"; @@ -114,13 +114,13 @@ tmp.close # test break tmp = open("while_tmp", "r") -ok(tmp.kind_of?(File)) +test_ok(tmp.kind_of?(File)) while tmp.gets() break if /vt100/ end -ok(!tmp.eof? && /vt100/) +test_ok(!tmp.eof? && /vt100/) tmp.close # test next @@ -130,7 +130,7 @@ while tmp.gets() next if /vt100/; $bad = 1 if /vt100/; end -ok(!(!tmp.eof? || /vt100/ || $bad)) +test_ok(!(!tmp.eof? || /vt100/ || $bad)) tmp.close # test redo @@ -146,7 +146,7 @@ while tmp.gets() $bad = 1 if /vt100/ $bad = 1 if /VT100/ end -ok(tmp.eof? && !$bad) +test_ok(tmp.eof? && !$bad) tmp.close sum=0 @@ -157,7 +157,7 @@ for i in 1..10 redo end end -ok(sum == 220) +test_ok(sum == 220) # test interval $bad = false @@ -169,27 +169,27 @@ while tmp.gets() break end end -ok(!$bad) +test_ok(!$bad) tmp.close File.unlink "while_tmp" or `/bin/rm -f "while_tmp"` -ok(!File.exist?("while_tmp")) +test_ok(!File.exist?("while_tmp")) i = 0 until i>4 i+=1 end -ok(i>4) +test_ok(i>4) # exception handling -check "exception"; +test_check "exception"; begin raise "this must be handled" - ok(false) + test_ok(false) rescue - ok(true) + test_ok(true) end $bad = true @@ -199,10 +199,10 @@ rescue if $bad $bad = false retry - ok(false) + test_ok(false) end end -ok(true) +test_ok(true) # exception in rescue clause $string = "this must be handled no.3" @@ -212,9 +212,9 @@ begin rescue raise $string end - ok(false) + test_ok(false) rescue - ok(true) if $! == $string + test_ok(true) if $! == $string end # exception in ensure clause @@ -224,9 +224,9 @@ begin ensure raise "exception in ensure clause" end - ok(false) + test_ok(false) rescue - ok(true) + test_ok(true) end $bad = true @@ -238,7 +238,7 @@ begin end rescue end -ok(!$bad) +test_ok(!$bad) $bad = true begin @@ -249,7 +249,7 @@ begin end rescue end -ok(!$bad) +test_ok(!$bad) $bad = true while true @@ -259,104 +259,104 @@ while true $bad = false end end -ok(!$bad) +test_ok(!$bad) -ok(catch(:foo) { +test_ok(catch(:foo) { loop do loop do throw :foo, true break end break - ok(false) # should no reach here + test_ok(false) # should no reach here end false }) -check "array" -ok([1, 2] + [3, 4] == [1, 2, 3, 4]) -ok([1, 2] * 2 == [1, 2, 1, 2]) -ok([1, 2] * ":" == "1:2") +test_check "array" +test_ok([1, 2] + [3, 4] == [1, 2, 3, 4]) +test_ok([1, 2] * 2 == [1, 2, 1, 2]) +test_ok([1, 2] * ":" == "1:2") -ok([1, 2].hash == [1, 2].hash) +test_ok([1, 2].hash == [1, 2].hash) -ok([1,2,3] & [2,3,4] == [2,3]) -ok([1,2,3] | [2,3,4] == [1,2,3,4]) -ok([1,2,3] - [2,3] == [1]) +test_ok([1,2,3] & [2,3,4] == [2,3]) +test_ok([1,2,3] | [2,3,4] == [1,2,3,4]) +test_ok([1,2,3] - [2,3] == [1]) $x = [0, 1, 2, 3, 4, 5] -ok($x[2] == 2) -ok($x[1..3] == [1, 2, 3]) -ok($x[1,3] == [1, 2, 3]) +test_ok($x[2] == 2) +test_ok($x[1..3] == [1, 2, 3]) +test_ok($x[1,3] == [1, 2, 3]) $x[0, 2] = 10 -ok($x[0] == 10 && $x[1] == 2) +test_ok($x[0] == 10 && $x[1] == 2) $x[0, 0] = -1 -ok($x[0] == -1 && $x[1] == 10) +test_ok($x[0] == -1 && $x[1] == 10) $x[-1, 1] = 20 -ok($x[-1] == 20 && $x.pop == 20) +test_ok($x[-1] == 20 && $x.pop == 20) # array and/or -ok(([1,2,3]&[2,4,6]) == [2]) -ok(([1,2,3]|[2,4,6]) == [1,2,3,4,6]) +test_ok(([1,2,3]&[2,4,6]) == [2]) +test_ok(([1,2,3]|[2,4,6]) == [1,2,3,4,6]) # compact $x = [nil, 1, nil, nil, 5, nil, nil] $x.compact! -ok($x == [1, 5]) +test_ok($x == [1, 5]) # uniq $x = [1, 1, 4, 2, 5, 4, 5, 1, 2] $x.uniq! -ok($x == [1, 4, 2, 5]) +test_ok($x == [1, 4, 2, 5]) # empty? -ok(!$x.empty?) +test_ok(!$x.empty?) $x = [] -ok($x.empty?) +test_ok($x.empty?) # sort $x = ["it", "came", "to", "pass", "that", "..."] $x = $x.sort.join(" ") -ok($x == "... came it pass that to") +test_ok($x == "... came it pass that to") $x = [2,5,3,1,7] $x.sort!{|a,b| a<=>b} # sort with condition -ok($x == [1,2,3,5,7]) +test_ok($x == [1,2,3,5,7]) $x.sort!{|a,b| b-a} # reverse sort -ok($x == [7,5,3,2,1]) +test_ok($x == [7,5,3,2,1]) # split test -$x = "The Book of Mormon" -ok($x.split(//).reverse!.join == $x.reverse) -ok($x.reverse == $x.reverse!) -ok("1 byte string".split(//).reverse.join(":") == "g:n:i:r:t:s: :e:t:y:b: :1") +$x = "The Botest_ok of Mormon" +test_ok($x.split(//).reverse!.join == $x.reverse) +test_ok($x.reverse == $x.reverse!) +test_ok("1 byte string".split(//).reverse.join(":") == "g:n:i:r:t:s: :e:t:y:b: :1") $x = "a b c d" -ok($x.split == ['a', 'b', 'c', 'd']) -ok($x.split(' ') == ['a', 'b', 'c', 'd']) -ok(defined? "a".chomp) -ok("abc".scan(/./) == ["a", "b", "c"]) -ok("1a2b3c".scan(/(\d.)/) == [["1a"], ["2b"], ["3c"]]) +test_ok($x.split == ['a', 'b', 'c', 'd']) +test_ok($x.split(' ') == ['a', 'b', 'c', 'd']) +test_ok(defined? "a".chomp) +test_ok("abc".scan(/./) == ["a", "b", "c"]) +test_ok("1a2b3c".scan(/(\d.)/) == [["1a"], ["2b"], ["3c"]]) # non-greedy match -ok("a=12;b=22".scan(/(.*?)=(\d*);?/) == [["a", "12"], ["b", "22"]]) +test_ok("a=12;b=22".scan(/(.*?)=(\d*);?/) == [["a", "12"], ["b", "22"]]) $x = [1] -ok(($x * 5).join(":") == '1:1:1:1:1') -ok(($x * 1).join(":") == '1') -ok(($x * 0).join(":") == '') +test_ok(($x * 5).join(":") == '1:1:1:1:1') +test_ok(($x * 1).join(":") == '1') +test_ok(($x * 0).join(":") == '') *$x = (1..7).to_a -ok($x.size == 7) -ok($x == [1, 2, 3, 4, 5, 6, 7]) +test_ok($x.size == 7) +test_ok($x == [1, 2, 3, 4, 5, 6, 7]) -check "hash" +test_check "hash" $x = {1=>2, 2=>4, 3=>6} $y = {1, 2, 2, 4, 3, 6} -ok($x[1] == 2) +test_ok($x[1] == 2) -ok(begin +test_ok(begin for k,v in $y raise if k*2 != v end @@ -365,37 +365,37 @@ ok(begin false end) -ok($x.length == 3) -ok($x.has_key?(1)) -ok($x.has_value?(4)) -ok($x.indexes(2,3) == [4,6]) -ok($x == {1=>2, 2=>4, 3=>6}) +test_ok($x.length == 3) +test_ok($x.has_key?(1)) +test_ok($x.has_value?(4)) +test_ok($x.indexes(2,3) == [4,6]) +test_ok($x == {1=>2, 2=>4, 3=>6}) $z = $y.keys.join(":") -ok($z == "1:2:3") +test_ok($z == "1:2:3") $z = $y.values.join(":") -ok($z == "2:4:6") -ok($x == $y) +test_ok($z == "2:4:6") +test_ok($x == $y) $y.shift -ok($y.length == 2) +test_ok($y.length == 2) $z = [1,2] $y[$z] = 256 -ok($y[$z] == 256) +test_ok($y[$z] == 256) -check "iterator" +test_check "iterator" -ok(!iterator?) +test_ok(!iterator?) def ttt - ok(iterator?) + test_ok(iterator?) end ttt{} # yield at top level -ok(!defined?(yield)) +test_ok(!defined?(yield)) $x = [1, 2, 3, 4] $y = [] @@ -404,7 +404,7 @@ $y = [] for i in $x $y.push i end -ok($x == $y) +test_ok($x == $y) # nested iterator def tt @@ -414,7 +414,7 @@ def tt end tt{|i| break if i == 5} -ok(i == 5) +test_ok(i == 5) def tt2(dummy) yield 1 @@ -431,7 +431,7 @@ rescue ArgumentError $x = true rescue Exception end -ok($x) +test_ok($x) # iterator break/redo/next/retry done = true @@ -439,7 +439,7 @@ loop{ break done = false # should not reach here } -ok(done) +test_ok(done) done = false $bad = false @@ -449,7 +449,7 @@ loop { next $bad = true # should not reach here } -ok(!$bad) +test_ok(!$bad) done = false $bad = false @@ -459,14 +459,14 @@ loop { redo $bad = true # should not reach here } -ok(!$bad) +test_ok(!$bad) $x = [] for i in 1 .. 7 $x.push i end -ok($x.size == 7) -ok($x == [1, 2, 3, 4, 5, 6, 7]) +test_ok($x.size == 7) +test_ok($x == [1, 2, 3, 4, 5, 6, 7]) $done = false $x = [] @@ -477,8 +477,8 @@ for i in 1 .. 7 # see how retry works in iterator loop end $x.push(i) end -ok($x.size == 10) -ok($x == [1, 2, 3, 1, 2, 3, 4, 5, 6, 7]) +test_ok($x.size == 10) +test_ok($x == [1, 2, 3, 1, 2, 3, 4, 5, 6, 7]) # append method to built-in class class Array @@ -491,7 +491,7 @@ class Array end end $x = [[1,2],[3,4],[5,6]] -ok($x.iter_test1{|x|x} == $x.iter_test2{|x|x}) +test_ok($x.iter_test1{|x|x} == $x.iter_test2{|x|x}) class IterTest def initialize(e); @body = e; end @@ -508,60 +508,60 @@ class IterTest end IterTest.new([0]).each0 { |x| $x = x } -ok($x == 0) +test_ok($x == 0) IterTest.new([1]).each1 { |x| $x = x } -ok($x == 1) +test_ok($x == 1) IterTest.new([2]).each2 { |x| $x = x } -ok($x == [2]) +test_ok($x == [2]) IterTest.new([3]).each3 { |x| $x = x } -ok($x == 3) +test_ok($x == 3) IterTest.new([4]).each4 { |x| $x = x } -ok($x == 4) +test_ok($x == 4) IterTest.new([5]).each5 { |x| $x = x } -ok($x == 5) +test_ok($x == 5) IterTest.new([6]).each6 { |x| $x = x } -ok($x == [6]) +test_ok($x == [6]) IterTest.new([7]).each7 { |x| $x = x } -ok($x == 7) +test_ok($x == 7) IterTest.new([8]).each8 { |x| $x = x } -ok($x == 8) +test_ok($x == 8) IterTest.new([[0]]).each0 { |x| $x = x } -ok($x == [0]) +test_ok($x == [0]) IterTest.new([[1]]).each1 { |x| $x = x } -ok($x == 1) +test_ok($x == 1) IterTest.new([[2]]).each2 { |x| $x = x } -ok($x == [2]) +test_ok($x == [2]) IterTest.new([[3]]).each3 { |x| $x = x } -ok($x == 3) +test_ok($x == 3) IterTest.new([[4]]).each4 { |x| $x = x } -ok($x == [4]) +test_ok($x == [4]) IterTest.new([[5]]).each5 { |x| $x = x } -ok($x == 5) +test_ok($x == 5) IterTest.new([[6]]).each6 { |x| $x = x } -ok($x == [6]) +test_ok($x == [6]) IterTest.new([[7]]).each7 { |x| $x = x } -ok($x == 7) +test_ok($x == 7) IterTest.new([[8]]).each8 { |x| $x = x } -ok($x == [8]) +test_ok($x == [8]) IterTest.new([[0,0]]).each0 { |x| $x = x } -ok($x == [0,0]) +test_ok($x == [0,0]) IterTest.new([[8,8]]).each8 { |x| $x = x } -ok($x == [8,8]) - -check "float" -ok(2.6.floor == 2) -ok(-2.6.floor == -3) -ok(2.6.ceil == 3) -ok(-2.6.ceil == -2) -ok(2.6.truncate == 2) -ok(-2.6.truncate == -2) -ok(2.6.round == 3) -ok(-2.4.truncate == -2) -ok((13.4 % 1 - 0.4).abs < 0.0001) - -check "bignum" +test_ok($x == [8,8]) + +test_check "float" +test_ok(2.6.floor == 2) +test_ok(-2.6.floor == -3) +test_ok(2.6.ceil == 3) +test_ok(-2.6.ceil == -2) +test_ok(2.6.truncate == 2) +test_ok(-2.6.truncate == -2) +test_ok(2.6.round == 3) +test_ok(-2.4.truncate == -2) +test_ok((13.4 % 1 - 0.4).abs < 0.0001) + +test_check "bignum" def fact(n) return 1 if n == 0 f = 1 @@ -573,24 +573,24 @@ def fact(n) end fact(3) $x = fact(40) -ok($x == $x) -ok($x == fact(40)) -ok($x < $x+2) -ok($x > $x-2) -ok($x == 815915283247897734345611269596115894272000000000) -ok($x != 815915283247897734345611269596115894272000000001) -ok($x+1 == 815915283247897734345611269596115894272000000001) -ok($x/fact(20) == 335367096786357081410764800000) +test_ok($x == $x) +test_ok($x == fact(40)) +test_ok($x < $x+2) +test_ok($x > $x-2) +test_ok($x == 815915283247897734345611269596115894272000000000) +test_ok($x != 815915283247897734345611269596115894272000000001) +test_ok($x+1 == 815915283247897734345611269596115894272000000001) +test_ok($x/fact(20) == 335367096786357081410764800000) $x = -$x -ok($x == -815915283247897734345611269596115894272000000000) -ok(2-(2**32) == -(2**32-2)) -ok(2**32 - 5 == (2**32-3)-2) +test_ok($x == -815915283247897734345611269596115894272000000000) +test_ok(2-(2**32) == -(2**32-2)) +test_ok(2**32 - 5 == (2**32-3)-2) $good = true; for i in 1000..1014 $good = false if ((1<<i) != (2**i)) end -ok($good) +test_ok($good) $good = true; n1=1<<1000 @@ -598,7 +598,7 @@ for i in 1000..1014 $good = false if ((1<<i) != n1) n1 *= 2 end -ok($good) +test_ok($good) $good = true; n2=n1 @@ -607,7 +607,7 @@ for i in 1..10 n2 = n2 >> 1 $good = false if (n1 != n2) end -ok($good) +test_ok($good) $good = true; for i in 4000..4096 @@ -616,94 +616,94 @@ for i in 4000..4096 $good = false end end -ok($good) +test_ok($good) b = 10**80 a = b * 9 + 7 -ok(7 == a.modulo(b)) -ok(-b + 7 == a.modulo(-b)) -ok(b + -7 == (-a).modulo(b)) -ok(-7 == (-a).modulo(-b)) -ok(7 == a.remainder(b)) -ok(7 == a.remainder(-b)) -ok(-7 == (-a).remainder(b)) -ok(-7 == (-a).remainder(-b)) - -check "string & char" - -ok("abcd" == "abcd") -ok("abcd" =~ "abcd") -ok("abcd" === "abcd") +test_ok(7 == a.modulo(b)) +test_ok(-b + 7 == a.modulo(-b)) +test_ok(b + -7 == (-a).modulo(b)) +test_ok(-7 == (-a).modulo(-b)) +test_ok(7 == a.remainder(b)) +test_ok(7 == a.remainder(-b)) +test_ok(-7 == (-a).remainder(b)) +test_ok(-7 == (-a).remainder(-b)) + +test_check "string & char" + +test_ok("abcd" == "abcd") +test_ok("abcd" =~ "abcd") +test_ok("abcd" === "abcd") # compile time string concatenation -ok("ab" "cd" == "abcd") -ok("#{22}aa" "cd#{44}" == "22aacd44") -ok("#{22}aa" "cd#{44}" "55" "#{66}" == "22aacd445566") -ok("abc" !~ /^$/) -ok("abc\n" !~ /^$/) -ok("abc" !~ /^d*$/) -ok(("abc" =~ /d*$/) == 3) -ok("" =~ /^$/) -ok("\n" =~ /^$/) -ok("a\n\n" =~ /^$/) -ok("abcabc" =~ /.*a/ && $& == "abca") -ok("abcabc" =~ /.*c/ && $& == "abcabc") -ok("abcabc" =~ /.*?a/ && $& == "a") -ok("abcabc" =~ /.*?c/ && $& == "abc") -ok(/(.|\n)*?\n(b|\n)/ =~ "a\nb\n\n" && $& == "a\nb") - -ok(/^(ab+)+b/ =~ "ababb" && $& == "ababb") -ok(/^(?:ab+)+b/ =~ "ababb" && $& == "ababb") -ok(/^(ab+)+/ =~ "ababb" && $& == "ababb") -ok(/^(?:ab+)+/ =~ "ababb" && $& == "ababb") - -ok(/(\s+\d+){2}/ =~ " 1 2" && $& == " 1 2") -ok(/(?:\s+\d+){2}/ =~ " 1 2" && $& == " 1 2") +test_ok("ab" "cd" == "abcd") +test_ok("#{22}aa" "cd#{44}" == "22aacd44") +test_ok("#{22}aa" "cd#{44}" "55" "#{66}" == "22aacd445566") +test_ok("abc" !~ /^$/) +test_ok("abc\n" !~ /^$/) +test_ok("abc" !~ /^d*$/) +test_ok(("abc" =~ /d*$/) == 3) +test_ok("" =~ /^$/) +test_ok("\n" =~ /^$/) +test_ok("a\n\n" =~ /^$/) +test_ok("abcabc" =~ /.*a/ && $& == "abca") +test_ok("abcabc" =~ /.*c/ && $& == "abcabc") +test_ok("abcabc" =~ /.*?a/ && $& == "a") +test_ok("abcabc" =~ /.*?c/ && $& == "abc") +test_ok(/(.|\n)*?\n(b|\n)/ =~ "a\nb\n\n" && $& == "a\nb") + +test_ok(/^(ab+)+b/ =~ "ababb" && $& == "ababb") +test_ok(/^(?:ab+)+b/ =~ "ababb" && $& == "ababb") +test_ok(/^(ab+)+/ =~ "ababb" && $& == "ababb") +test_ok(/^(?:ab+)+/ =~ "ababb" && $& == "ababb") + +test_ok(/(\s+\d+){2}/ =~ " 1 2" && $& == " 1 2") +test_ok(/(?:\s+\d+){2}/ =~ " 1 2" && $& == " 1 2") $x = <<END; ABCD ABCD END $x.gsub!(/((.|\n)*?)B((.|\n)*?)D/){$1+$3} -ok($x == "AC\nAC\n") +test_ok($x == "AC\nAC\n") -ok("foobar" =~ /foo(?=(bar)|(baz))/) -ok("foobaz" =~ /foo(?=(bar)|(baz))/) +test_ok("foobar" =~ /foo(?=(bar)|(baz))/) +test_ok("foobaz" =~ /foo(?=(bar)|(baz))/) $foo = "abc" -ok("#$foo = abc" == "abc = abc") -ok("#{$foo} = abc" == "abc = abc") +test_ok("#$foo = abc" == "abc = abc") +test_ok("#{$foo} = abc" == "abc = abc") foo = "abc" -ok("#{foo} = abc" == "abc = abc") +test_ok("#{foo} = abc" == "abc = abc") -ok('-' * 5 == '-----') -ok('-' * 1 == '-') -ok('-' * 0 == '') +test_ok('-' * 5 == '-----') +test_ok('-' * 1 == '-') +test_ok('-' * 0 == '') foo = '-' -ok(foo * 5 == '-----') -ok(foo * 1 == '-') -ok(foo * 0 == '') +test_ok(foo * 5 == '-----') +test_ok(foo * 1 == '-') +test_ok(foo * 0 == '') $x = "a.gif" -ok($x.sub(/.*\.([^\.]+)$/, '\1') == "gif") -ok($x.sub(/.*\.([^\.]+)$/, 'b.\1') == "b.gif") -ok($x.sub(/.*\.([^\.]+)$/, '\2') == "") -ok($x.sub(/.*\.([^\.]+)$/, 'a\2b') == "ab") -ok($x.sub(/.*\.([^\.]+)$/, '<\&>') == "<a.gif>") +test_ok($x.sub(/.*\.([^\.]+)$/, '\1') == "gif") +test_ok($x.sub(/.*\.([^\.]+)$/, 'b.\1') == "b.gif") +test_ok($x.sub(/.*\.([^\.]+)$/, '\2') == "") +test_ok($x.sub(/.*\.([^\.]+)$/, 'a\2b') == "ab") +test_ok($x.sub(/.*\.([^\.]+)$/, '<\&>') == "<a.gif>") # character constants(assumes ASCII) -ok("a"[0] == ?a) -ok(?a == ?a) -ok(?\C-a == 1) -ok(?\M-a == 225) -ok(?\M-\C-a == 129) -ok("a".upcase![0] == ?A) -ok("A".downcase![0] == ?a) -ok("abc".tr!("a-z", "A-Z") == "ABC") -ok("aabbcccc".tr_s!("a-z", "A-Z") == "ABC") -ok("abcc".squeeze!("a-z") == "abc") -ok("abcd".delete!("bc") == "ad") +test_ok("a"[0] == ?a) +test_ok(?a == ?a) +test_ok(?\C-a == 1) +test_ok(?\M-a == 225) +test_ok(?\M-\C-a == 129) +test_ok("a".upcase![0] == ?A) +test_ok("A".downcase![0] == ?a) +test_ok("abc".tr!("a-z", "A-Z") == "ABC") +test_ok("aabbcccc".tr_s!("a-z", "A-Z") == "ABC") +test_ok("abcc".squeeze!("a-z") == "abc") +test_ok("abcd".delete!("bc") == "ad") $x = "abcdef" $y = [ ?a, ?b, ?c, ?d, ?e, ?f ] @@ -714,43 +714,43 @@ $x.each_byte {|i| break end } -ok(!$bad) +test_ok(!$bad) s = "a string" s[0..s.size]="another string" -ok(s == "another string") +test_ok(s == "another string") -check "assignment" +test_check "assignment" a = nil -ok(defined?(a)) -ok(a == nil) +test_ok(defined?(a)) +test_ok(a == nil) # multiple asignment a, b = 1, 2 -ok(a == 1 && b == 2) +test_ok(a == 1 && b == 2) a, b = b, a -ok(a == 2 && b == 1) +test_ok(a == 2 && b == 1) a, = 1,2 -ok(a == 1) +test_ok(a == 1) a, *b = 1, 2, 3 -ok(a == 1 && b == [2, 3]) +test_ok(a == 1 && b == [2, 3]) a, (b, c), d = 1, [2, 3], 4 -ok(a == 1 && b == 2 && c == 3 && d == 4) +test_ok(a == 1 && b == 2 && c == 3 && d == 4) *a = 1, 2, 3 -ok(a == [1, 2, 3]) +test_ok(a == [1, 2, 3]) *a = 4 -ok(a == [4]) +test_ok(a == [4]) *a = nil -ok(a == [nil]) +test_ok(a == [nil]) -check "call" +test_check "call" def aaa(a, b=100, *rest) res = [a, b] res += rest if rest @@ -760,31 +760,31 @@ end # not enough argument begin aaa() # need at least 1 arg - ok(false) + test_ok(false) rescue - ok(true) + test_ok(true) end begin aaa # no arg given (exception raised) - ok(false) + test_ok(false) rescue - ok(true) + test_ok(true) end -ok(aaa(1) == [1, 100]) -ok(aaa(1, 2) == [1, 2]) -ok(aaa(1, 2, 3, 4) == [1, 2, 3, 4]) -ok(aaa(1, *[2, 3, 4]) == [1, 2, 3, 4]) +test_ok(aaa(1) == [1, 100]) +test_ok(aaa(1, 2) == [1, 2]) +test_ok(aaa(1, 2, 3, 4) == [1, 2, 3, 4]) +test_ok(aaa(1, *[2, 3, 4]) == [1, 2, 3, 4]) -check "proc" +test_check "proc" $proc = proc{|i| i} -ok($proc.call(2) == 2) -ok($proc.call(3) == 3) +test_ok($proc.call(2) == 2) +test_ok($proc.call(3) == 3) $proc = proc{|i| i*2} -ok($proc.call(2) == 4) -ok($proc.call(3) == 6) +test_ok($proc.call(2) == 4) +test_ok($proc.call(3) == 6) proc{ iii=5 # nested local variable @@ -795,23 +795,23 @@ proc{ $x = iii # nested variables shared by procs } # scope of nested variables - ok(defined?(iii)) + test_ok(defined?(iii)) }.call -ok(!defined?(iii)) # out of scope +test_ok(!defined?(iii)) # out of scope $x=0 $proc.call(5) $proc2.call -ok($x == 5) +test_ok($x == 5) if defined? Process.kill - check "signal" + test_check "signal" $x = 0 trap "SIGINT", proc{|sig| $x = 2} Process.kill "SIGINT", $$ sleep 0.1 - ok($x == 2) + test_ok($x == 2) trap "SIGINT", proc{raise "Interrupt"} @@ -822,35 +822,35 @@ if defined? Process.kill rescue x = $! end - ok(x && /Interrupt/ =~ x) + test_ok(x && /Interrupt/ =~ x) end -check "eval" -ok(eval("") == nil) +test_check "eval" +test_ok(eval("") == nil) $bad=false eval 'while false; $bad = true; print "foo\n" end' -ok(!$bad) +test_ok(!$bad) -ok(eval('TRUE')) -ok(eval('true')) -ok(!eval('NIL')) -ok(!eval('nil')) -ok(!eval('FALSE')) -ok(!eval('false')) +test_ok(eval('TRUE')) +test_ok(eval('true')) +test_ok(!eval('NIL')) +test_ok(!eval('nil')) +test_ok(!eval('FALSE')) +test_ok(!eval('false')) -$foo = 'ok(true)' +$foo = 'test_ok(true)' begin eval $foo rescue - ok(false) + test_ok(false) end -ok(eval("$foo") == 'ok(true)') -ok(eval("true") == true) +test_ok(eval("$foo") == 'test_ok(true)') +test_ok(eval("true") == true) i = 5 -ok(eval("i == 5")) -ok(eval("i") == 5) -ok(eval("defined? i")) +test_ok(eval("i == 5")) +test_ok(eval("i") == 5) +test_ok(eval("defined? i")) # eval with binding def test_ev @@ -862,56 +862,56 @@ def test_ev end $x = test_ev -ok(eval("local1", $x) == "local1") # normal local var -ok(eval("local2", $x) == "local2") # nested local var +test_ok(eval("local1", $x) == "local1") # normal local var +test_ok(eval("local2", $x) == "local2") # nested local var $bad = true begin p eval("local1") rescue NameError # must raise error $bad = false end -ok(!$bad) +test_ok(!$bad) module EvTest EVTEST1 = 25 evtest2 = 125 $x = binding end -ok(eval("EVTEST1", $x) == 25) # constant in module -ok(eval("evtest2", $x) == 125) # local var in module +test_ok(eval("EVTEST1", $x) == 25) # constant in module +test_ok(eval("evtest2", $x) == 125) # local var in module $bad = true begin eval("EVTEST1") rescue NameError # must raise error $bad = false end -ok(!$bad) +test_ok(!$bad) x = proc{} eval "i4 = 1", x -ok(eval("i4", x) == 1) +test_ok(eval("i4", x) == 1) x = proc{proc{}}.call eval "i4 = 22", x -ok(eval("i4", x) == 22) +test_ok(eval("i4", x) == 22) $x = [] x = proc{proc{}}.call eval "(0..9).each{|i5| $x[i5] = proc{i5*2}}", x -ok($x[4].call == 8) +test_ok($x[4].call == 8) x = binding eval "i = 1", x -ok(eval("i", x) == 1) +test_ok(eval("i", x) == 1) x = proc{binding}.call eval "i = 22", x -ok(eval("i", x) == 22) +test_ok(eval("i", x) == 22) $x = [] x = proc{binding}.call eval "(0..9).each{|i5| $x[i5] = proc{i5*2}}", x -ok($x[4].call == 8) +test_ok($x[4].call == 8) x = proc{binding}.call eval "for i6 in 1..1; j6=i6; end", x -ok(eval("defined? i6", x)) -ok(eval("defined? j6", x)) +test_ok(eval("defined? i6", x)) +test_ok(eval("defined? j6", x)) proc { p = binding @@ -919,44 +919,44 @@ proc { foo22 = 5 proc{foo11=22}.call proc{foo22=55}.call - ok(eval("foo11", p) == eval("foo11")) - ok(eval("foo11") == 1) - ok(eval("foo22", p) == eval("foo22")) - ok(eval("foo22") == 55) + test_ok(eval("foo11", p) == eval("foo11")) + test_ok(eval("foo11") == 1) + test_ok(eval("foo22", p) == eval("foo22")) + test_ok(eval("foo22") == 55) }.call p1 = proc{i7 = 0; proc{i7}}.call -ok(p1.call == 0) +test_ok(p1.call == 0) eval "i7=5", p1 -ok(p1.call == 5) -ok(!defined?(i7)) +test_ok(p1.call == 5) +test_ok(!defined?(i7)) p1 = proc{i7 = 0; proc{i7}}.call i7 = nil -ok(p1.call == 0) +test_ok(p1.call == 0) eval "i7=1", p1 -ok(p1.call == 1) +test_ok(p1.call == 1) eval "i7=5", p1 -ok(p1.call == 5) -ok(i7 == nil) +test_ok(p1.call == 5) +test_ok(i7 == nil) -check "system" -ok(`echo foobar` == "foobar\n") -ok(`./miniruby -e 'print "foobar"'` == 'foobar') +test_check "system" +test_ok(`echo foobar` == "foobar\n") +test_ok(`./miniruby -e 'print "foobar"'` == 'foobar') tmp = open("script_tmp", "w") tmp.print "print $zzz\n"; tmp.close -ok(`./miniruby -s script_tmp -zzz` == 'true') -ok(`./miniruby -s script_tmp -zzz=555` == '555') +test_ok(`./miniruby -s script_tmp -zzz` == 'true') +test_ok(`./miniruby -s script_tmp -zzz=555` == '555') tmp = open("script_tmp", "w") tmp.print "#! /usr/local/bin/ruby -s\n"; tmp.print "print $zzz\n"; tmp.close -ok(`./miniruby script_tmp -zzz=678` == '678') +test_ok(`./miniruby script_tmp -zzz=678` == '678') tmp = open("script_tmp", "w") tmp.print "this is a leading junk\n"; @@ -966,8 +966,8 @@ tmp.print "__END__\n"; tmp.print "this is a trailing junk\n"; tmp.close -ok(`./miniruby -x script_tmp` == 'nil') -ok(`./miniruby -x script_tmp -zzz=555` == '555') +test_ok(`./miniruby -x script_tmp` == 'nil') +test_ok(`./miniruby -x script_tmp -zzz=555` == '555') tmp = open("script_tmp", "w") for i in 1..5 @@ -985,20 +985,21 @@ while tmp.gets end end tmp.close -ok(done) +test_ok(done) File.unlink "script_tmp" or `/bin/rm -f "script_tmp"` File.unlink "script_tmp.bak" or `/bin/rm -f "script_tmp.bak"` $bad = false -for script in Dir["{lib,sample}/**/*.rb"] - unless `./miniruby -c #{script}`.chomp == "Syntax OK" +for script in Dir["{lib,sample,ext}/**/*.rb"] + `./miniruby -c #{script}` + unless $? $bad = true end end -ok(!$bad) +test_ok(!$bad) -check "const" +test_check "const" TEST1 = 1 TEST2 = 2 @@ -1014,13 +1015,13 @@ end include Const -ok([TEST1,TEST2,TEST3,TEST4] == [1,2,3,4]) +test_ok([TEST1,TEST2,TEST3,TEST4] == [1,2,3,4]) include Const2 STDERR.print "intentionally redefines TEST3, TEST4\n" if $VERBOSE -ok([TEST1,TEST2,TEST3,TEST4] == [1,2,6,8]) +test_ok([TEST1,TEST2,TEST3,TEST4] == [1,2,6,8]) -check "clone" +test_check "clone" foo = Object.new def foo.test "test" @@ -1030,23 +1031,23 @@ def bar.test2 "test2" end -ok(bar.test2 == "test2") -ok(bar.test == "test") -ok(foo.test == "test") +test_ok(bar.test2 == "test2") +test_ok(bar.test == "test") +test_ok(foo.test == "test") begin foo.test2 - ok false + test_ok false rescue NameError - ok true + test_ok true end -check "marshal" +test_check "marshal" $x = [1,2,3,[4,5,"foo"],{1=>"bar"},2.5,fact(30)] $y = Marshal.dump($x) -ok($x == Marshal.load($y)) +test_ok($x == Marshal.load($y)) -check "pack" +test_check "pack" $format = "c2x5CCxsdils_l_a6"; # Need the expression in here to force ary[5] to be numeric. This avoids @@ -1055,86 +1056,86 @@ ary = [1,-100,127,128,32767,987.654321098 / 100.0,12345,123456,-32767,-123456,"a $x = ary.pack($format) ary2 = $x.unpack($format) -ok(ary.length == ary2.length) -ok(ary.join(':') == ary2.join(':')) -ok($x =~ /def/) +test_ok(ary.length == ary2.length) +test_ok(ary.join(':') == ary2.join(':')) +test_ok($x =~ /def/) -check "math" -ok(Math.sqrt(4) == 2) +test_check "math" +test_ok(Math.sqrt(4) == 2) include Math -ok(sqrt(4) == 2) +test_ok(sqrt(4) == 2) -check "struct" +test_check "struct" struct_test = Struct.new("Test", :foo, :bar) -ok(struct_test == Struct::Test) +test_ok(struct_test == Struct::Test) test = struct_test.new(1, 2) -ok(test.foo == 1 && test.bar == 2) -ok(test[0] == 1 && test[1] == 2) +test_ok(test.foo == 1 && test.bar == 2) +test_ok(test[0] == 1 && test[1] == 2) a, b = test.to_a -ok(a == 1 && b == 2) +test_ok(a == 1 && b == 2) test[0] = 22 -ok(test.foo == 22) +test_ok(test.foo == 22) test.bar = 47 -ok(test.bar == 47) +test_ok(test.bar == 47) -check "variable" -ok($$.instance_of?(Fixnum)) +test_check "variable" +test_ok($$.instance_of?(Fixnum)) # read-only variable begin $$ = 5 - ok false + test_ok false rescue NameError - ok true + test_ok true end foobar = "foobar" $_ = foobar -ok($_ == foobar) +test_ok($_ == foobar) -check "trace" +test_check "trace" $x = 1234 $y = 0 trace_var :$x, proc{$y = $x} $x = 40414 -ok($y == $x) +test_ok($y == $x) untrace_var :$x $x = 19660208 -ok($y != $x) +test_ok($y != $x) trace_var :$x, proc{$x *= 2} $x = 5 -ok($x == 10) +test_ok($x == 10) untrace_var :$x -check "defined?" +test_check "defined?" -ok(defined?($x)) # global variable -ok(defined?($x) == 'global-variable')# returns description +test_ok(defined?($x)) # global variable +test_ok(defined?($x) == 'global-variable')# returns description foo=5 -ok(defined?(foo)) # local variable +test_ok(defined?(foo)) # local variable -ok(defined?(Array)) # constant -ok(defined?(Object.new)) # method -ok(!defined?(Object.print)) # private method -ok(defined?(1 == 2)) # operator expression +test_ok(defined?(Array)) # constant +test_ok(defined?(Object.new)) # method +test_ok(!defined?(Object.print)) # private method +test_ok(defined?(1 == 2)) # operator expression def defined_test return !defined?(yield) end -ok(defined_test) # not iterator -ok(!defined_test{}) # called as iterator +test_ok(defined_test) # not iterator +test_ok(!defined_test{}) # called as iterator -check "alias" +test_check "alias" class Alias0 def foo; "foo" end end @@ -1148,11 +1149,11 @@ class Alias2<Alias1 end x = Alias2.new -ok(x.bar == "foo") -ok(x.baz == "foo+foo") +test_ok(x.bar == "foo") +test_ok(x.baz == "foo+foo") -# check for cache -ok(x.baz == "foo+foo") +# test_check for cache +test_ok(x.baz == "foo+foo") class Alias3<Alias2 def foo @@ -1166,19 +1167,19 @@ class Alias3<Alias2 end end x = Alias3.new -ok(!x.foo) -ok(x.bar) -ok(!x.quux) +test_ok(!x.foo) +test_ok(x.bar) +test_ok(!x.quux) -check "gc" +test_check "gc" begin 1.upto(10000) { tmp = [0,1,2,3,4,5,6,7,8,9] } tmp = nil - ok true + test_ok true rescue - ok false + test_ok false end if $failed > 0 @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.5.4" -#define RUBY_RELEASE_DATE "2000-07-06" +#define RUBY_RELEASE_DATE "2000-07-10" #define RUBY_VERSION_CODE 154 -#define RUBY_RELEASE_CODE 20000706 +#define RUBY_RELEASE_CODE 20000710 |