From eb807d42eca121df22f72b95465bba52a4e7fefa Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 7 Mar 2011 08:39:39 +0000 Subject: * gc.c (rb_gc_set_params): allow GC parameter configuration by environment variables. based on a patch from funny-falcon at https://gist.github.com/856296, but honors safe level. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- .gitignore | 8 - ChangeLog | 7 +- NEWS | 6 +- bin/gem | 2 +- class.c | 10 +- eval_jump.c | 1 + ext/bigdecimal/bigdecimal.c | 8 +- ext/openssl/ossl_cipher.c | 2 +- ext/openssl/ossl_ns_spki.c | 8 +- ext/openssl/ossl_ocsp.c | 48 +-- ext/openssl/ossl_pkcs12.c | 12 +- ext/openssl/ossl_pkcs7.c | 38 +- ext/openssl/ossl_pkey.h | 16 +- ext/openssl/ossl_pkey_dh.c | 4 +- ext/openssl/ossl_pkey_dsa.c | 4 +- gc.c | 58 ++- golf_prelude.rb | 8 - include/ruby/intern.h | 1 + lib/date.rb | 363 ++++++++---------- lib/tempfile.rb | 6 +- marshal.c | 4 +- proc.c | 14 +- process.c | 80 ++-- ruby.c | 1 + strftime.c | 4 - string.c | 2 +- test/ruby/test_io.rb | 33 -- test/ruby/test_m17n.rb | 1 - test/ruby/test_process.rb | 18 +- test/ruby/test_string.rb | 32 -- test/ruby/test_system.rb | 30 +- test/rubygems/test_gem.rb | 422 ++------------------- test/rubygems/test_gem_builder.rb | 2 +- test/rubygems/test_gem_command_manager.rb | 4 +- test/rubygems/test_gem_commands_build_command.rb | 2 +- test/rubygems/test_gem_commands_cert_command.rb | 3 +- .../test_gem_commands_dependency_command.rb | 11 +- test/rubygems/test_gem_commands_fetch_command.rb | 8 +- test/rubygems/test_gem_commands_install_command.rb | 39 +- test/rubygems/test_gem_commands_lock_command.rb | 2 +- .../rubygems/test_gem_commands_outdated_command.rb | 7 +- .../rubygems/test_gem_commands_pristine_command.rb | 36 +- .../test_gem_commands_specification_command.rb | 16 +- test/rubygems/test_gem_commands_stale_command.rb | 6 +- .../test_gem_commands_uninstall_command.rb | 27 +- test/rubygems/test_gem_commands_unpack_command.rb | 18 +- test/rubygems/test_gem_commands_update_command.rb | 202 +--------- test/rubygems/test_gem_config_file.rb | 14 - test/rubygems/test_gem_dependency.rb | 39 -- test/rubygems/test_gem_dependency_installer.rb | 305 +++++---------- test/rubygems/test_gem_dependency_list.rb | 54 +-- test/rubygems/test_gem_doc_manager.rb | 9 +- test/rubygems/test_gem_format.rb | 4 +- test/rubygems/test_gem_indexer.rb | 19 +- test/rubygems/test_gem_install_update_options.rb | 2 + test/rubygems/test_gem_installer.rb | 229 ++++------- test/rubygems/test_gem_package_tar_output.rb | 3 - test/rubygems/test_gem_remote_fetcher.rb | 37 +- test/rubygems/test_gem_source_index.rb | 33 +- test/rubygems/test_gem_spec_fetcher.rb | 7 +- test/rubygems/test_gem_specification.rb | 118 ++---- test/rubygems/test_gem_uninstaller.rb | 80 +--- test/rubygems/test_gem_validator.rb | 2 +- test/rubygems/test_kernel.rb | 2 +- version.h | 7 +- vm_eval.c | 8 +- vm_method.c | 6 +- 67 files changed, 770 insertions(+), 1842 deletions(-) diff --git a/.gitignore b/.gitignore index c2e8cb5c08..1f76488f60 100644 --- a/.gitignore +++ b/.gitignore @@ -97,9 +97,6 @@ /ext/-test-/*/Makefile /ext/-test-/*/extconf.h /ext/-test-/*/mkmf.log -/ext/-test-/*/*/Makefile -/ext/-test-/*/*/extconf.h -/ext/-test-/*/*/mkmf.log # /ext/bigdecimal/ /ext/bigdecimal/*.def @@ -449,11 +446,6 @@ /ext/zlib/zlib.a /ext/zlib/conftest.dSYM -# /ext/date/ -/ext/date/Makefile -/ext/date/extconf.h -/ext/date/mkmf.log - # /lib/rexml/ # /spec/ diff --git a/ChangeLog b/ChangeLog index da102dc5d9..538181cc55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Mar 7 17:13:00 2011 Yukihiro Matsumoto + + * gc.c (rb_gc_set_params): allow GC parameter configuration by + environment variables. based on a patch from funny-falcon at + https://gist.github.com/856296, but honors safe level. + Mon Mar 7 09:05:18 2011 Nobuyoshi Nakada * process.c: NUM2RLIM is defined but no getrlimit and setrlimit on @@ -6567,7 +6573,6 @@ For the changes before 1.9.3, see doc/ChangeLog-1.9.3 For the changes before 1.8.0, see doc/ChangeLog-1.8.0 Local variables: -coding: us-ascii add-log-time-format: (lambda () (let* ((time (current-time)) (system-time-locale "C") diff --git a/NEWS b/NEWS index 266b660c46..8839403304 100644 --- a/NEWS +++ b/NEWS @@ -72,7 +72,6 @@ with all sufficient information, see the ChangeLog file. * String#unpack supports endian modifiers * new method: * String#prepend - * String#byteslice * Time * extended method: @@ -154,3 +153,8 @@ with all sufficient information, see the ChangeLog file. * Kernel#respond_to? See above. + +* REXML::Document#encoding, REXML::XMLDecl#encoding, + REXML::Output#encoding and REXML::Source#encoding + + Return an Encoding object not encoding name as a String. diff --git a/bin/gem b/bin/gem index a4ec754abb..14c3d3c480 100755 --- a/bin/gem +++ b/bin/gem @@ -9,7 +9,7 @@ require 'rubygems' require 'rubygems/gem_runner' require 'rubygems/exceptions' -required_version = Gem::Requirement.new ">= 1.8.7" +required_version = Gem::Requirement.new ">= 1.8.6" unless required_version.satisfied_by? Gem.ruby_version then abort "Expected Ruby Version #{required_version}, is #{Gem.ruby_version}" diff --git a/class.c b/class.c index 39e5e1447f..0d7623350f 100644 --- a/class.c +++ b/class.c @@ -988,14 +988,14 @@ rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod) * obj's ancestors. * * class Klass - * def klass_method() + * def kMethod() * end * end * k = Klass.new - * k.methods[0..9] #=> [:klass_method, :nil?, :===, - * # :==~, :!, :eql? - * # :hash, :<=>, :class, :singleton_class] - * k.methods.length #=> 57 + * k.methods[0..9] #=> [:kMethod, :freeze, :nil?, :is_a?, + * # :class, :instance_variable_set, + * # :methods, :extend, :__send__, :instance_eval] + * k.methods.length #=> 42 */ VALUE diff --git a/eval_jump.c b/eval_jump.c index a8f04808ca..8d552565ec 100644 --- a/eval_jump.c +++ b/eval_jump.c @@ -97,6 +97,7 @@ void rb_exec_end_proc(void) { struct end_proc_data *volatile link; + struct end_proc_data *tmp; int status; volatile int safe = rb_safe_level(); diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 83d090280d..53fb678d12 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -2237,11 +2237,11 @@ static int gnAlloc=0; /* Memory allocation counter */ VP_EXPORT void * VpMemAlloc(size_t mb) { - void *p = xmalloc(mb); - if (!p) { - VpException(VP_EXCEPTION_MEMORY, "failed to allocate memory", 1); + void *p = xmalloc((unsigned int)mb); + if(!p) { + VpException(VP_EXCEPTION_MEMORY,"failed to allocate memory",1); } - memset(p, 0, mb); + memset(p,0,mb); #ifdef BIGDECIMAL_DEBUG gnAlloc++; /* Count allocation call */ #endif /* BIGDECIMAL_DEBUG */ diff --git a/ext/openssl/ossl_cipher.c b/ext/openssl/ossl_cipher.c index 485626fe62..84b51a0101 100644 --- a/ext/openssl/ossl_cipher.c +++ b/ext/openssl/ossl_cipher.c @@ -202,7 +202,7 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode) * keeping this behaviour for backward compatibility. */ const char *cname = rb_class2name(rb_obj_class(self)); - rb_warn("arguments for %s#encrypt and %s#decrypt were deprecated; " + rb_warn("argumtents for %s#encrypt and %s#decrypt were deprecated; " "use %s#pkcs5_keyivgen to derive key and IV", cname, cname, cname); StringValue(pass); diff --git a/ext/openssl/ossl_ns_spki.c b/ext/openssl/ossl_ns_spki.c index fde8957206..b67dd225a1 100644 --- a/ext/openssl/ossl_ns_spki.c +++ b/ext/openssl/ossl_ns_spki.c @@ -11,14 +11,14 @@ #include "ossl.h" #define WrapSPKI(klass, obj, spki) do { \ - if (!(spki)) { \ + if (!spki) { \ ossl_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \ } \ - (obj) = Data_Wrap_Struct((klass), 0, NETSCAPE_SPKI_free, (spki)); \ + obj = Data_Wrap_Struct(klass, 0, NETSCAPE_SPKI_free, spki); \ } while (0) #define GetSPKI(obj, spki) do { \ - Data_Get_Struct((obj), NETSCAPE_SPKI, (spki)); \ - if (!(spki)) { \ + Data_Get_Struct(obj, NETSCAPE_SPKI, spki); \ + if (!spki) { \ ossl_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \ } \ } while (0) diff --git a/ext/openssl/ossl_ocsp.c b/ext/openssl/ossl_ocsp.c index dc4d4fb2af..fb01243261 100644 --- a/ext/openssl/ossl_ocsp.c +++ b/ext/openssl/ossl_ocsp.c @@ -14,55 +14,55 @@ #if defined(OSSL_OCSP_ENABLED) #define WrapOCSPReq(klass, obj, req) do { \ - if(!(req)) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \ - (obj) = Data_Wrap_Struct((klass), 0, OCSP_REQUEST_free, (req)); \ + if(!req) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \ + obj = Data_Wrap_Struct(klass, 0, OCSP_REQUEST_free, req); \ } while (0) #define GetOCSPReq(obj, req) do { \ - Data_Get_Struct((obj), OCSP_REQUEST, (req)); \ - if(!(req)) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \ + Data_Get_Struct(obj, OCSP_REQUEST, req); \ + if(!req) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \ } while (0) #define SafeGetOCSPReq(obj, req) do { \ - OSSL_Check_Kind((obj), cOCSPReq); \ - GetOCSPReq((obj), (req)); \ + OSSL_Check_Kind(obj, cOCSPReq); \ + GetOCSPReq(obj, req); \ } while (0) #define WrapOCSPRes(klass, obj, res) do { \ - if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ - (obj) = Data_Wrap_Struct((klass), 0, OCSP_RESPONSE_free, (res)); \ + if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ + obj = Data_Wrap_Struct(klass, 0, OCSP_RESPONSE_free, res); \ } while (0) #define GetOCSPRes(obj, res) do { \ - Data_Get_Struct((obj), OCSP_RESPONSE, (res)); \ - if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ + Data_Get_Struct(obj, OCSP_RESPONSE, res); \ + if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ } while (0) #define SafeGetOCSPRes(obj, res) do { \ - OSSL_Check_Kind((obj), cOCSPRes); \ - GetOCSPRes((obj), (res)); \ + OSSL_Check_Kind(obj, cOCSPRes); \ + GetOCSPRes(obj, res); \ } while (0) #define WrapOCSPBasicRes(klass, obj, res) do { \ - if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ - (obj) = Data_Wrap_Struct((klass), 0, OCSP_BASICRESP_free, (res)); \ + if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ + obj = Data_Wrap_Struct(klass, 0, OCSP_BASICRESP_free, res); \ } while (0) #define GetOCSPBasicRes(obj, res) do { \ - Data_Get_Struct((obj), OCSP_BASICRESP, (res)); \ - if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ + Data_Get_Struct(obj, OCSP_BASICRESP, res); \ + if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ } while (0) #define SafeGetOCSPBasicRes(obj, res) do { \ - OSSL_Check_Kind((obj), cOCSPBasicRes); \ - GetOCSPBasicRes((obj), (res)); \ + OSSL_Check_Kind(obj, cOCSPBasicRes); \ + GetOCSPBasicRes(obj, res); \ } while (0) #define WrapOCSPCertId(klass, obj, cid) do { \ - if(!(cid)) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \ - (obj) = Data_Wrap_Struct((klass), 0, OCSP_CERTID_free, (cid)); \ + if(!cid) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \ + obj = Data_Wrap_Struct(klass, 0, OCSP_CERTID_free, cid); \ } while (0) #define GetOCSPCertId(obj, cid) do { \ - Data_Get_Struct((obj), OCSP_CERTID, (cid)); \ - if(!(cid)) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \ + Data_Get_Struct(obj, OCSP_CERTID, cid); \ + if(!cid) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \ } while (0) #define SafeGetOCSPCertId(obj, cid) do { \ - OSSL_Check_Kind((obj), cOCSPCertId); \ - GetOCSPCertId((obj), (cid)); \ + OSSL_Check_Kind(obj, cOCSPCertId); \ + GetOCSPCertId(obj, cid); \ } while (0) VALUE mOCSP; diff --git a/ext/openssl/ossl_pkcs12.c b/ext/openssl/ossl_pkcs12.c index 3628374b4e..85e092b251 100644 --- a/ext/openssl/ossl_pkcs12.c +++ b/ext/openssl/ossl_pkcs12.c @@ -6,18 +6,18 @@ #include "ossl.h" #define WrapPKCS12(klass, obj, p12) do { \ - if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \ - (obj) = Data_Wrap_Struct((klass), 0, PKCS12_free, (p12)); \ + if(!p12) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \ + obj = Data_Wrap_Struct(klass, 0, PKCS12_free, p12); \ } while (0) #define GetPKCS12(obj, p12) do { \ - Data_Get_Struct((obj), PKCS12, (p12)); \ - if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \ + Data_Get_Struct(obj, PKCS12, p12); \ + if(!p12) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \ } while (0) #define SafeGetPKCS12(obj, p12) do { \ - OSSL_Check_Kind((obj), cPKCS12); \ - GetPKCS12((obj), (p12)); \ + OSSL_Check_Kind(obj, cPKCS12); \ + GetPKCS12(obj, p12); \ } while (0) #define ossl_pkcs12_set_key(o,v) rb_iv_set((o), "@key", (v)) diff --git a/ext/openssl/ossl_pkcs7.c b/ext/openssl/ossl_pkcs7.c index e25c8bc5c1..9842d4e941 100644 --- a/ext/openssl/ossl_pkcs7.c +++ b/ext/openssl/ossl_pkcs7.c @@ -11,57 +11,57 @@ #include "ossl.h" #define WrapPKCS7(klass, obj, pkcs7) do { \ - if (!(pkcs7)) { \ + if (!pkcs7) { \ ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \ } \ - (obj) = Data_Wrap_Struct((klass), 0, PKCS7_free, (pkcs7)); \ + obj = Data_Wrap_Struct(klass, 0, PKCS7_free, pkcs7); \ } while (0) #define GetPKCS7(obj, pkcs7) do { \ - Data_Get_Struct((obj), PKCS7, (pkcs7)); \ - if (!(pkcs7)) { \ + Data_Get_Struct(obj, PKCS7, pkcs7); \ + if (!pkcs7) { \ ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \ } \ } while (0) #define SafeGetPKCS7(obj, pkcs7) do { \ - OSSL_Check_Kind((obj), cPKCS7); \ - GetPKCS7((obj), (pkcs7)); \ + OSSL_Check_Kind(obj, cPKCS7); \ + GetPKCS7(obj, pkcs7); \ } while (0) #define WrapPKCS7si(klass, obj, p7si) do { \ - if (!(p7si)) { \ + if (!p7si) { \ ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \ } \ - (obj) = Data_Wrap_Struct((klass), 0, PKCS7_SIGNER_INFO_free, (p7si)); \ + obj = Data_Wrap_Struct(klass, 0, PKCS7_SIGNER_INFO_free, p7si); \ } while (0) #define GetPKCS7si(obj, p7si) do { \ - Data_Get_Struct((obj), PKCS7_SIGNER_INFO, (p7si)); \ - if (!(p7si)) { \ + Data_Get_Struct(obj, PKCS7_SIGNER_INFO, p7si); \ + if (!p7si) { \ ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \ } \ } while (0) #define SafeGetPKCS7si(obj, p7si) do { \ - OSSL_Check_Kind((obj), cPKCS7Signer); \ - GetPKCS7si((obj), (p7si)); \ + OSSL_Check_Kind(obj, cPKCS7Signer); \ + GetPKCS7si(obj, p7si); \ } while (0) #define WrapPKCS7ri(klass, obj, p7ri) do { \ - if (!(p7ri)) { \ + if (!p7ri) { \ ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \ } \ - (obj) = Data_Wrap_Struct((klass), 0, PKCS7_RECIP_INFO_free, (p7ri)); \ + obj = Data_Wrap_Struct(klass, 0, PKCS7_RECIP_INFO_free, p7ri); \ } while (0) #define GetPKCS7ri(obj, p7ri) do { \ - Data_Get_Struct((obj), PKCS7_RECIP_INFO, (p7ri)); \ - if (!(p7ri)) { \ + Data_Get_Struct(obj, PKCS7_RECIP_INFO, p7ri); \ + if (!p7ri) { \ ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \ } \ } while (0) #define SafeGetPKCS7ri(obj, p7ri) do { \ - OSSL_Check_Kind((obj), cPKCS7Recipient); \ - GetPKCS7ri((obj), (p7ri)); \ + OSSL_Check_Kind(obj, cPKCS7Recipient); \ + GetPKCS7ri(obj, p7ri); \ } while (0) -#define numberof(ary) (int)(sizeof(ary)/sizeof((ary)[0])) +#define numberof(ary) (int)(sizeof(ary)/sizeof(ary[0])) #define ossl_pkcs7_set_data(o,v) rb_iv_set((o), "@data", (v)) #define ossl_pkcs7_get_data(o) rb_iv_get((o), "@data") diff --git a/ext/openssl/ossl_pkey.h b/ext/openssl/ossl_pkey.h index 5e3329d326..67ff1fddd0 100644 --- a/ext/openssl/ossl_pkey.h +++ b/ext/openssl/ossl_pkey.h @@ -21,21 +21,21 @@ extern ID id_private_q; #define OSSL_PKEY_IS_PRIVATE(obj) (rb_iv_get((obj), "private") == Qtrue) #define WrapPKey(klass, obj, pkey) do { \ - if (!(pkey)) { \ + if (!pkey) { \ rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!"); \ } \ - (obj) = Data_Wrap_Struct((klass), 0, EVP_PKEY_free, (pkey)); \ + obj = Data_Wrap_Struct(klass, 0, EVP_PKEY_free, pkey); \ OSSL_PKEY_SET_PUBLIC(obj); \ } while (0) #define GetPKey(obj, pkey) do {\ - Data_Get_Struct((obj), EVP_PKEY, (pkey));\ - if (!(pkey)) { \ + Data_Get_Struct(obj, EVP_PKEY, pkey);\ + if (!pkey) { \ rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!");\ } \ } while (0) #define SafeGetPKey(obj, pkey) do { \ - OSSL_Check_Kind((obj), cPKey); \ - GetPKey((obj), (pkey)); \ + OSSL_Check_Kind(obj, cPKey); \ + GetPKey(obj, pkey); \ } while (0) void ossl_generate_cb(int, int, void *); @@ -134,8 +134,8 @@ static VALUE ossl_##keytype##_set_##name(VALUE self, VALUE bignum) \ #define DEF_OSSL_PKEY_BN(class, keytype, name) \ do { \ - rb_define_method((class), #name, ossl_##keytype##_get_##name, 0); \ - rb_define_method((class), #name "=", ossl_##keytype##_set_##name, 1);\ + rb_define_method(class, #name, ossl_##keytype##_get_##name, 0); \ + rb_define_method(class, #name "=", ossl_##keytype##_set_##name, 1);\ } while (0) #endif /* _OSSL_PKEY_H_ */ diff --git a/ext/openssl/ossl_pkey_dh.c b/ext/openssl/ossl_pkey_dh.c index 4311fa1e96..5ea575eaf9 100644 --- a/ext/openssl/ossl_pkey_dh.c +++ b/ext/openssl/ossl_pkey_dh.c @@ -13,8 +13,8 @@ #include "ossl.h" #define GetPKeyDH(obj, pkey) do { \ - GetPKey((obj), (pkey)); \ - if (EVP_PKEY_type((pkey)->type) != EVP_PKEY_DH) { /* PARANOIA? */ \ + GetPKey(obj, pkey); \ + if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DH) { /* PARANOIA? */ \ ossl_raise(rb_eRuntimeError, "THIS IS NOT A DH!") ; \ } \ } while (0) diff --git a/ext/openssl/ossl_pkey_dsa.c b/ext/openssl/ossl_pkey_dsa.c index 65550ca351..e66f4ed009 100644 --- a/ext/openssl/ossl_pkey_dsa.c +++ b/ext/openssl/ossl_pkey_dsa.c @@ -13,8 +13,8 @@ #include "ossl.h" #define GetPKeyDSA(obj, pkey) do { \ - GetPKey((obj), (pkey)); \ - if (EVP_PKEY_type((pkey)->type) != EVP_PKEY_DSA) { /* PARANOIA? */ \ + GetPKey(obj, pkey); \ + if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DSA) { /* PARANOIA? */ \ ossl_raise(rb_eRuntimeError, "THIS IS NOT A DSA!"); \ } \ } while (0) diff --git a/gc.c b/gc.c index 39979138bb..0675048126 100644 --- a/gc.c +++ b/gc.c @@ -78,6 +78,47 @@ void *alloca (); #ifndef GC_MALLOC_LIMIT #define GC_MALLOC_LIMIT 8000000 #endif +#define HEAP_MIN_SLOTS 10000 +#define FREE_MIN 4096 + +static unsigned int initial_malloc_limit = GC_MALLOC_LIMIT; +static unsigned int initial_heap_min_slots = HEAP_MIN_SLOTS; +static unsigned int initial_free_min = FREE_MIN; + +void +rb_gc_set_params(void) +{ + char *malloc_limit_ptr, *heap_min_slots_ptr, *free_min_ptr; + + if (rb_safe_level() > 0) return; + + malloc_limit_ptr = getenv("RUBY_GC_MALLOC_LIMIT"); + if (malloc_limit_ptr != NULL) { + int malloc_limit_i = atoi(malloc_limit_ptr); + printf("malloc_limit=%d (%d)\n", malloc_limit_i, initial_malloc_limit); + if (malloc_limit_i > 0) { + initial_malloc_limit = malloc_limit_i; + } + } + + heap_min_slots_ptr = getenv("RUBY_HEAP_MIN_SLOTS"); + if (heap_min_slots_ptr != NULL) { + int heap_min_slots_i = atoi(heap_min_slots_ptr); + printf("heap_min_slots=%d (%d)\n", heap_min_slots_i, initial_heap_min_slots); + if (heap_min_slots_i > 0) { + initial_heap_min_slots = heap_min_slots_i; + } + } + + free_min_ptr = getenv("RUBY_FREE_MIN"); + if (free_min_ptr != NULL) { + int free_min_i = atoi(free_min_ptr); + printf("free_min=%d (%d)\n", free_min_i, initial_free_min); + if (free_min_i > 0) { + initial_free_min = free_min_i; + } + } +} #define nomem_error GET_VM()->special_exceptions[ruby_error_nomemory] @@ -297,9 +338,6 @@ struct sorted_heaps_slot { struct heaps_slot *slot; }; -#define HEAP_MIN_SLOTS 10000 -#define FREE_MIN 4096 - struct gc_list { VALUE *varptr; struct gc_list *next; @@ -363,7 +401,7 @@ typedef struct rb_objspace { static int ruby_initial_gc_stress = 0; int *ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress; #else -static rb_objspace_t rb_objspace = {{GC_MALLOC_LIMIT}, {HEAP_MIN_SLOTS}}; +static rb_objspace_t rb_objspace = {{initial_malloc_limit}, {initial_heap_min_slots}}; int *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress; #endif #define malloc_limit objspace->malloc_params.limit @@ -394,7 +432,7 @@ rb_objspace_alloc(void) { rb_objspace_t *objspace = malloc(sizeof(rb_objspace_t)); memset(objspace, 0, sizeof(*objspace)); - malloc_limit = GC_MALLOC_LIMIT; + malloc_limit = initial_malloc_limit; ruby_gc_stress = ruby_initial_gc_stress; return objspace; @@ -998,7 +1036,7 @@ init_heap(rb_objspace_t *objspace) { size_t add, i; - add = HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT; + add = initial_heap_min_slots / HEAP_OBJ_LIMIT; if (!add) { add = 1; @@ -1986,9 +2024,9 @@ before_gc_sweep(rb_objspace_t *objspace) freelist = 0; objspace->heap.do_heap_free = (size_t)((heaps_used * HEAP_OBJ_LIMIT) * 0.65); objspace->heap.free_min = (size_t)((heaps_used * HEAP_OBJ_LIMIT) * 0.2); - if (objspace->heap.free_min < FREE_MIN) { + if (objspace->heap.free_min < initial_free_min) { objspace->heap.do_heap_free = heaps_used * HEAP_OBJ_LIMIT; - objspace->heap.free_min = FREE_MIN; + objspace->heap.free_min = initial_free_min; } objspace->heap.sweep_slots = heaps; objspace->heap.free_num = 0; @@ -2011,7 +2049,7 @@ after_gc_sweep(rb_objspace_t *objspace) if (malloc_increase > malloc_limit) { malloc_limit += (size_t)((malloc_increase - malloc_limit) * (double)objspace->heap.live_num / (heaps_used * HEAP_OBJ_LIMIT)); - if (malloc_limit < GC_MALLOC_LIMIT) malloc_limit = GC_MALLOC_LIMIT; + if (malloc_limit < initial_malloc_limit) malloc_limit = initial_malloc_limit; } malloc_increase = 0; @@ -2530,7 +2568,7 @@ objspace_each_objects(VALUE arg) while (i < heaps_used) { while (0 < i && (uintptr_t)membase < (uintptr_t)objspace->heap.sorted[i-1].slot->membase) i--; - while (i < heaps_used && (uintptr_t)objspace->heap.sorted[i].slot->membase <= (uintptr_t)membase ) + while (i < heaps_used && (uintptr_t)objspace->heap.sorted[i].slot->membase <= (uintptr_t)membase) i++; if (heaps_used <= i) break; diff --git a/golf_prelude.rb b/golf_prelude.rb index b090503213..4363b496f0 100644 --- a/golf_prelude.rb +++ b/golf_prelude.rb @@ -112,11 +112,3 @@ class Enumerator alias old_inspect inspect alias inspect old_to_s end - -class Symbol - def call(*args, &block) - proc do |recv| - recv.__send__(self, *args, &block) - end - end -end diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 472166d995..f330aa509a 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -424,6 +424,7 @@ VALUE rb_gc_enable(void); VALUE rb_gc_disable(void); VALUE rb_gc_start(void); #define Init_stack(addr) ruby_init_stack(addr) +void rb_gc_set_params(void); /* hash.c */ void st_foreach_safe(struct st_table *, int (*)(ANYARGS), st_data_t); VALUE rb_check_hash_type(VALUE); diff --git a/lib/date.rb b/lib/date.rb index 66fa67a579..079a6059bb 100644 --- a/lib/date.rb +++ b/lib/date.rb @@ -5,6 +5,10 @@ # # Documentation: William Webber # +#-- +# $Id: date.rb,v 2.37 2008-01-17 20:16:31+09 tadf Exp $ +#++ +# # == Overview # # This file provides two classes for working with @@ -276,15 +280,6 @@ class Date end end - def to_f - return 0 if @d == 0 - if @d > 0 - Float::INFINITY - else - -Float::INFINITY - end - end - end # The Julian Day Number of the Day of Calendar Reform for Italy @@ -448,14 +443,8 @@ class Date # [commercial_year, week_of_year, day_of_week] def jd_to_commercial(jd, sg=GREGORIAN) # :nodoc: a = jd_to_civil(jd - 3, sg)[0] - j = commercial_to_jd(a + 1, 1, 1, sg) - if jd >= j - y = a + 1 - else - j = commercial_to_jd(a, 1, 1, sg) - y = a - end - w = 1 + ((jd - j) / 7).floor + y = if jd >= commercial_to_jd(a + 1, 1, 1, sg) then a + 1 else a end + w = 1 + ((jd - commercial_to_jd(y, 1, 1, sg)) / 7).floor d = (jd + 1) % 7 d = 7 if d == 0 return y, w, d @@ -730,31 +719,26 @@ class Date def self.gregorian_leap? (y) y % 4 == 0 && y % 100 != 0 || y % 400 == 0 end class << self; alias_method :leap?, :gregorian_leap? end + class << self; alias_method :new!, :new end - def self.valid_jd_r? (jd, sg=ITALY) + def self.valid_jd? (jd, sg=ITALY) !!_valid_jd?(jd, sg) end - private_class_method :valid_jd_r? - - def self.valid_ordinal_r? (y, d, sg=ITALY) + def self.valid_ordinal? (y, d, sg=ITALY) !!_valid_ordinal?(y, d, sg) end - private_class_method :valid_ordinal_r? - - def self.valid_civil_r? (y, m, d, sg=ITALY) + def self.valid_civil? (y, m, d, sg=ITALY) !!_valid_civil?(y, m, d, sg) end - private_class_method :valid_civil_r? + class << self; alias_method :valid_date?, :valid_civil? end - def self.valid_commercial_r? (y, w, d, sg=ITALY) + def self.valid_commercial? (y, w, d, sg=ITALY) !!_valid_commercial?(y, w, d, sg) end - private_class_method :valid_commercial_r? - def self.valid_weeknum? (y, w, d, f, sg=ITALY) # :nodoc: !!_valid_weeknum?(y, w, d, f, sg) end @@ -773,28 +757,16 @@ class Date private_class_method :valid_time? - def self.new!(ajd=0, of=0, sg=ITALY) - jd, df = ajd_to_jd(ajd, 0) - if !(Fixnum === jd) || - jd < sg || df !=0 || of != 0 || - jd < -327 || jd > 366963925 - return new_r!(ajd, of, sg) - end - new_l!(jd, sg) - end - # Create a new Date object from a Julian Day Number. # # +jd+ is the Julian Day Number; if not specified, it defaults to # 0. # +sg+ specifies the Day of Calendar Reform. - def self.jd_r(jd=0, sg=ITALY) # :nodoc: + def self.jd(jd=0, sg=ITALY) jd = _valid_jd?(jd, sg) - new_r!(jd_to_ajd(jd, 0, 0), 0, sg) + new!(jd_to_ajd(jd, 0, 0), 0, sg) end - private_class_method :jd_r - # Create a new Date object from an Ordinal Date, specified # by year +y+ and day-of-year +d+. +d+ can be negative, # in which it counts backwards from the end of the year. @@ -805,15 +777,13 @@ class Date # Number day 0. # # +sg+ specifies the Day of Calendar Reform. - def self.ordinal_r(y=-4712, d=1, sg=ITALY) # :nodoc: + def self.ordinal(y=-4712, d=1, sg=ITALY) unless jd = _valid_ordinal?(y, d, sg) raise ArgumentError, 'invalid date' end - new_r!(jd_to_ajd(jd, 0, 0), 0, sg) + new!(jd_to_ajd(jd, 0, 0), 0, sg) end - private_class_method :ordinal_r - # Create a new Date object for the Civil Date specified by # year +y+, month +m+, and day-of-month +d+. # @@ -827,14 +797,14 @@ class Date # Julian Day Number day 0. # # +sg+ specifies the Day of Calendar Reform. - def self.civil_r(y=-4712, m=1, d=1, sg=ITALY) # :nodoc: + def self.civil(y=-4712, m=1, d=1, sg=ITALY) unless jd = _valid_civil?(y, m, d, sg) raise ArgumentError, 'invalid date' end - new_r!(jd_to_ajd(jd, 0, 0), 0, sg) + new!(jd_to_ajd(jd, 0, 0), 0, sg) end - private_class_method :civil_r + class << self; alias_method :new, :civil end # Create a new Date object for the Commercial Date specified by # year +y+, week-of-year +w+, and day-of-week +d+. @@ -850,15 +820,13 @@ class Date # Julian Day Number day 0. # # +sg+ specifies the Day of Calendar Reform. - def self.commercial_r(y=-4712, w=1, d=1, sg=ITALY) # :nodoc: + def self.commercial(y=-4712, w=1, d=1, sg=ITALY) unless jd = _valid_commercial?(y, w, d, sg) raise ArgumentError, 'invalid date' end - new_r!(jd_to_ajd(jd, 0, 0), 0, sg) + new!(jd_to_ajd(jd, 0, 0), 0, sg) end - private_class_method :commercial_r - def self.weeknum(y=-4712, w=0, d=1, f=0, sg=ITALY) unless jd = _valid_weeknum?(y, w, d, f, sg) raise ArgumentError, 'invalid date' @@ -1131,7 +1099,7 @@ class Date alias_method :__#{id.object_id}__, :#{id.to_s} private :__#{id.object_id}__ def #{id.to_s}(*args) - __ca__[#{id.object_id}] ||= __#{id.object_id}__(*args) + @__ca__[#{id.object_id}] ||= __#{id.object_id}__(*args) end end; end @@ -1141,69 +1109,96 @@ class Date end + # *NOTE* this is the documentation for the method new!(). If + # you are reading this as the documentation for new(), that is + # because rdoc doesn't fully support the aliasing of the + # initialize() method. + # new() is in + # fact an alias for #civil(): read the documentation for that + # method instead. + # + # Create a new Date object. + # + # +ajd+ is the Astronomical Julian Day Number. + # +of+ is the offset from UTC as a fraction of a day. + # Both default to 0. + # + # +sg+ specifies the Day of Calendar Reform to use for this + # Date object. + # + # Using one of the factory methods such as Date::civil is + # generally easier and safer. + def initialize(ajd=0, of=0, sg=ITALY) + @ajd, @of, @sg = ajd, of, sg + @__ca__ = {} + end + + # Get the date as an Astronomical Julian Day Number. + def ajd() @ajd end + # Get the date as an Astronomical Modified Julian Day Number. - def amjd_r() ajd_to_amjd(ajd) end + def amjd() ajd_to_amjd(@ajd) end - once :amjd_r + once :amjd - def daynum() ajd_to_jd(ajd, offset) end + def daynum() ajd_to_jd(@ajd, @of) end once :daynum private :daynum # Get the date as a Julian Day Number. - def jd_r() daynum[0] end # :nodoc: + def jd() daynum[0] end # Get any fractional day part of the date. - def day_fraction_r() daynum[1] end # :nodoc: + def day_fraction() daynum[1] end # Get the date as a Modified Julian Day Number. - def mjd_r() jd_to_mjd(jd) end # :nodoc: + def mjd() jd_to_mjd(jd) end # Get the date as the number of days since the Day of Calendar # Reform (in Italy and the Catholic countries). - def ld_r() jd_to_ld(jd) end # :nodoc: + def ld() jd_to_ld(jd) end - once :jd_r, :day_fraction_r, :mjd_r, :ld_r - private :jd_r, :day_fraction_r, :mjd_r, :ld_r + once :jd, :day_fraction, :mjd, :ld # Get the date as a Civil Date, [year, month, day_of_month] - def civil() jd_to_civil(jd, start) end # :nodoc: + def civil() jd_to_civil(jd, @sg) end # :nodoc: # Get the date as an Ordinal Date, [year, day_of_year] - def ordinal() jd_to_ordinal(jd, start) end # :nodoc: + def ordinal() jd_to_ordinal(jd, @sg) end # :nodoc: # Get the date as a Commercial Date, [year, week_of_year, day_of_week] - def commercial() jd_to_commercial(jd, start) end # :nodoc: + def commercial() jd_to_commercial(jd, @sg) end # :nodoc: - def weeknum0() jd_to_weeknum(jd, 0, start) end # :nodoc: - def weeknum1() jd_to_weeknum(jd, 1, start) end # :nodoc: + def weeknum0() jd_to_weeknum(jd, 0, @sg) end # :nodoc: + def weeknum1() jd_to_weeknum(jd, 1, @sg) end # :nodoc: once :civil, :ordinal, :commercial, :weeknum0, :weeknum1 private :civil, :ordinal, :commercial, :weeknum0, :weeknum1 # Get the year of this date. - def year_r() civil[0] end # :nodoc: + def year() civil[0] end # Get the day-of-the-year of this date. # # January 1 is day-of-the-year 1 - def yday_r() ordinal[1] end # :nodoc: + def yday() ordinal[1] end # Get the month of this date. # # January is month 1. - def mon_r() civil[1] end # :nodoc: + def mon() civil[1] end # Get the day-of-the-month of this date. - def mday_r() civil[2] end # :nodoc: + def mday() civil[2] end - private :year_r, :yday_r, :mon_r, :mday_r + alias_method :month, :mon + alias_method :day, :mday - def wnum0_r() weeknum0[1] end # :nodoc: - def wnum1_r() weeknum1[1] end # :nodoc: + def wnum0() weeknum0[1] end # :nodoc: + def wnum1() weeknum1[1] end # :nodoc: - private :wnum0_r, :wnum1_r + private :wnum0, :wnum1 # Get the time of this date as [hours, minutes, seconds, # fraction_of_a_second] @@ -1215,20 +1210,25 @@ class Date private :time, :time_wo_sf, :time_sf # Get the hour of this date. - def hour_r() time_wo_sf[0] end # :nodoc: # 4p + def hour() time_wo_sf[0] end # 4p # Get the minute of this date. - def min_r() time_wo_sf[1] end # :nodoc: # 4p + def min() time_wo_sf[1] end # 4p # Get the second of this date. - def sec_r() time_wo_sf[2] end # :nodoc: # 4p + def sec() time_wo_sf[2] end # 4p # Get the fraction-of-a-second of this date. - def sec_fraction_r() time_sf end # 4p + def sec_fraction() time_sf end # 4p + + alias_method :minute, :min + alias_method :second, :sec + alias_method :second_fraction, :sec_fraction - private :hour_r, :min_r, :sec_r, :sec_fraction_r + private :hour, :min, :sec, :sec_fraction, + :minute, :second, :second_fraction - def zone_r # :nodoc: # 4p - strftime('%:z') + def zone # 4p - strftime('%:z') sign = if offset < 0 then '-' else '+' end fr = offset.abs ss = fr.div(SECONDS_IN_DAY) @@ -1237,27 +1237,24 @@ class Date format('%s%02d:%02d', sign, hh, mm) end - private :zone_r + private :zone # Get the commercial year of this date. See *Commercial* *Date* # in the introduction for how this differs from the normal year. - def cwyear_r() commercial[0] end # :nodoc: + def cwyear() commercial[0] end # Get the commercial week of the year of this date. - def cweek_r() commercial[1] end # :nodoc: + def cweek() commercial[1] end # Get the commercial day of the week of this date. Monday is # commercial day-of-week 1; Sunday is commercial day-of-week 7. - def cwday_r() commercial[2] end # :nodoc: - - private :cwyear_r, :cweek_r, :cwday_r + def cwday() commercial[2] end # Get the week day of this date. Sunday is day-of-week 0; # Saturday is day-of-week 6. - def wday_r() jd_to_wday(jd) end # :nodoc: + def wday() jd_to_wday(jd) end - once :wday_r - private :wday_r + once :wday =begin MONTHNAMES.each_with_index do |n, i| @@ -1271,20 +1268,19 @@ class Date define_method(n.downcase + '?'){wday == i} end - def nth_kday? (n, k) # :nodoc: + def nth_kday? (n, k) k == wday && jd === nth_kday_to_jd(year, mon, n, k, start) end private :nth_kday? # Is the current date old-style (Julian Calendar)? - def julian_r? () jd < start end # :nodoc: + def julian? () jd < @sg end # Is the current date new-style (Gregorian Calendar)? - def gregorian_r? () !julian? end # :nodoc: + def gregorian? () !julian? end - once :julian_r?, :gregorian_r? - private :julian_r?, :gregorian_r? + once :julian?, :gregorian? def fix_style # :nodoc: if julian? @@ -1295,21 +1291,18 @@ class Date private :fix_style # Is this a leap year? - def leap_r? # :nodoc: + def leap? jd_to_civil(civil_to_jd(year, 3, 1, fix_style) - 1, fix_style)[-1] == 29 end - once :leap_r? - private :leap_r? + once :leap? # When is the Day of Calendar Reform for this Date object? - def start_r() @sg end # :nodoc: + def start() @sg end # Create a copy of this Date object using a new Day of Calendar Reform. - def new_start_r(sg=self.class::ITALY) self.class.new_r!(ajd, offset, sg) end # :nodoc: - - private :start_r, :new_start_r + def new_start(sg=self.class::ITALY) self.class.new!(@ajd, @of, sg) end # Create a copy of this Date object that uses the Italian/Catholic # Day of Calendar Reform. @@ -1327,16 +1320,16 @@ class Date # Calendar. def gregorian() new_start(self.class::GREGORIAN) end - def new_offset_r(of=0) # :nodoc: + def offset() @of end + + def new_offset(of=0) if String === of of = Rational(zone_to_diff(of) || 0, 86400) - elsif Float === of - of = Rational((of * 86400).round, 86400) end - self.class.new_r!(ajd, of, start) + self.class.new!(@ajd, of, @sg) end - private :new_offset_r + private :offset, :new_offset # Return a new Date object that is +n+ days later than the # current one. @@ -1347,19 +1340,13 @@ class Date # # If +n+ is not a Numeric, a TypeError will be thrown. In # particular, two Dates cannot be added to each other. - def plus_r (n) # :nodoc: + def + (n) case n - when Numeric - if Float === n - n = Rational((n * 86400000000000).round, 86400000000000) - end - return self.class.new_r!(ajd + n, offset, start) + when Numeric; return self.class.new!(@ajd + n, @of, @sg) end raise TypeError, 'expected numeric' end - private :plus_r - # If +x+ is a Numeric value, create a new Date object that is # +x+ days earlier than the current one. # @@ -1368,21 +1355,14 @@ class Date # date is than +x+. # # If +x+ is neither Numeric nor a Date, a TypeError is raised. - def minus_r (x) # :nodoc: + def - (x) case x - when Numeric - if Float === x - x = Rational((x * 86400000000000).round, 86400000000000) - end - return self.class.new_r!(ajd - x, offset, start) - when Date - return ajd - x.ajd + when Numeric; return self.class.new!(@ajd - x, @of, @sg) + when Date; return @ajd - x.ajd end raise TypeError, 'expected numeric or date' end - private :minus_r - # Compare this date with another date. # # +other+ can also be a Numeric value, in which case it is @@ -1394,10 +1374,10 @@ class Date # two DateTime instances. When comparing a DateTime instance # with a Date instance, the time of the latter will be # considered as falling on midnight UTC. - def cmp_r (other) # :nodoc: + def <=> (other) case other - when Numeric; return ajd <=> other - when Date; return ajd <=> other.ajd + when Numeric; return @ajd <=> other + when Date; return @ajd <=> other.ajd else begin l, r = other.coerce(self) @@ -1408,15 +1388,13 @@ class Date nil end - private :cmp_r - # The relationship operator for Date. # # Compares dates by Julian Day Number. When comparing # two DateTime instances, or a DateTime with a Date, # the instances will be regarded as equivalent if they # fall on the same date in local time. - def equal_r (other) # :nodoc: + def === (other) case other when Numeric; return jd == other when Date; return jd == other.jd @@ -1430,8 +1408,6 @@ class Date false end - private :equal_r - def next_day(n=1) self + n end def prev_day(n=1) self - n end @@ -1450,7 +1426,7 @@ class Date y, m = (year * 12 + (mon - 1) + n).divmod(12) m, = (m + 1) .divmod(1) d = mday - until jd2 = _valid_civil?(y, m, d, start) + until jd2 = _valid_civil?(y, m, d, @sg) d -= 1 raise ArgumentError, 'invalid date' unless d > 0 end @@ -1510,28 +1486,29 @@ class Date # Is this Date equal to +other+? # # +other+ must both be a Date object, and represent the same date. - def eql_r? (other) Date === other && self == other end # :nodoc: - - private :eql_r? + def eql? (other) Date === other && self == other end # Calculate a hash value for this date. - def hash_r() ajd.hash end # :nodoc: - - private :hash_r + def hash() @ajd.hash end # Return internal object state as a programmer-readable string. - def inspect_r # :nodoc: - format('#<%s[R]: %s (%s,%s,%s)>', self.class, to_s_r, ajd, offset, start) + def inspect + format('#<%s: %s (%s,%s,%s)>', self.class, to_s, @ajd, @of, @sg) end - private :inspect_r - # Return the date as a human-readable string. # # The format used is YYYY-MM-DD. - def to_s_r() format('%.4d-%02d-%02d', year, mon, mday) end # :nodoc: # 4p + def to_s() format('%.4d-%02d-%02d', year, mon, mday) end # 4p + + # Dump to Marshal format. + def marshal_dump() [@ajd, @of, @sg] end - private :to_s_r + # Load from Marshal format. + def marshal_load(a) + @ajd, @of, @sg, = a + @__ca__ = {} + end end @@ -1585,19 +1562,6 @@ end # class DateTime < Date - def self.new!(ajd=0, of=0, sg=ITALY) - jd, df = ajd_to_jd(ajd, 0) - df, sf = (df * 86400).divmod(1) - sf, ssf = (sf * 1000000000).divmod(1) - odf, osf = (of * 86400).divmod(1) - if !(Fixnum === jd) || - jd < sg || ssf != 0 || osf != 0 || - jd < -327 || jd > 366963925 - return new_r!(ajd, of, sg) - end - new_l!(jd, df, sf, odf, sg) - end - # Create a new DateTime object corresponding to the specified # Julian Day Number +jd+ and hour +h+, minute +min+, second +s+. # @@ -1611,21 +1575,17 @@ class DateTime < Date # +sg+ specifies the Day of Calendar Reform. # # All day/time values default to 0. - def self.jd_r(jd=0, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc: + def self.jd(jd=0, h=0, min=0, s=0, of=0, sg=ITALY) unless (jd = _valid_jd?(jd, sg)) && (fr = _valid_time?(h, min, s)) raise ArgumentError, 'invalid date' end if String === of of = Rational(zone_to_diff(of) || 0, 86400) - elsif Float === of - of = Rational((of * 86400).round, 86400) end - new_r!(jd_to_ajd(jd, fr, of), of, sg) + new!(jd_to_ajd(jd, fr, of), of, sg) end - private_class_method :jd_r - # Create a new DateTime object corresponding to the specified # Ordinal Date and hour +h+, minute +min+, second +s+. # @@ -1640,21 +1600,17 @@ class DateTime < Date # # +y+ defaults to -4712, and +d+ to 1; this is Julian Day Number # day 0. The time values default to 0. - def self.ordinal_r(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc: + def self.ordinal(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY) unless (jd = _valid_ordinal?(y, d, sg)) && (fr = _valid_time?(h, min, s)) raise ArgumentError, 'invalid date' end if String === of of = Rational(zone_to_diff(of) || 0, 86400) - elsif Float === of - of = Rational((of * 86400).round, 86400) end - new_r!(jd_to_ajd(jd, fr, of), of, sg) + new!(jd_to_ajd(jd, fr, of), of, sg) end - private_class_method :ordinal_r - # Create a new DateTime object corresponding to the specified # Civil Date and hour +h+, minute +min+, second +s+. # @@ -1669,20 +1625,18 @@ class DateTime < Date # # +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is Julian Day # Number day 0. The time values default to 0. - def self.civil_r(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc: + def self.civil(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY) unless (jd = _valid_civil?(y, m, d, sg)) && (fr = _valid_time?(h, min, s)) raise ArgumentError, 'invalid date' end if String === of of = Rational(zone_to_diff(of) || 0, 86400) - elsif Float === of - of = Rational((of * 86400).round, 86400) end - new_r!(jd_to_ajd(jd, fr, of), of, sg) + new!(jd_to_ajd(jd, fr, of), of, sg) end - private_class_method :civil_r + class << self; alias_method :new, :civil end # Create a new DateTime object corresponding to the specified # Commercial Date and hour +h+, minute +min+, second +s+. @@ -1699,21 +1653,17 @@ class DateTime < Date # +y+ defaults to -4712, +w+ to 1, and +d+ to 1; this is # Julian Day Number day 0. # The time values default to 0. - def self.commercial_r(y=-4712, w=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc: + def self.commercial(y=-4712, w=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY) unless (jd = _valid_commercial?(y, w, d, sg)) && (fr = _valid_time?(h, min, s)) raise ArgumentError, 'invalid date' end if String === of of = Rational(zone_to_diff(of) || 0, 86400) - elsif Float === of - of = Rational((of * 86400).round, 86400) end - new_r!(jd_to_ajd(jd, fr, of), of, sg) + new!(jd_to_ajd(jd, fr, of), of, sg) end - private_class_method :commercial_r - def self.weeknum(y=-4712, w=0, d=1, f=0, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc: unless (jd = _valid_weeknum?(y, w, d, f, sg)) && (fr = _valid_time?(h, min, s)) @@ -1721,8 +1671,6 @@ class DateTime < Date end if String === of of = Rational(zone_to_diff(of) || 0, 86400) - elsif Float === of - of = Rational((of * 86400).round, 86400) end new!(jd_to_ajd(jd, fr, of), of, sg) end @@ -1736,8 +1684,6 @@ class DateTime < Date end if String === of of = Rational(zone_to_diff(of) || 0, 86400) - elsif Float === of - of = Rational((of * 86400).round, 86400) end new!(jd_to_ajd(jd, fr, of), of, sg) end @@ -1824,13 +1770,14 @@ class DateTime < Date new_by_frags(elem, sg) end - def to_s_r # :nodoc: # 4p + public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset, + :minute, :second, :second_fraction + + def to_s # 4p format('%.4d-%02d-%02dT%02d:%02d:%02d%s', year, mon, mday, hour, min, sec, zone) end - private :to_s_r - end class Time @@ -1848,7 +1795,7 @@ class Time Rational(subsec, 86400) of = Rational(utc_offset, 86400) DateTime.new!(DateTime.__send__(:jd_to_ajd, jd, fr, of), - of, DateTime::ITALY) + of, DateTime::ITALY) end end @@ -1857,7 +1804,30 @@ class Date def to_time() Time.local(year, mon, mday) end def to_date() self end - def to_datetime() DateTime.new!(jd_to_ajd(jd, 0, 0), offset, start) end + def to_datetime() DateTime.new!(jd_to_ajd(jd, 0, 0), @of, @sg) end + + # Create a new Date object representing today. + # + # +sg+ specifies the Day of Calendar Reform. + def self.today(sg=ITALY) + t = Time.now + jd = civil_to_jd(t.year, t.mon, t.mday, sg) + new!(jd_to_ajd(jd, 0, 0), 0, sg) + end + + # Create a new DateTime object representing the current time. + # + # +sg+ specifies the Day of Calendar Reform. + def self.now(sg=ITALY) + t = Time.now + jd = civil_to_jd(t.year, t.mon, t.mday, sg) + fr = time_to_day_fraction(t.hour, t.min, [t.sec, 59].min) + + Rational(t.subsec, 86400) + of = Rational(t.utc_offset, 86400) + new!(jd_to_ajd(jd, fr, of), of, sg) + end + + private_class_method :now end @@ -1869,12 +1839,13 @@ class DateTime < Date Time.utc(year, mon, mday, hour, min, sec + sec_fraction) end. - getlocal + getlocal end - def to_date() Date.new!(jd_to_ajd(jd, 0, 0), 0, start) end + def to_date() Date.new!(jd_to_ajd(jd, 0, 0), 0, @sg) end def to_datetime() self end -end + private_class_method :today + public_class_method :now -require 'date_core' +end diff --git a/lib/tempfile.rb b/lib/tempfile.rb index 8bdf086b33..54f00de2b0 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -96,11 +96,11 @@ class Tempfile < DelegateClass(File) # element, and end with the second element. For example: # # file = Tempfile.new('hello') - # file.path # => something like: "/tmp/hello2843-8392-92849382--0" + # file.path # => something like: "/tmp/foo2843-8392-92849382--0" # # # Use the Array form to enforce an extension in the filename: # file = Tempfile.new(['hello', '.jpg']) - # file.path # => something like: "/tmp/hello2843-8392-92849382--0.jpg" + # file.path # => something like: "/tmp/foo2843-8392-92849382--0.jpg" # # The temporary file will be placed in the directory as specified # by the +tmpdir+ parameter. By default, this is +Dir.tmpdir+. @@ -110,7 +110,7 @@ class Tempfile < DelegateClass(File) # come from environment variables (e.g. $TMPDIR). # # file = Tempfile.new('hello', '/home/aisaka') - # file.path # => something like: "/home/aisaka/hello2843-8392-92849382--0" + # file.path # => something like: "/home/aisaka/foo2843-8392-92849382--0" # # You can also pass an options hash. Under the hood, Tempfile creates # the temporary file using +File.open+. These options will be passed to diff --git a/marshal.c b/marshal.c index 03537395c8..808aa0f9af 100644 --- a/marshal.c +++ b/marshal.c @@ -876,7 +876,7 @@ clear_dump_arg(struct dump_arg *arg) * def initialize(str) * @str = str * end - * def say_hello + * def sayHello * @str * end * end @@ -886,7 +886,7 @@ clear_dump_arg(struct dump_arg *arg) * o = Klass.new("hello\n") * data = Marshal.dump(o) * obj = Marshal.load(data) - * obj.say_hello #=> "hello\n" + * obj.sayHello #=> "hello\n" * * Marshal can't dump following objects: * * anonymous Class/Module. diff --git a/proc.c b/proc.c index f81118ae61..18c7393536 100644 --- a/proc.c +++ b/proc.c @@ -336,10 +336,10 @@ rb_binding_new(void) * calling +eval+ to execute the evaluated command in this * environment. Also see the description of class +Binding+. * - * def get_binding(param) + * def getBinding(param) * return binding * end - * b = get_binding("hello") + * b = getBinding("hello") * eval("param", b) #=> "hello" */ @@ -358,10 +358,10 @@ rb_f_binding(VALUE self) * lineno parameters are present, they will be used when * reporting syntax errors. * - * def get_binding(param) + * def getBinding(param) * return binding * end - * b = get_binding("hello") + * b = getBinding("hello") * b.eval("param") #=> "hello" */ @@ -2211,15 +2211,15 @@ Init_Proc(void) * def initialize(n) * @secret = n * end - * def get_binding + * def getBinding * return binding() * end * end * * k1 = Demo.new(99) - * b1 = k1.get_binding + * b1 = k1.getBinding * k2 = Demo.new(-3) - * b2 = k2.get_binding + * b2 = k2.getBinding * * eval("@secret", b1) #=> 99 * eval("@secret", b2) #=> -3 diff --git a/process.c b/process.c index 8711ab7c90..7ca3dfe063 100644 --- a/process.c +++ b/process.c @@ -122,6 +122,17 @@ static VALUE rb_cProcessTms; #endif #endif +#if SIZEOF_RLIM_T == SIZEOF_INT +# define RLIM2NUM(v) UINT2NUM(v) +# define NUM2RLIM(v) NUM2UINT(v) +#elif SIZEOF_RLIM_T == SIZEOF_LONG +# define RLIM2NUM(v) ULONG2NUM(v) +# define NUM2RLIM(v) NUM2ULONG(v) +#elif SIZEOF_RLIM_T == SIZEOF_LONG_LONG +# define RLIM2NUM(v) ULL2NUM(v) +# define NUM2RLIM(v) NUM2ULL(v) +#endif + #define preserving_errno(stmts) \ do {int saved_errno = errno; stmts; errno = saved_errno;} while (0) @@ -1283,7 +1294,7 @@ enum { }; static VALUE -check_exec_redirect_fd(VALUE v, int iskey) +check_exec_redirect_fd(VALUE v) { VALUE tmp; int fd; @@ -1315,11 +1326,6 @@ check_exec_redirect_fd(VALUE v, int iskey) wrong: rb_raise(rb_eArgError, "negative file descriptor"); } -#ifdef _WIN32 - else if (fd >= 3 && iskey) { - rb_raise(rb_eArgError, "wrong file descriptor (%d)", fd); - } -#endif return INT2FIX(fd); } @@ -1357,7 +1363,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options) break; case T_FILE: - val = check_exec_redirect_fd(val, 0); + val = check_exec_redirect_fd(val); /* fall through */ case T_FIXNUM: index = EXEC_OPTION_DUP2; @@ -1369,7 +1375,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options) if (RARRAY_LEN(val) == 2 && SYMBOL_P(path) && SYM2ID(path) == rb_intern("child")) { index = EXEC_OPTION_DUP2_CHILD; - param = check_exec_redirect_fd(rb_ary_entry(val, 1), 0); + param = check_exec_redirect_fd(rb_ary_entry(val, 1)); } else { index = EXEC_OPTION_OPEN; @@ -1393,7 +1399,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options) path = val; FilePathValue(path); if (TYPE(key) == T_FILE) - key = check_exec_redirect_fd(key, 1); + key = check_exec_redirect_fd(key); if (FIXNUM_P(key) && (FIX2INT(key) == 1 || FIX2INT(key) == 2)) flags = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC); else @@ -1413,21 +1419,21 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options) rb_ary_store(options, index, ary); } if (TYPE(key) != T_ARRAY) { - VALUE fd = check_exec_redirect_fd(key, !NIL_P(param)); + VALUE fd = check_exec_redirect_fd(key); rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param))); } else { int i, n=0; for (i = 0 ; i < RARRAY_LEN(key); i++) { VALUE v = RARRAY_PTR(key)[i]; - VALUE fd = check_exec_redirect_fd(v, !NIL_P(param)); + VALUE fd = check_exec_redirect_fd(v); rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param))); n++; } } } -#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM) +#ifdef RLIM2NUM static int rlimit_type_by_lname(const char *name); #endif @@ -1465,7 +1471,7 @@ rb_exec_arg_addopt(struct rb_exec_arg *e, VALUE key, VALUE val) } else #endif -#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM) +#ifdef RLIM2NUM if (strncmp("rlimit_", rb_id2name(id), 7) == 0 && (rtype = rlimit_type_by_lname(rb_id2name(id)+7)) != -1) { VALUE ary = rb_ary_entry(options, EXEC_OPTION_RLIMIT); @@ -2222,7 +2228,7 @@ run_exec_pgroup(VALUE obj, VALUE save, char *errmsg, size_t errmsg_buflen) } #endif -#if defined(HAVE_SETRLIMIT) && defined(RLIM2NUM) +#ifdef RLIM2NUM static int run_exec_rlimit(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen) { @@ -2284,7 +2290,7 @@ rb_run_exec_options_err(const struct rb_exec_arg *e, struct rb_exec_arg *s, char } #endif -#if defined(HAVE_SETRLIMIT) && defined(RLIM2NUM) +#ifdef RLIM2NUM obj = rb_ary_entry(options, EXEC_OPTION_RLIMIT); if (!NIL_P(obj)) { if (run_exec_rlimit(obj, soptions, errmsg, errmsg_buflen) == -1) @@ -3626,7 +3632,7 @@ proc_setpriority(VALUE obj, VALUE which, VALUE who, VALUE prio) #define proc_setpriority rb_f_notimplement #endif -#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM) +#if defined(RLIM2NUM) static int rlimit_resource_name2int(const char *name, int casetype) { @@ -4520,28 +4526,7 @@ proc_setgid(VALUE obj, VALUE id) #endif -/* - * Maximum supplementary groups are platform dependent. - * FWIW, 65536 is enough big for our supported OSs. - * - * OS Name max groups - * ----------------------------------------------- - * Linux Kernel >= 2.6.3 65536 - * Linux Kernel < 2.6.3 32 - * IBM AIX 5.2 64 - * IBM AIX 5.3 ... 6.1 128 - * IBM AIX 7.1 128 (can be configured to be up to 2048) - * OpenBSD, NetBSD 16 - * FreeBSD < 8.0 16 - * FreeBSD >=8.0 1023 - * Darwin (Mac OS X) 16 - * Sun Solaris 7,8,9,10 16 - * Sun Solaris 11 / OpenSolaris 1024 - * HP-UX 20 - * Windows 1015 - */ -#define RB_MAX_GROUPS (65536) -static int maxgroups = RB_MAX_GROUPS; +static int maxgroups = 32; #ifdef HAVE_GETGROUPS @@ -4563,13 +4548,9 @@ proc_getgroups(VALUE obj) int i, ngroups; rb_gid_t *groups; - ngroups = getgroups(0, NULL); - if (ngroups == -1) - rb_sys_fail(0); - - groups = ALLOCA_N(rb_gid_t, ngroups); + groups = ALLOCA_N(rb_gid_t, maxgroups); - ngroups = getgroups(ngroups, groups); + ngroups = getgroups(maxgroups, groups); if (ngroups == -1) rb_sys_fail(0); @@ -4706,13 +4687,10 @@ proc_getmaxgroups(VALUE obj) static VALUE proc_setmaxgroups(VALUE obj, VALUE val) { - int ngroups = FIX2INT(val); + int ngroups = FIX2UINT(val); - if (ngroups <= 0) - rb_raise(rb_eArgError, "maxgroups %d shold be positive", ngroups); - - if (ngroups > RB_MAX_GROUPS) - ngroups = RB_MAX_GROUPS; + if (ngroups > 4096) + ngroups = 4096; maxgroups = ngroups; @@ -5690,7 +5668,7 @@ Init_process(void) rb_define_module_function(rb_mProcess, "getrlimit", proc_getrlimit, 1); rb_define_module_function(rb_mProcess, "setrlimit", proc_setrlimit, -1); -#if defined(RLIM2NUM) && defined(RLIM_INFINITY) +#ifdef RLIM2NUM { VALUE inf = RLIM2NUM(RLIM_INFINITY); #ifdef RLIM_SAVED_MAX diff --git a/ruby.c b/ruby.c index 749b57a893..c5d46eddbf 100644 --- a/ruby.c +++ b/ruby.c @@ -1544,6 +1544,7 @@ process_options(int argc, char **argv, struct cmdline_options *opt) rb_define_readonly_boolean("$-a", opt->do_split); rb_set_safe_level(opt->safe_level); + rb_gc_set_params(); return iseq; } diff --git a/strftime.c b/strftime.c index 9d9f48d0de..dc6df615d7 100644 --- a/strftime.c +++ b/strftime.c @@ -237,10 +237,6 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, const str i = rb_strftime_with_timespec(s, endp - s, (fmt), vtm, timev, ts, gmt); \ if (!i) return 0; \ if (precision > i) {\ - if (start + maxsize < s + precision) { \ - errno = ERANGE; \ - return 0; \ - } \ memmove(s + precision - i, s, i);\ memset(s, padding ? padding : ' ', precision - i); \ s += precision; \ diff --git a/string.c b/string.c index 798e108d42..0fb667f0c5 100644 --- a/string.c +++ b/string.c @@ -5164,7 +5164,7 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag) else c = NUM2INT(tmp); } else { - c = cflag ? last : errc; + c = errc; } if (c != errc) { tlen = rb_enc_codelen(c, enc); diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 6b8e6b58ce..6cc2897f5f 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1776,37 +1776,4 @@ End end end end - - def test_fcntl_lock - return if /x86_64-linux/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform - - pad=0 - Tempfile.open(self.class.name) do |f| - r, w = IO.pipe - pid = fork do - r.close - lock = [Fcntl::F_WRLCK, IO::SEEK_SET, pad, 12, 34, 0].pack("s!s!i!L!L!i!") - f.fcntl Fcntl::F_SETLKW, lock - w.syswrite "." - sleep - end - w.close - assert_equal ".", r.read(1) - r.close - pad = 0 - getlock = [Fcntl::F_WRLCK, 0, pad, 0, 0, 0].pack("s!s!i!L!L!i!") - f.fcntl Fcntl::F_GETLK, getlock - - ptype, whence, pad, start, len, lockpid = getlock.unpack("s!s!i!L!L!i!") - - assert_equal(ptype, Fcntl::F_WRLCK) - assert_equal(whence, IO::SEEK_SET) - assert_equal(start, 12) - assert_equal(len, 34) - assert_equal(pid, lockpid) - - Process.kill :TERM, pid - Process.waitpid2(pid) - end - end end diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index c4bc9e6637..a29d509fc4 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -962,7 +962,6 @@ class TestM17N < Test::Unit::TestCase assert_equal("X\u3042\u3044X", "A\u3042\u3044\u3046".tr("^\u3042\u3044", "X")) assert_equal("\u3042\u3046" * 100, ("\u3042\u3044" * 100).tr("\u3044", "\u3046")) - assert_equal("Y", "\u3042".tr("^X", "Y")) end def test_tr_s diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index f3f3f9eb80..b45bfb9bb0 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -384,20 +384,16 @@ class TestProcess < Test::Unit::TestCase Process.wait Process.spawn(*ECHO["c"], STDERR=>STDOUT, STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]) assert_equal("c", File.read("out").chomp) File.open("out", "w") {|f| - Process.wait Process.spawn(*ECHO["d"], STDOUT=>f) + Process.wait Process.spawn(*ECHO["d"], f=>STDOUT, STDOUT=>f) assert_equal("d", File.read("out").chomp) } - opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]} - if /mswin|mingw/ !~ RUBY_PLATFORM - opts.merge(3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT) - end - Process.wait Process.spawn(*ECHO["e"], opts) + Process.wait Process.spawn(*ECHO["e"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644], + 3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT) assert_equal("e", File.read("out").chomp) - opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]} - if /mswin|mingw/ !~ RUBY_PLATFORM - opts.merge(3=>0, 4=>:in, 5=>STDIN, 6=>1, 7=>:out, 8=>STDOUT, 9=>2, 10=>:err, 11=>STDERR) - end - Process.wait Process.spawn(*ECHO["ee"], opts) + Process.wait Process.spawn(*ECHO["ee"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644], + 3=>0, 4=>:in, 5=>STDIN, + 6=>1, 7=>:out, 8=>STDOUT, + 9=>2, 10=>:err, 11=>STDERR) assert_equal("ee", File.read("out").chomp) if /mswin|mingw/ !~ RUBY_PLATFORM # passing non-stdio fds is not supported on Windows diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index faa7bd670d..c5d3a53850 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1944,36 +1944,4 @@ class TestString < Test::Unit::TestCase assert_equal(S("hello world"), a) assert_equal(S("hello "), b) end - - def u(str) - str.force_encoding(Encoding::UTF_8) - end - - def test_byteslice - assert_equal("h", "hello".byteslice(0)) - assert_equal(nil, "hello".byteslice(5)) - assert_equal("o", "hello".byteslice(-1)) - assert_equal(nil, "hello".byteslice(-6)) - - assert_equal("", "hello".byteslice(0, 0)) - assert_equal("hello", "hello".byteslice(0, 6)) - assert_equal("hello", "hello".byteslice(0, 6)) - assert_equal("", "hello".byteslice(5, 1)) - assert_equal("o", "hello".byteslice(-1, 6)) - assert_equal(nil, "hello".byteslice(-6, 1)) - assert_equal(nil, "hello".byteslice(0, -1)) - - assert_equal("h", "hello".byteslice(0..0)) - assert_equal("", "hello".byteslice(5..0)) - assert_equal("o", "hello".byteslice(4..5)) - assert_equal(nil, "hello".byteslice(6..0)) - assert_equal("", "hello".byteslice(-1..0)) - assert_equal("llo", "hello".byteslice(-3..5)) - - assert_equal(u("\x81"), "\u3042".byteslice(1)) - assert_equal(u("\x81\x82"), "\u3042".byteslice(1, 2)) - assert_equal(u("\x81\x82"), "\u3042".byteslice(1..2)) - - assert_equal(u("\x82")+("\u3042"*9), ("\u3042"*10).byteslice(2, 28)) - end end diff --git a/test/ruby/test_system.rb b/test/ruby/test_system.rb index f1372781cf..bb77ad445e 100644 --- a/test/ruby/test_system.rb +++ b/test/ruby/test_system.rb @@ -91,13 +91,24 @@ class TestSystem < Test::Unit::TestCase def test_system_at if /mswin|mingw/ =~ RUBY_PLATFORM bug4393 = '[ruby-core:35218]' + bug4396 = '[ruby-core:35227]' # @ + builtin command assert_equal("foo\n", `@echo foo`, bug4393); assert_equal("foo\n", `@@echo foo`, bug4393); assert_equal("@@foo\n", `@@echo @@foo`, bug4393); - # @ + non builtin command + # "" + @ + built-in + assert_equal("@@foo\n", `"echo" @@foo`, bug4396); + assert_equal("@@foo\n", `"@@echo" @@foo`, bug4396); + assert_equal("@@foo\n", `"@@echo @@foo"`, bug4396); + assert_equal('"@foo"\n', `"echo" "@foo"`, bug4396); + + # ^ + @ + built-in + assert_equal(nil, system('^@echo foo'), bug4396); + assert_equal(nil, system('"^@echo foo"'), bug4396); + assert_equal("@foo\n", `echo ^@foo`); + Dir.mktmpdir("ruby_script_tmp") {|tmpdir| tmpfilename = "#{tmpdir}/ruby_script_tmp.#{$$}" @@ -105,23 +116,16 @@ class TestSystem < Test::Unit::TestCase tmp.print "foo\nbar\nbaz\n@foo"; tmp.close + # @ + non builtin command assert_match(/\Abar\nbaz\n?\z/, `@@findstr "ba" #{tmpfilename.gsub("/", "\\")}`, bug4393); + + # "" + @ + non built-in + assert_match(/\Abar\nbaz\n?\z/, `"@@findstr" "ba" #{tmpfilename.gsub("/", "\\")}`, bug4396); + assert_match(/\A@foo\n?\z/, `"@@findstr" "@foo" #{tmpfilename.gsub("/", "\\")}`, bug4396); } end end - def test_system_redirect_win - if /mswin|mingw/ !~ RUBY_PLATFORM - return - end - - cmd = "%WINDIR%/system32/ping.exe \"BFI3CHL671\" > out.txt 2>NUL" - assert_equal(false, system(cmd), '[ruby-talk:258939]'); - - cmd = "\"%WINDIR%/system32/ping.exe BFI3CHL671\" > out.txt 2>NUL" - assert_equal(false, system(cmd), '[ruby-talk:258939]'); - end - def test_empty_evstr assert_equal("", eval('"#{}"', nil, __FILE__, __LINE__), "[ruby-dev:25113]") end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 98d37a807e..06f25d4775 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -26,352 +26,6 @@ class TestGem < Gem::TestCase util_remove_interrupt_command end - def assert_activate expected, *specs - specs.each do |spec| - case spec - when Array - Gem.activate(*spec) - when String - Gem.activate spec - else - Gem.activate spec.name - end - end - - loaded = Gem.loaded_specs.values.map(&:full_name) - - assert_equal expected.sort, loaded.sort if expected - end - - def test_self_activate - foo = util_spec 'foo', '1' - - assert_activate %w[foo-1], foo - end - - def loaded_spec_names - Gem.loaded_specs.values.map(&:full_name).sort - end - - def unresolved_names - Gem.unresolved_deps.values.map(&:to_s).sort - end - - def test_self_activate_via_require - a1 = new_spec "a", "1", "b" => "= 1" - b1 = new_spec "b", "1", nil, "lib/b/c.rb" - b2 = new_spec "b", "2", nil, "lib/b/c.rb" - - Gem.activate "a", "= 1" - require "b/c" - - assert_equal %w(a-1 b-1), loaded_spec_names - end - - def test_self_activate_deep_unambiguous - a1 = new_spec "a", "1", "b" => "= 1" - b1 = new_spec "b", "1", "c" => "= 1" - b2 = new_spec "b", "2", "c" => "= 2" - c1 = new_spec "c", "1" - c2 = new_spec "c", "2" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1 b-1 c-1), loaded_spec_names - end - - def save_loaded_features - old_loaded_features = $LOADED_FEATURES.dup - yield - ensure - $LOADED_FEATURES.replace old_loaded_features - end - - def test_self_activate_ambiguous_direct - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - b1 = new_spec("b", "1", { "c" => ">= 1" }, "lib/d.rb") - b2 = new_spec("b", "2", { "c" => ">= 2" }, "lib/d.rb") - c1 = new_spec "c", "1" - c2 = new_spec "c", "2" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-1 b-2 c-2), loaded_spec_names - assert_equal [], unresolved_names - end - end - - def test_self_activate_ambiguous_indirect - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - b1 = new_spec "b", "1", "c" => ">= 1" - b2 = new_spec "b", "2", "c" => ">= 2" - c1 = new_spec "c", "1", nil, "lib/d.rb" - c2 = new_spec "c", "2", nil, "lib/d.rb" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-1 b-2 c-2), loaded_spec_names - assert_equal [], unresolved_names - end - end - - def test_self_activate_ambiguous_unrelated - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - b1 = new_spec "b", "1", "c" => ">= 1" - b2 = new_spec "b", "2", "c" => ">= 2" - c1 = new_spec "c", "1" - c2 = new_spec "c", "2" - d1 = new_spec "d", "1", nil, "lib/d.rb" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-1 d-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - end - end - - def test_self_activate_ambiguous_indirect_conflict - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - a2 = new_spec "a", "2", "b" => "> 0" - b1 = new_spec "b", "1", "c" => ">= 1" - b2 = new_spec "b", "2", "c" => ">= 2" - c1 = new_spec "c", "1", nil, "lib/d.rb" - c2 = new_spec("c", "2", { "a" => "1" }, "lib/d.rb") # conflicts with a-2 - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 2" - assert_equal %w(a-2), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-2 b-1 c-1), loaded_spec_names - assert_equal [], unresolved_names - end - end - - def test_require_missing - save_loaded_features do - assert_raises ::LoadError do - require "q" - end - end - end - - def test_self_activate_loaded - util_spec 'foo', '1' - - assert Gem.activate 'foo' - refute Gem.activate 'foo' - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 2.0) - # [C] depends on nothing - - def test_self_activate_unrelated - a = util_spec 'a', '1.0', 'b' => '>= 1.0' - util_spec 'b', '1.0' - c = util_spec 'c', '1.0' - - assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b" - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 2.0) - # [C] = 1.0 depends on - # [B] ~> 1.0 - # - # and should resolve using b-1.0 - - def test_self_activate_over - a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '1.1' - util_spec 'b', '2.0' - c, _ = util_spec 'c', '1.0', 'b' => '~> 1.0' - - Gem.activate "a" - - assert_equal %w[a-1.0 c-1.0], loaded_spec_names - assert_equal ["b (>= 1.0, ~> 1.0)"], unresolved_names - end - - ## - # [A] depends on - # [B] ~> 1.0 (satisfied by 1.1) - # [C] = 1.0 depends on - # [B] = 1.0 - # - # and should resolve using b-1.0 - # - # TODO: this is not under, but over... under would require depth - # first resolve through a dependency that is later pruned. - - def test_self_activate_under - a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '1.1' - c, _ = util_spec 'c', '1.0', 'b' => '= 1.0' - - assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b" - end - - ## - # [A1] depends on - # [B] > 0 (satisfied by 2.0) - # [B1] depends on - # [C] > 0 (satisfied by 1.0) - # [B2] depends on nothing! - # [C1] depends on nothing - - def test_self_activate_dropped - a1, = util_spec 'a', '1', 'b' => nil - util_spec 'b', '1', 'c' => nil - util_spec 'b', '2' - util_spec 'c', '1' - - assert_activate %w[b-2 a-1], a1, "b" - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 1.1) depends on - # [Z] - # [C] >= 1.0 depends on - # [B] = 1.0 - # - # and should backtrack to resolve using b-1.0, pruning Z from the - # resolve. - - def test_self_activate_raggi_the_edgecase_generator - a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '>= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '1.1', 'z' => '>= 1.0' - c, _ = util_spec 'c', '1.0', 'b' => '= 1.0' - - assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b" - end - - def test_self_activate_conflict - util_spec 'b', '1.0' - util_spec 'b', '2.0' - - gem "b", "= 1.0" - - assert_raises Gem::LoadError do - gem "b", "= 2.0" - end - end - - ## - # [A] depends on - # [B] ~> 1.0 (satisfied by 1.0) - # [C] = 1.0 depends on - # [B] = 2.0 - - def test_self_activate_divergent - a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '2.0' - c, _ = util_spec 'c', '1.0', 'b' => '= 2.0' - - e = assert_raises Gem::LoadError do - assert_activate nil, a, c, "b" - end - - assert_match(/Unable to activate c-1.0,/, e.message) - assert_match(/because b-1.0 conflicts with b .= 2.0/, e.message) - end - - ## - # DOC - - def test_self_activate_platform_alternate - @x1_m = util_spec 'x', '1' do |s| - s.platform = Gem::Platform.new %w[cpu my_platform 1] - end - - @x1_o = util_spec 'x', '1' do |s| - s.platform = Gem::Platform.new %w[cpu other_platform 1] - end - - @w1 = util_spec 'w', '1', 'x' => nil - - util_set_arch 'cpu-my_platform1' - - assert_activate %w[x-1-cpu-my_platform-1 w-1], @w1, @x1_m - end - - ## - # DOC - - def test_self_activate_platform_bump - @y1 = util_spec 'y', '1' - - @y1_1_p = util_spec 'y', '1.1' do |s| - s.platform = Gem::Platform.new %w[cpu my_platform 1] - end - - @z1 = util_spec 'z', '1', 'y' => nil - - assert_activate %w[y-1 z-1], @z1, @y1 - end - - ## - # [C] depends on - # [A] = 1.a - # [B] = 1.0 depends on - # [A] >= 0 (satisfied by 1.a) - - def test_self_activate_prerelease - @c1_pre = util_spec 'c', '1.a', "a" => "1.a", "b" => "1" - @a1_pre = util_spec 'a', '1.a' - @b1 = util_spec 'b', '1' do |s| - s.add_dependency 'a' - s.add_development_dependency 'aa' - end - - assert_activate %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1 - end - - ## - # DOC - - def test_self_activate_old_required - e1, = util_spec 'e', '1', 'd' => '= 1' - @d1 = util_spec 'd', '1' - @d2 = util_spec 'd', '2' - - assert_activate %w[d-1 e-1], e1, "d" - end - def test_self_all_load_paths util_make_gems @@ -417,7 +71,7 @@ class TestGem < Gem::TestCase end def test_self_bin_path_nonexistent_binfile - quick_spec 'a', '2' do |s| + quick_gem 'a', '2' do |s| s.executables = ['exec'] end assert_raises(Gem::GemNotFoundException) do @@ -426,7 +80,7 @@ class TestGem < Gem::TestCase end def test_self_bin_path_no_bin_file - quick_spec 'a', '1' + quick_gem 'a', '1' assert_raises(Gem::Exception) do Gem.bin_path('a', nil, '1') end @@ -440,7 +94,7 @@ class TestGem < Gem::TestCase def test_self_bin_path_bin_file_gone_in_latest util_exec_gem - quick_spec 'a', '10' do |s| + quick_gem 'a', '10' do |s| s.executables = [] s.default_executable = nil end @@ -496,7 +150,7 @@ class TestGem < Gem::TestCase fp.puts 'blah' end - foo = quick_spec 'foo' do |s| s.files = %w[data/foo.txt] end + foo = quick_gem 'foo' do |s| s.files = %w[data/foo.txt] end install_gem foo end @@ -558,7 +212,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories @gemhome - assert File.directory?(Gem.cache_dir(@gemhome)) + assert File.directory?(File.join(@gemhome, "cache")) end def test_self_ensure_gem_directories_missing_parents @@ -570,7 +224,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - assert File.directory?(Gem.cache_dir(gemdir)) + assert File.directory?("#{gemdir}/cache") end unless win_platform? then # only for FS that support write protection @@ -584,7 +238,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - refute File.exist?(Gem.cache_dir(gemdir)) + refute File.exist?("#{gemdir}/cache") ensure FileUtils.chmod 0600, gemdir end @@ -601,7 +255,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - refute File.exist?(Gem.cache_dir(gemdir)) + refute File.exist?("#{gemdir}/cache") ensure FileUtils.chmod 0600, parent end @@ -622,8 +276,8 @@ class TestGem < Gem::TestCase def test_self_find_files discover_path = File.join 'lib', 'sff', 'discover.rb' - cwd = File.expand_path("test/rubygems", @@project_dir) - $LOAD_PATH.unshift cwd + cwd = File.expand_path '..', __FILE__ + $LOAD_PATH.unshift cwd.dup foo1 = quick_gem 'sff', '1' do |s| s.files << discover_path @@ -647,7 +301,7 @@ class TestGem < Gem::TestCase Gem.searcher = nil expected = [ - File.expand_path('test/rubygems/sff/discover.rb', @@project_dir), + File.expand_path('../sff/discover.rb', __FILE__), File.join(foo2.full_gem_path, discover_path), File.join(foo1.full_gem_path, discover_path), ] @@ -673,7 +327,7 @@ class TestGem < Gem::TestCase end def test_self_loaded_specs - foo = quick_spec 'foo' + foo = quick_gem 'foo' install_gem foo Gem.source_index = nil @@ -776,12 +430,22 @@ class TestGem < Gem::TestCase end def test_self_prefix - assert_equal @@project_dir, Gem.prefix + file_name = File.expand_path __FILE__ + + prefix = File.dirname File.dirname(file_name) + prefix = File.dirname prefix if File.basename(prefix) == 'test' + + assert_equal prefix, Gem.prefix end def test_self_prefix_libdir orig_libdir = Gem::ConfigMap[:libdir] - Gem::ConfigMap[:libdir] = @@project_dir + + file_name = File.expand_path __FILE__ + prefix = File.dirname File.dirname(file_name) + prefix = File.dirname prefix if File.basename(prefix) == 'test' + + Gem::ConfigMap[:libdir] = prefix assert_nil Gem.prefix ensure @@ -790,7 +454,12 @@ class TestGem < Gem::TestCase def test_self_prefix_sitelibdir orig_sitelibdir = Gem::ConfigMap[:sitelibdir] - Gem::ConfigMap[:sitelibdir] = @@project_dir + + file_name = File.expand_path __FILE__ + prefix = File.dirname File.dirname(file_name) + prefix = File.dirname prefix if File.basename(prefix) == 'test' + + Gem::ConfigMap[:sitelibdir] = prefix assert_nil Gem.prefix ensure @@ -954,20 +623,6 @@ class TestGem < Gem::TestCase end end - def test_self_cache_dir - util_ensure_gem_dirs - - assert_equal File.join(@gemhome, 'cache'), Gem.cache_dir - assert_equal File.join(@userhome, '.gem', Gem.ruby_engine, Gem::ConfigMap[:ruby_version], 'cache'), Gem.cache_dir(Gem.user_dir) - end - - def test_self_cache_gem - util_ensure_gem_dirs - - assert_equal File.join(@gemhome, 'cache', 'test.gem'), Gem.cache_gem('test.gem') - assert_equal File.join(@userhome, '.gem', Gem.ruby_engine, Gem::ConfigMap[:ruby_version], 'cache', 'test.gem'), Gem.cache_gem('test.gem', Gem.user_dir) - end - if Gem.win_platform? then def test_self_user_home_userprofile skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION @@ -1019,10 +674,10 @@ class TestGem < Gem::TestCase Dir.chdir @tempdir do FileUtils.mkdir_p 'lib' File.open plugin_path, "w" do |fp| - fp.puts "class TestGem; TEST_SPEC_PLUGIN_LOAD = :loaded; end" + fp.puts "TestGem::TEST_SPEC_PLUGIN_LOAD = :loaded" end - foo = quick_spec 'foo', '1' do |s| + foo = quick_gem 'foo', '1' do |s| s.files << plugin_path end @@ -1030,7 +685,6 @@ class TestGem < Gem::TestCase end Gem.source_index = nil - Gem.searcher = nil gem 'foo' @@ -1041,24 +695,23 @@ class TestGem < Gem::TestCase def test_load_env_plugins with_plugin('load') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_LOAD rescue nil + assert_equal :loaded, TEST_PLUGIN_LOAD util_remove_interrupt_command # Should attempt to cause a StandardError with_plugin('standarderror') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_STANDARDERROR rescue nil + assert_equal :loaded, TEST_PLUGIN_STANDARDERROR util_remove_interrupt_command # Should attempt to cause an Exception with_plugin('exception') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_EXCEPTION rescue nil + assert_equal :loaded, TEST_PLUGIN_EXCEPTION end def with_plugin(path) - test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}", - @@project_dir) + test_plugin_path = File.expand_path "../plugin/#{path}", __FILE__ # A single test plugin should get loaded once only, in order to preserve # sane test semantics. @@ -1080,7 +733,7 @@ class TestGem < Gem::TestCase end def util_exec_gem - spec, _ = quick_spec 'a', '4' do |s| + spec, _ = quick_gem 'a', '4' do |s| s.default_executable = 'exec' s.executables = ['exec', 'abin'] end @@ -1124,5 +777,6 @@ class TestGem < Gem::TestCase Gem::Commands.send :remove_const, :InterruptCommand if Gem::Commands.const_defined? :InterruptCommand end + end diff --git a/test/rubygems/test_gem_builder.rb b/test/rubygems/test_gem_builder.rb index f95472f626..d146c843bb 100644 --- a/test/rubygems/test_gem_builder.rb +++ b/test/rubygems/test_gem_builder.rb @@ -10,7 +10,7 @@ require 'rubygems/builder' class TestGemBuilder < Gem::TestCase def test_build - builder = Gem::Builder.new quick_spec('a') + builder = Gem::Builder.new quick_gem('a') use_ui @ui do Dir.chdir @tempdir do diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb index 3769c250d5..daadf2520e 100644 --- a/test/rubygems/test_gem_command_manager.rb +++ b/test/rubygems/test_gem_command_manager.rb @@ -17,7 +17,7 @@ class TestGemCommandManager < Gem::TestCase def test_run_interrupt old_load_path = $:.dup - $: << File.expand_path("test/rubygems", @@project_dir) + $: << "test/rubygems" Gem.load_env_plugins use_ui @ui do @@ -33,7 +33,7 @@ class TestGemCommandManager < Gem::TestCase def test_run_crash_command old_load_path = $:.dup - $: << File.expand_path("test/rubygems", @@project_dir) + $: << "test/rubygems" @command_manager.register_command :crash use_ui @ui do diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb index 5c38a1a5e8..5c9c5eeb6e 100644 --- a/test/rubygems/test_gem_commands_build_command.rb +++ b/test/rubygems/test_gem_commands_build_command.rb @@ -13,7 +13,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase def setup super - @gem = quick_spec 'some_gem' do |s| + @gem = quick_gem 'some_gem' do |s| s.rubyforge_project = 'example' end diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb index a514ea41f2..9d5fc1eada 100644 --- a/test/rubygems/test_gem_commands_cert_command.rb +++ b/test/rubygems/test_gem_commands_cert_command.rb @@ -6,7 +6,6 @@ require 'rubygems/test_case' require 'rubygems/commands/cert_command' -require 'rubygems/fix_openssl_warnings' if RUBY_VERSION < "1.9" unless defined? OpenSSL then warn "`gem cert` tests are being skipped, module OpenSSL not found" @@ -22,7 +21,7 @@ class TestGemCommandsCertCommand < Gem::TestCase @cmd = Gem::Commands::CertCommand.new - root = File.expand_path(File.dirname(__FILE__), @@project_dir) + root = File.expand_path(File.dirname(__FILE__)) FileUtils.cp File.join(root, 'data', 'gem-private_key.pem'), @tempdir FileUtils.cp File.join(root, 'data', 'gem-public_cert.pem'), @tempdir diff --git a/test/rubygems/test_gem_commands_dependency_command.rb b/test/rubygems/test_gem_commands_dependency_command.rb index 665cd98c4d..40d96f729a 100644 --- a/test/rubygems/test_gem_commands_dependency_command.rb +++ b/test/rubygems/test_gem_commands_dependency_command.rb @@ -32,7 +32,7 @@ class TestGemCommandsDependencyCommand < Gem::TestCase @cmd.execute end - assert_equal "Gem foo-2\n bar (> 1)\n baz (> 1)\n\n", + assert_equal "Gem foo-2\n bar (> 1, runtime)\n baz (> 1, runtime)\n\n", @ui.output assert_equal '', @ui.error end @@ -83,7 +83,7 @@ Gem pl-1-x86-linux end def test_execute_pipe_format - quick_spec 'foo' do |gem| + quick_gem 'foo' do |gem| gem.add_dependency 'bar', '> 1' end @@ -127,7 +127,6 @@ Gem b-2 end def test_execute_reverse - # FIX: this shouldn't need to write out, but fails if you switch it quick_gem 'foo' do |gem| gem.add_dependency 'bar', '> 1' end @@ -147,9 +146,9 @@ Gem b-2 expected = <<-EOF Gem foo-2 - bar (> 1) + bar (> 1, runtime) Used by - baz-2 (foo (>= 0)) + baz-2 (foo (>= 0, runtime)) EOF @@ -195,7 +194,7 @@ ERROR: Only reverse dependencies for local gems are supported. @cmd.execute end - assert_equal "Gem foo-2\n bar (> 1)\n\n", @ui.output + assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output assert_equal '', @ui.error end diff --git a/test/rubygems/test_gem_commands_fetch_command.rb b/test/rubygems/test_gem_commands_fetch_command.rb index 173a33572f..657e8e9f80 100644 --- a/test/rubygems/test_gem_commands_fetch_command.rb +++ b/test/rubygems/test_gem_commands_fetch_command.rb @@ -22,7 +22,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase util_setup_spec_fetcher @a2 @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - File.read(Gem.cache_gem(@a2.file_name, @gemhome)) + File.read(File.join(@gemhome, 'cache', @a2.file_name)) @cmd.options[:args] = [@a2.name] @@ -41,9 +41,9 @@ class TestGemCommandsFetchCommand < Gem::TestCase util_setup_spec_fetcher @a2, @a2_pre @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - File.read(Gem.cache_gem(@a2.file_name, @gemhome)) + File.read(File.join(@gemhome, 'cache', @a2.file_name)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - File.read(Gem.cache_gem(@a2_pre.file_name, @gemhome)) + File.read(File.join(@gemhome, 'cache', @a2_pre.file_name)) @cmd.options[:args] = [@a2.name] @cmd.options[:prerelease] = true @@ -63,7 +63,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase util_setup_spec_fetcher @a1, @a2 @fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] = - File.read(Gem.cache_gem(@a1.file_name, @gemhome)) + File.read(File.join(@gemhome, 'cache', @a1.file_name)) @cmd.options[:args] = [@a2.name] @cmd.options[:version] = Gem::Requirement.new '1' diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index adc66aa911..a3ceb81ab7 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -7,12 +7,6 @@ require 'rubygems/test_case' require 'rubygems/commands/install_command' -begin - gem "rdoc" -rescue Gem::LoadError - # ignore -end - class TestGemCommandsInstallCommand < Gem::TestCase def setup @@ -28,9 +22,9 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_spec_fetcher @a2, @a2_pre @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2.file_name)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name)) @cmd.options[:args] = [@a2.name] @@ -50,12 +44,11 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_spec_fetcher @a2, @a2_pre @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2.file_name)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name)) - @cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s, - "--no-ri", "--no-rdoc"] + @cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s] assert @cmd.options[:prerelease] assert @cmd.options[:version].satisfied_by?(@a2_pre.version) @@ -92,7 +85,8 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_fake_fetcher @cmd.options[:domain] = :local - FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir + FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name), + File.join(@tempdir) @cmd.options[:args] = [@a2.name] @@ -121,7 +115,8 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_fake_fetcher @cmd.options[:user_install] = false - FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir + FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name), + File.join(@tempdir) @cmd.options[:args] = [@a2.name] @@ -188,7 +183,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase correctly_spelled = "non_existent_with_hint" util_setup_fake_fetcher - util_setup_spec_fetcher quick_spec(correctly_spelled, '2') + util_setup_spec_fetcher quick_gem(correctly_spelled, '2') @cmd.options[:args] = [misspelled] @@ -212,9 +207,9 @@ ERROR: Possible alternatives: non_existent_with_hint util_setup_spec_fetcher @a2, @a2_pre @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2.file_name)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name)) @cmd.options[:prerelease] = true @cmd.options[:args] = [@a2_pre.name] @@ -238,7 +233,7 @@ ERROR: Possible alternatives: non_existent_with_hint util_setup_spec_fetcher @a2 @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2.file_name)) @cmd.options[:args] = [@a2.name] @@ -265,9 +260,11 @@ ERROR: Possible alternatives: non_existent_with_hint util_setup_fake_fetcher @cmd.options[:domain] = :local - FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir + FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name), + File.join(@tempdir) - FileUtils.mv Gem.cache_gem(@b2.file_name, @gemhome), @tempdir + FileUtils.mv File.join(@gemhome, 'cache', @b2.file_name), + File.join(@tempdir) @cmd.options[:args] = [@a2.name, @b2.name] @@ -296,7 +293,7 @@ ERROR: Possible alternatives: non_existent_with_hint util_setup_spec_fetcher @b2 @fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] = - read_binary(Gem.cache_gem(@b2.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @b2.file_name)) uninstall_gem(@b2) diff --git a/test/rubygems/test_gem_commands_lock_command.rb b/test/rubygems/test_gem_commands_lock_command.rb index bb3134661d..25b033af5d 100644 --- a/test/rubygems/test_gem_commands_lock_command.rb +++ b/test/rubygems/test_gem_commands_lock_command.rb @@ -51,7 +51,7 @@ gem 'a', '= 1' expected = <<-EXPECTED require 'rubygems' gem 'd', '= 1' -# Unable to satisfy 'z (>= 0)' from currently installed gems +# Unable to satisfy 'z (>= 0, runtime)' from currently installed gems EXPECTED assert_equal expected, @ui.output diff --git a/test/rubygems/test_gem_commands_outdated_command.rb b/test/rubygems/test_gem_commands_outdated_command.rb index 632e9a5548..6f99f33e99 100644 --- a/test/rubygems/test_gem_commands_outdated_command.rb +++ b/test/rubygems/test_gem_commands_outdated_command.rb @@ -22,11 +22,14 @@ class TestGemCommandsOutdatedCommand < Gem::TestCase def test_execute quick_gem 'foo', '0.1' quick_gem 'foo', '0.2' - remote_10 = quick_spec 'foo', '1.0' - remote_20 = quick_spec 'foo', '2.0' + remote_10 = quick_gem 'foo', '1.0' + remote_20 = quick_gem 'foo', '2.0' remote_spec_file = File.join @gemhome, 'specifications', remote_10.spec_name + FileUtils.rm remote_spec_file + remote_spec_file = File.join @gemhome, 'specifications', remote_20.spec_name + FileUtils.rm remote_spec_file @fetcher = Gem::FakeFetcher.new Gem::RemoteFetcher.fetcher = @fetcher diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb index 4decdf81b9..9cab574a1f 100644 --- a/test/rubygems/test_gem_commands_pristine_command.rb +++ b/test/rubygems/test_gem_commands_pristine_command.rb @@ -15,7 +15,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase end def test_execute - a = quick_spec 'a' do |s| s.executables = %w[foo] end + a = quick_gem 'a' do |s| s.executables = %w[foo] end FileUtils.mkdir_p File.join(@tempdir, 'bin') File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp| fp.puts "#!/usr/bin/ruby" @@ -45,7 +45,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase end def test_execute_all - a = quick_spec 'a' do |s| s.executables = %w[foo] end + a = quick_gem 'a' do |s| s.executables = %w[foo] end FileUtils.mkdir_p File.join(@tempdir, 'bin') File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp| fp.puts "#!/usr/bin/ruby" @@ -73,29 +73,15 @@ class TestGemCommandsPristineCommand < Gem::TestCase end def test_execute_missing_cache_gem - a = quick_spec 'a' do |s| - s.executables = %w[foo] - end - + a = quick_gem 'a' do |s| s.executables = %w[foo] end FileUtils.mkdir_p File.join(@tempdir, 'bin') - File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp| fp.puts "#!/usr/bin/ruby" end install_gem a - a_data = nil - open File.join(@gemhome, 'cache', a.file_name), 'rb' do |fp| - a_data = fp.read - end - - util_setup_fake_fetcher - util_setup_spec_fetcher a - - Gem::RemoteFetcher.fetcher.data["http://gems.example.com/gems/#{a.file_name}"] = a_data - - FileUtils.rm Gem.cache_gem(a.file_name, @gemhome) + FileUtils.rm File.join(@gemhome, 'cache', a.file_name) @cmd.options[:args] = %w[a] @@ -105,17 +91,11 @@ class TestGemCommandsPristineCommand < Gem::TestCase out = @ui.output.split "\n" - [ - "Restoring gem\(s\) to pristine condition...", - "Restored a-1", - "Cached gem for a-2 not found, attempting to fetch...", - "Restored a-2", - "Restored a-3.a" - ].each do |line| - assert_equal line, out.shift - end - + assert_equal "Restoring gem\(s\) to pristine condition...", out.shift assert_empty out, out.inspect + + assert_equal "ERROR: Cached gem for #{a.full_name} not found, use `gem install` to restore\n", + @ui.error end def test_execute_no_gem diff --git a/test/rubygems/test_gem_commands_specification_command.rb b/test/rubygems/test_gem_commands_specification_command.rb index 767992f240..ca210059fd 100644 --- a/test/rubygems/test_gem_commands_specification_command.rb +++ b/test/rubygems/test_gem_commands_specification_command.rb @@ -16,7 +16,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute - foo = quick_spec 'foo' + foo = quick_gem 'foo' Gem.source_index.add_spec foo @cmd.options[:args] = %w[foo] @@ -31,8 +31,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute_all - quick_spec 'foo', '0.0.1' - quick_spec 'foo', '0.0.2' + quick_gem 'foo', '0.0.1' + quick_gem 'foo', '0.0.2' @cmd.options[:args] = %w[foo] @cmd.options[:all] = true @@ -62,8 +62,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute_exact_match - quick_spec 'foo' - quick_spec 'foo_bar' + quick_gem 'foo' + quick_gem 'foo_bar' @cmd.options[:args] = %w[foo] @@ -77,7 +77,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute_field - foo = quick_spec 'foo' + foo = quick_gem 'foo' Gem.source_index.add_spec foo @cmd.options[:args] = %w[foo name] @@ -90,7 +90,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute_marshal - foo = quick_spec 'foo' + foo = quick_gem 'foo' Gem.source_index.add_spec foo @cmd.options[:args] = %w[foo] @@ -126,7 +126,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute_ruby - foo = quick_spec 'foo' + foo = quick_gem 'foo' Gem.source_index.add_spec foo @cmd.options[:args] = %w[foo] diff --git a/test/rubygems/test_gem_commands_stale_command.rb b/test/rubygems/test_gem_commands_stale_command.rb index d5aad6ce0c..f3876d90db 100644 --- a/test/rubygems/test_gem_commands_stale_command.rb +++ b/test/rubygems/test_gem_commands_stale_command.rb @@ -16,11 +16,10 @@ class TestGemCommandsStaleCommand < Gem::TestCase def test_execute_sorts files = %w[lib/foo_bar.rb Rakefile] - foo_bar = quick_spec 'foo_bar' do |gem| + foo_bar = quick_gem 'foo_bar' do |gem| gem.files = files end - - bar_baz = quick_spec 'bar_baz' do |gem| + bar_baz = quick_gem 'bar_baz' do |gem| gem.files = files end @@ -37,7 +36,6 @@ class TestGemCommandsStaleCommand < Gem::TestCase use_ui @ui do @cmd.execute end - lines = @ui.output.split("\n") assert_equal("#{foo_bar.name}-#{foo_bar.version}", lines[0].split.first) assert_equal("#{bar_baz.name}-#{bar_baz.version}", lines[1].split.first) diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 47f4960145..c5be3beb90 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -33,7 +33,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end end - if win_platform? then + if win_platform? assert File.exist?(@executable) else assert File.symlink?(@executable) @@ -42,9 +42,9 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase # Evil hack to prevent false removal success FileUtils.rm_f @executable - open @executable, "wb+" do |f| f.puts "binary" end + open(@executable, "wb+") {|f| f.puts "binary"} - @cmd.options[:args] = [@spec.name] + @cmd.options[:args] = Array(@spec.name) use_ui @ui do @cmd.execute end @@ -56,25 +56,6 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase assert_nil output.shift, "UI output should have contained only two lines" end - def test_execute_removes_formatted_executable - FileUtils.rm_f @executable # Wish this didn't happen in #setup - - Gem::Installer.exec_format = 'foo-%s-bar' - - @installer.format_executable = true - @installer.install - - formatted_executable = File.join @gemhome, 'bin', 'foo-executable-bar' - assert_equal true, File.exist?(formatted_executable) - - @cmd.options[:format_executable] = true - @cmd.execute - - assert_equal false, File.exist?(formatted_executable) - rescue - Gem::Installer.exec_format = nil - end - def test_execute_not_installed @cmd.options[:args] = ["foo"] e = assert_raises Gem::InstallError do @@ -89,7 +70,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end def test_execute_prerelease - @spec = quick_spec "pre", "2.b" + @spec = quick_gem "pre", "2.b" @gem = File.join @tempdir, @spec.file_name FileUtils.touch @gem diff --git a/test/rubygems/test_gem_commands_unpack_command.rb b/test/rubygems/test_gem_commands_unpack_command.rb index 8291a6b949..0fb4ef3843 100644 --- a/test/rubygems/test_gem_commands_unpack_command.rb +++ b/test/rubygems/test_gem_commands_unpack_command.rb @@ -22,7 +22,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase assert_equal( @cmd.find_in_cache(@a1.file_name), - Gem.cache_gem(@a1.file_name, @gemhome), + File.join(@gemhome, 'cache', @a1.file_name), 'found a-1.gem in the cache' ) end @@ -34,7 +34,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase a1_data = nil - open Gem.cache_gem(@a1.file_name, @gemhome), 'rb' do |fp| + open File.join(@gemhome, 'cache', @a1.file_name), 'rb' do |fp| a1_data = fp.read end @@ -44,15 +44,15 @@ class TestGemCommandsUnpackCommand < Gem::TestCase dep = Gem::Dependency.new(@a1.name, @a1.version) assert_equal( @cmd.get_path(dep), - Gem.cache_gem(@a1.file_name, @gemhome), + File.join(@gemhome, 'cache', @a1.file_name), 'fetches a-1 and returns the cache path' ) - FileUtils.rm Gem.cache_gem(@a1.file_name, @gemhome) + FileUtils.rm File.join(@gemhome, 'cache', @a1.file_name) assert_equal( @cmd.get_path(dep), - Gem.cache_gem(@a1.file_name, @gemhome), + File.join(@gemhome, 'cache', @a1.file_name), 'when removed from cache, refetches a-1' ) end @@ -74,8 +74,6 @@ class TestGemCommandsUnpackCommand < Gem::TestCase def test_execute_gem_path util_make_gems - util_setup_spec_fetcher - util_setup_fake_fetcher Gem.clear_paths @@ -123,7 +121,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase util_clear_gems a2_data = nil - open Gem.cache_gem(@a2.file_name, @gemhome), 'rb' do |fp| + open File.join(@gemhome, 'cache', @a2.file_name), 'rb' do |fp| a2_data = fp.read end @@ -177,8 +175,8 @@ class TestGemCommandsUnpackCommand < Gem::TestCase end def test_execute_exact_match - foo_spec = quick_spec 'foo' - foo_bar_spec = quick_spec 'foo_bar' + foo_spec = quick_gem 'foo' + foo_bar_spec = quick_gem 'foo_bar' use_ui @ui do Dir.chdir @tempdir do diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb index 24966a3a84..6c16713130 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -7,12 +7,6 @@ require 'rubygems/test_case' require 'rubygems/commands/update_command' -begin - gem "rdoc" -rescue Gem::LoadError - # ignore -end - class TestGemCommandsUpdateCommand < Gem::TestCase def setup @@ -25,8 +19,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase util_setup_fake_fetcher - @a1_path = Gem.cache_gem(@a1.file_name, @gemhome) - @a2_path = Gem.cache_gem(@a2.file_name, @gemhome) + @a1_path = File.join @gemhome, 'cache', @a1.file_name + @a2_path = File.join @gemhome, 'cache', @a2.file_name util_setup_spec_fetcher @a1, @a2 @@ -42,8 +36,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase Gem::Installer.new(@a1_path).install @cmd.options[:args] = [] - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false + @cmd.options[:generate_rdoc] = true + @cmd.options[:generate_ri] = true use_ui @ui do @cmd.execute @@ -54,153 +48,12 @@ class TestGemCommandsUpdateCommand < Gem::TestCase assert_equal "Updating #{@a2.name}", out.shift assert_equal "Successfully installed #{@a2.full_name}", out.shift assert_equal "Gems updated: #{@a2.name}", out.shift - assert_empty out - end - - def util_setup_rubygem version - gem = quick_spec('rubygems-update', version.to_s) do |s| - s.files = %w[setup.rb] - end - write_file File.join(*%W[gems #{gem.original_name} setup.rb]) - util_build_gem gem - util_setup_spec_fetcher gem - gem - end - - def util_setup_rubygem8 - @rubygem8 = util_setup_rubygem 8 - end - - def util_setup_rubygem9 - @rubygem9 = util_setup_rubygem 9 - end - - def util_setup_rubygem_current - @rubygem_current = util_setup_rubygem Gem::VERSION - end - - def util_add_to_fetcher *specs - specs.each do |spec| - gem_file = Gem.cache_gem(spec.file_name, @gemhome) - - @fetcher.data["http://gems.example.com/gems/#{spec.file_name}"] = - Gem.read_binary gem_file - end - end - - def test_execute_system - util_setup_rubygem9 - util_setup_spec_fetcher @rubygem9 - util_add_to_fetcher @rubygem9 - util_clear_gems - - @cmd.options[:args] = [] - @cmd.options[:system] = true - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false - - use_ui @ui do - @cmd.execute - end - - out = @ui.output.split "\n" - assert_equal "Updating rubygems-update", out.shift - assert_equal "Successfully installed rubygems-update-9", out.shift - assert_equal "Installing RubyGems 9", out.shift - assert_equal "RubyGems system software updated", out.shift - - assert_empty out - end - - def test_execute_system_at_latest - util_setup_rubygem_current - util_setup_spec_fetcher @rubygem_current - util_add_to_fetcher @rubygem_current - util_clear_gems - - @cmd.options[:args] = [] - @cmd.options[:system] = true - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false - - assert_raises Gem::SystemExitException do - use_ui @ui do - @cmd.execute - end - end - - out = @ui.output.split "\n" - assert_equal "Latest version currently installed. Aborting.", out.shift - assert_empty out - end - - def test_execute_system_multiple - util_setup_rubygem9 - util_setup_rubygem8 - util_setup_spec_fetcher @rubygem8, @rubygem9 - util_add_to_fetcher @rubygem8, @rubygem9 - util_clear_gems - - @cmd.options[:args] = [] - @cmd.options[:system] = true - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false - - use_ui @ui do - @cmd.execute - end - - out = @ui.output.split "\n" - assert_equal "Updating rubygems-update", out.shift - assert_equal "Successfully installed rubygems-update-9", out.shift - assert_equal "Installing RubyGems 9", out.shift - assert_equal "RubyGems system software updated", out.shift - - assert_empty out - end - - def test_execute_system_specific - util_clear_gems - util_setup_rubygem9 - util_setup_rubygem8 - util_setup_spec_fetcher @rubygem8, @rubygem9 - util_add_to_fetcher @rubygem8, @rubygem9 - - @cmd.options[:args] = [] - @cmd.options[:system] = "8" - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false - - use_ui @ui do - @cmd.execute - end - - out = @ui.output.split "\n" - assert_equal "Updating rubygems-update", out.shift - assert_equal "Successfully installed rubygems-update-8", out.shift - assert_equal "Installing RubyGems 8", out.shift - assert_equal "RubyGems system software updated", out.shift + assert_equal "Installing ri documentation for a-2...", out.shift + assert_equal "Installing RDoc documentation for a-2...", out.shift assert_empty out end - def test_execute_system_with_gems - @cmd.options[:args] = %w[gem] - @cmd.options[:system] = true - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false - - assert_raises Gem::MockGemUi::TermError do - use_ui @ui do - @cmd.execute - end - end - - assert_empty @ui.output - assert_equal "ERROR: Gem names are not allowed with the --system option\n", - @ui.error - end - # before: # a1 -> c1.2 # after: @@ -210,7 +63,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase def test_execute_dependencies @a1.add_dependency 'c', '1.2' - @c2 = quick_spec 'c', '2' do |s| + @c2 = quick_gem 'c', '2' do |s| s.files = %w[lib/code.rb] s.require_paths = %w[lib] end @@ -218,9 +71,9 @@ class TestGemCommandsUpdateCommand < Gem::TestCase @a2.add_dependency 'c', '2' @a2.add_dependency 'b', '2' - @b2_path = Gem.cache_gem(@b2.file_name, @gemhome) - @c1_2_path = Gem.cache_gem(@c1_2.file_name, @gemhome) - @c2_path = Gem.cache_gem(@c2.file_name, @gemhome) + @b2_path = File.join @gemhome, 'cache', @b2.file_name + @c1_2_path = File.join @gemhome, 'cache', @c1_2.file_name + @c2_path = File.join @gemhome, 'cache', @c2.file_name @source_index = Gem::SourceIndex.new @source_index.add_spec @a1 @@ -319,39 +172,4 @@ class TestGemCommandsUpdateCommand < Gem::TestCase assert_empty out end - - def test_handle_options_system - @cmd.handle_options %w[--system] - - expected = { - :generate_ri => true, - :system => true, - :force => false, - :args => [], - :generate_rdoc => true, - } - - assert_equal expected, @cmd.options - end - - def test_handle_options_system_non_version - assert_raises ArgumentError do - @cmd.handle_options %w[--system non-version] - end - end - - def test_handle_options_system_specific - @cmd.handle_options %w[--system 1.3.7] - - expected = { - :generate_ri => true, - :system => "1.3.7", - :force => false, - :args => [], - :generate_rdoc => true, - } - - assert_equal expected, @cmd.options - end - end diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index 424fd92f80..dc53d21933 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -283,20 +283,6 @@ class TestGemConfigFile < Gem::TestCase assert_equal "701229f217cdf23b1344c7b4b54ca97", @cfg.rubygems_api_key end - def test_load_api_keys_from_config - temp_cred = File.join Gem.user_home, '.gem', 'credentials' - FileUtils.mkdir File.dirname(temp_cred) - File.open temp_cred, 'w' do |fp| - fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97" - fp.puts ":other: a5fdbb6ba150cbb83aad2bb2fede64c" - end - - util_config_file - - assert_equal({:rubygems => '701229f217cdf23b1344c7b4b54ca97', - :other => 'a5fdbb6ba150cbb83aad2bb2fede64c'}, @cfg.api_keys) - end - def util_config_file(args = @cfg_args) @cfg = Gem::ConfigFile.new args end diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb index b4a21b896c..51b746f555 100644 --- a/test/rubygems/test_gem_dependency.rb +++ b/test/rubygems/test_gem_dependency.rb @@ -106,45 +106,6 @@ class TestGemDependency < Gem::TestCase refute_equal dep("pkg", :development), dep("pkg", :runtime), "type" end - def test_merge - a1 = dep 'a', '~> 1.0' - a2 = dep 'a', '= 1.0' - - a3 = a1.merge a2 - - assert_equal dep('a', '~> 1.0', '= 1.0'), a3 - end - - def test_merge_default - a1 = dep 'a' - a2 = dep 'a', '1' - - a3 = a1.merge a2 - - assert_equal dep('a', '1'), a3 - end - - def test_merge_name_mismatch - a = dep 'a' - b = dep 'b' - - e = assert_raises ArgumentError do - a.merge b - end - - assert_equal 'a (>= 0) and b (>= 0) have different names', - e.message - end - - def test_merge_other_default - a1 = dep 'a', '1' - a2 = dep 'a' - - a3 = a1.merge a2 - - assert_equal dep('a', '1'), a3 - end - def test_prerelease_eh d = dep "pkg", "= 1" diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index 5cf79d3c59..cdc0428e9f 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -6,28 +6,66 @@ require 'rubygems/test_case' require 'rubygems/dependency_installer' -require 'rubygems/security' class TestGemDependencyInstaller < Gem::TestCase def setup super - @gems_dir = File.join @tempdir, 'gems' - @cache_dir = Gem.cache_dir(@gemhome) - + @gems_dir = File.join @tempdir, 'gems' + @cache_dir = File.join @gemhome, 'cache' FileUtils.mkdir @gems_dir - @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end + write_file File.join('gems', 'a-1', 'bin', 'a_bin') do |fp| + fp.puts "#!/usr/bin/ruby" + end + + @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end + @aa1, @aa1_gem = util_gem 'aa', '1' @a1_pre, @a1_pre_gem = util_gem 'a', '1.a' - @b1, @b1_gem = util_gem 'b', '1' do |s| + + @b1, @b1_gem = util_gem 'b', '1' do |s| + s.add_dependency 'a' + s.add_development_dependency 'aa' + end + + @b1_pre, @b1_pre_gem = util_gem 'b', '1.a' do |s| s.add_dependency 'a' s.add_development_dependency 'aa' end - Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new + @c1_pre, @c1_pre_gem = util_gem 'c', '1.a' do |s| + s.add_dependency 'a', '1.a' + s.add_dependency 'b', '1' + end + + @d1, @d1_gem = util_gem 'd', '1' + @d2, @d2_gem = util_gem 'd', '2' + + @x1_m, @x1_m_gem = util_gem 'x', '1' do |s| + s.platform = Gem::Platform.new %w[cpu my_platform 1] + end + + @x1_o, @x1_o_gem = util_gem 'x', '1' do |s| + s.platform = Gem::Platform.new %w[cpu other_platform 1] + end + + @w1, @w1_gem = util_gem 'w', '1', 'x' => nil + + @y1, @y1_gem = util_gem 'y', '1' + @y1_1_p, @y1_1_p_gem = util_gem 'y', '1.1' do |s| + s.platform = Gem::Platform.new %w[cpu my_platform 1] + end + + @z1, @z1_gem = util_gem 'z', '1', 'y' => nil + + @fetcher = Gem::FakeFetcher.new + Gem::RemoteFetcher.fetcher = @fetcher + + util_setup_spec_fetcher(@a1, @a1_pre, @b1, @b1_pre, @c1_pre, @d1, @d2, + @x1_m, @x1_o, @w1, @y1, @y1_1_p, @z1) - util_reset_gems + util_clear_gems end def test_install @@ -82,8 +120,8 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name } - assert Gem.cache_gem(@a1.file_name, @gemhome) - assert Gem.cache_gem(@b1.file_name, @gemhome) + assert File.exist?(File.join(@tempdir, 'cache', @a1.file_name)) + assert File.exist?(File.join(@tempdir, 'cache', @b1.file_name)) end def test_install_dependencies_satisfied @@ -130,10 +168,6 @@ class TestGemDependencyInstaller < Gem::TestCase end def test_install_dependency_development - @aa1, @aa1_gem = util_gem 'aa', '1' - - util_reset_gems - FileUtils.mv @a1_gem, @tempdir FileUtils.mv @aa1_gem, @tempdir FileUtils.mv @b1_gem, @tempdir @@ -287,7 +321,7 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } assert File.exist?(File.join(gemhome2, 'specifications', @a1.spec_name)) - assert File.exist?(Gem.cache_gem(@a1.file_name, gemhome2)) + assert File.exist?(File.join(gemhome2, 'cache', @a1.file_name)) end def test_install_domain_both @@ -342,13 +376,12 @@ class TestGemDependencyInstaller < Gem::TestCase Gem.source_index.remove_spec @a1_pre.full_name Dir.chdir @tempdir do - e = assert_raises Gem::DependencyError do + e = assert_raises Gem::InstallError do inst = Gem::DependencyInstaller.new :domain => :local inst.install 'b' end - expected = "Unable to resolve dependencies: b requires a (>= 0)" - assert_equal expected, e.message + assert_equal 'b requires a (>= 0, runtime)', e.message end assert_equal [], inst.installed_gems.map { |s| s.full_name } @@ -392,22 +425,6 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name } end - def test_install_reinstall - Gem::Installer.new(@a1_gem).install - FileUtils.mv @a1_gem, @tempdir - inst = nil - - Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new - inst.install 'a' - end - - assert_equal Gem::SourceIndex.new(@a1.full_name => @a1), - Gem::SourceIndex.from_installed_gems - - assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } - end - def test_install_remote a1_data = nil File.open @a1_gem, 'rb' do |fp| @@ -443,7 +460,7 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } end - def test_install_remote_platform_newer + def test_install_domain_remote_platform_newer a2_o, a2_o_gem = util_gem 'a', '2' do |s| s.platform = Gem::Platform.new %w[cpu other_platform 1] end @@ -471,6 +488,22 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } end + def test_install_reinstall + Gem::Installer.new(@a1_gem).install + FileUtils.mv @a1_gem, @tempdir + inst = nil + + Dir.chdir @tempdir do + inst = Gem::DependencyInstaller.new + inst.install 'a' + end + + assert_equal Gem::SourceIndex.new(@a1.full_name => @a1), + Gem::SourceIndex.from_installed_gems + + assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } + end + if defined? OpenSSL then def test_install_security_policy data = File.open(@a1_gem, 'rb') { |f| f.read } @@ -506,8 +539,6 @@ class TestGemDependencyInstaller < Gem::TestCase end def test_install_version - util_setup_d - data = File.open(@d2_gem, 'rb') { |f| f.read } @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data @@ -522,8 +553,6 @@ class TestGemDependencyInstaller < Gem::TestCase end def test_install_version_default - util_setup_d - data = File.open(@d2_gem, 'rb') { |f| f.read } @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data @@ -590,22 +619,7 @@ class TestGemDependencyInstaller < Gem::TestCase util_setup_spec_fetcher(*specs) inst = Gem::DependencyInstaller.new - inst.find_spec_by_name_and_version specs.first.name - inst.gather_dependencies - - actual = inst.gems_to_install.map { |s| s.full_name } - assert_equal expected, actual - end - - def assert_resolve_pre expected, *specs - util_clear_gems - - util_setup_spec_fetcher(*specs) - - spec = specs.first - - inst = Gem::DependencyInstaller.new :prerelease => true - inst.find_spec_by_name_and_version spec.name, spec.version + inst.find_spec_by_name_and_version 'a' inst.gather_dependencies actual = inst.gems_to_install.map { |s| s.full_name } @@ -620,182 +634,47 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1 b-1], inst.gems_to_install.map { |s| s.full_name } end - ## - # [A1] depends on - # [B] > 0 (satisfied by 2.0) - # [B1] depends on - # [C] > 0 (satisfied by 1.0) - # [B2] depends on nothing! - # [C1] depends on nothing - - def test_gather_dependencies_dropped - a1, = util_spec 'a', '1', 'b' => nil - b1, = util_spec 'b', '1', 'c' => nil - b2, = util_spec 'b', '2' - c1, = util_spec 'c', '1' - - assert_resolve %w[b-2 a-1], a1, b1, b2, c1 - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 1.1) depends on - # [Z] - # [C] >= 1.0 depends on - # [B] = 1.0 - # - # and should backtrack to resolve using b-1.0, pruning Z from the - # resolve. - - def test_gather_dependencies_raggi_the_edgecase_generator - a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '>= 1.0' - b1, _ = util_spec 'b', '1.0' - b2, _ = util_spec 'b', '1.1', 'z' => '>= 1.0' - c, _ = util_spec 'c', '1.0', 'b' => '= 1.0' - - assert_resolve %w[b-1.0 c-1.0 a-1.0], a, b1, b2, c - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 2.0) - # [C] = 1.0 depends on - # [B] ~> 1.0 - # - # and should resolve using b-1.0 - - def test_gather_dependencies_over - a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '= 1.0' - b1, _ = util_spec 'b', '1.0' - b2, _ = util_spec 'b', '2.0' - c, _ = util_spec 'c', '1.0', 'b' => '~> 1.0' - - assert_resolve %w[b-1.0 c-1.0 a-1.0], a, b1, b2, c - end - - ## - # [A] depends on - # [B] ~> 1.0 (satisfied by 1.1) - # [C] = 1.0 depends on - # [B] = 1.0 - # - # and should resolve using b-1.0 - # - # TODO: this is not under, but over... under would require depth - # first resolve through a dependency that is later pruned. - - def test_gather_dependencies_under - a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0' - b10, _ = util_spec 'b', '1.0' - b11, _ = util_spec 'b', '1.1' - c, _ = util_spec 'c', '1.0', 'b' => '= 1.0' - - assert_resolve %w[b-1.0 c-1.0 a-1.0], a, b10, b11, c - end - - # under - # - # [A] depends on - # [B] ~> 1.0 (satisfied by 1.0) - # [C] = 1.0 depends on - # [B] = 2.0 - - def test_gather_dependencies_divergent - a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0' - b1, _ = util_spec 'b', '1.0' - b2, _ = util_spec 'b', '2.0' - c, _ = util_spec 'c', '1.0', 'b' => '= 2.0' - - assert_raises Gem::DependencyError do - assert_resolve :ignored, a, b1, b2, c - end - end - def test_gather_dependencies_platform_alternate - util_setup_wxyz util_set_arch 'cpu-my_platform1' - assert_resolve %w[x-1-cpu-my_platform-1 w-1], @w1, @x1_m + inst = Gem::DependencyInstaller.new + inst.find_spec_by_name_and_version 'w' + inst.gather_dependencies + + assert_equal %w[x-1-cpu-my_platform-1 w-1], + inst.gems_to_install.map { |s| s.full_name } end def test_gather_dependencies_platform_bump - util_setup_wxyz + inst = Gem::DependencyInstaller.new + inst.find_spec_by_name_and_version 'z' + inst.gather_dependencies - assert_resolve %w[y-1 z-1], @z1, @y1 + assert_equal %w[y-1 z-1], inst.gems_to_install.map { |s| s.full_name } end def test_gather_dependencies_prerelease - util_setup_c1_pre + inst = Gem::DependencyInstaller.new :prerelease => true + inst.find_spec_by_name_and_version 'c', '1.a' + inst.gather_dependencies - assert_resolve_pre %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1 + assert_equal %w[a-1.a b-1 c-1.a], + inst.gems_to_install.map { |s| s.full_name } end def test_gather_dependencies_old_required - util_setup_d - e1, = util_spec 'e', '1', 'd' => '= 1' - util_clear_gems - - assert_resolve %w[d-1 e-1], e1, @d1, @d2 - end - - def util_write_a1_bin - write_file File.join('gems', 'a-1', 'bin', 'a_bin') do |fp| - fp.puts "#!/usr/bin/ruby" - end - end - - def util_setup_c1_pre - @c1_pre, @c1_pre_gem = util_spec 'c', '1.a' do |s| - s.add_dependency 'a', '1.a' - s.add_dependency 'b', '1' - end - - util_reset_gems - end + e1, = util_gem 'e', '1', 'd' => '= 1' - def util_setup_d - @d1, @d1_gem = util_gem 'd', '1' - @d2, @d2_gem = util_gem 'd', '2' - - util_reset_gems - end - - def util_setup_wxyz - @x1_m, @x1_m_gem = util_spec 'x', '1' do |s| - s.platform = Gem::Platform.new %w[cpu my_platform 1] - end - - @x1_o, @x1_o_gem = util_spec 'x', '1' do |s| - s.platform = Gem::Platform.new %w[cpu other_platform 1] - end + util_clear_gems - @w1, @w1_gem = util_spec 'w', '1', 'x' => nil + util_setup_spec_fetcher @d1, @d2, e1 - @y1, @y1_gem = util_spec 'y', '1' - @y1_1_p, @y1_1_p_gem = util_spec 'y', '1.1' do |s| - s.platform = Gem::Platform.new %w[cpu my_platform 1] - end - - @z1, @z1_gem = util_spec 'z', '1', 'y' => nil + inst = Gem::DependencyInstaller.new + inst.find_spec_by_name_and_version 'e' + inst.gather_dependencies - util_reset_gems + assert_equal %w[d-1 e-1], inst.gems_to_install.map { |s| s.full_name } end - def util_reset_gems - @c1_pre ||= nil - @d1 ||= nil - @d2 ||= nil - @w1 ||= nil - @x1_m ||= nil - @x1_o ||= nil - @y1 ||= nil - @y1_1_p ||= nil - @z1 ||= nil - - util_setup_spec_fetcher(*[@a1, @a1_pre, @b1, @c1_pre, - @d1, @d2, @x1_m, @x1_o, @w1, @y1, - @y1_1_p, @z1].compact) - - util_clear_gems - end end + diff --git a/test/rubygems/test_gem_dependency_list.rb b/test/rubygems/test_gem_dependency_list.rb index 688455475b..92966ace08 100644 --- a/test/rubygems/test_gem_dependency_list.rb +++ b/test/rubygems/test_gem_dependency_list.rb @@ -14,17 +14,17 @@ class TestGemDependencyList < Gem::TestCase @deplist = Gem::DependencyList.new - @a1 = quick_spec 'a', '1' - @a2 = quick_spec 'a', '2' - @a3 = quick_spec 'a', '3' + @a1 = quick_gem 'a', '1' + @a2 = quick_gem 'a', '2' + @a3 = quick_gem 'a', '3' - @b1 = quick_spec 'b', '1' do |s| s.add_dependency 'a', '>= 1' end - @b2 = quick_spec 'b', '2' do |s| s.add_dependency 'a', '>= 1' end + @b1 = quick_gem 'b', '1' do |s| s.add_dependency 'a', '>= 1' end + @b2 = quick_gem 'b', '2' do |s| s.add_dependency 'a', '>= 1' end - @c1 = quick_spec 'c', '1' do |s| s.add_dependency 'b', '>= 1' end - @c2 = quick_spec 'c', '2' + @c1 = quick_gem 'c', '1' do |s| s.add_dependency 'b', '>= 1' end + @c2 = quick_gem 'c', '2' - @d1 = quick_spec 'd', '1' do |s| s.add_dependency 'c', '>= 1' end + @d1 = quick_gem 'd', '1' do |s| s.add_dependency 'c', '>= 1' end end def test_self_from_source_index @@ -72,9 +72,9 @@ class TestGemDependencyList < Gem::TestCase end def test_dependency_order_development - e1 = quick_spec 'e', '1' - f1 = quick_spec 'f', '1' - g1 = quick_spec 'g', '1' + e1 = quick_gem 'e', '1' + f1 = quick_gem 'f', '1' + g1 = quick_gem 'g', '1' @a1.add_dependency 'e' @a1.add_dependency 'f' @@ -100,7 +100,7 @@ class TestGemDependencyList < Gem::TestCase def test_dependency_order_diamond util_diamond - e1 = quick_spec 'e', '1' + e1 = quick_gem 'e', '1' @deplist.add e1 @a1.add_dependency 'e', '>= 1' @@ -128,8 +128,6 @@ class TestGemDependencyList < Gem::TestCase end def test_ok_eh - util_clear_gems - assert @deplist.ok?, 'no dependencies' @deplist.add @b2 @@ -141,30 +139,14 @@ class TestGemDependencyList < Gem::TestCase assert @deplist.ok?, 'satisfied dependency' end - def test_why_not_ok_eh - util_clear_gems - - assert_equal({}, @deplist.why_not_ok?) - - @deplist.add @b2 - - exp = { - "b" => [ - Gem::Dependency.new("a", ">= 1") - ] - } - - assert_equal exp, @deplist.why_not_ok? - end - def test_ok_eh_mismatch - a1 = quick_spec 'a', '1' - a2 = quick_spec 'a', '2' + a1 = quick_gem 'a', '1' + a2 = quick_gem 'a', '2' - b = quick_spec 'b', '1' do |s| s.add_dependency 'a', '= 1' end - c = quick_spec 'c', '1' do |s| s.add_dependency 'a', '= 2' end + b = quick_gem 'b', '1' do |s| s.add_dependency 'a', '= 1' end + c = quick_gem 'c', '1' do |s| s.add_dependency 'a', '= 2' end - d = quick_spec 'd', '1' do |s| + d = quick_gem 'd', '1' do |s| s.add_dependency 'b' s.add_dependency 'c' end @@ -210,8 +192,6 @@ class TestGemDependencyList < Gem::TestCase end def test_remove_by_name - util_clear_gems - @deplist.add @a1, @b2 @deplist.remove_by_name "a-1" diff --git a/test/rubygems/test_gem_doc_manager.rb b/test/rubygems/test_gem_doc_manager.rb index f52f1f87f1..be4c12bd5b 100644 --- a/test/rubygems/test_gem_doc_manager.rb +++ b/test/rubygems/test_gem_doc_manager.rb @@ -12,26 +12,25 @@ class TestGemDocManager < Gem::TestCase def setup super - @spec = quick_gem 'a', 2 + @spec = quick_gem 'a' @manager = Gem::DocManager.new(@spec) end def test_uninstall_doc_unwritable - path = @spec.installation_path - orig_mode = File.stat(path).mode + orig_mode = File.stat(@spec.installation_path).mode # File.chmod has no effect on MS Windows directories (it needs ACL). if win_platform? skip("test_uninstall_doc_unwritable skipped on MS Windows") else - File.chmod 0000, path + File.chmod(0, @spec.installation_path) end assert_raises Gem::FilePermissionError do @manager.uninstall_doc end ensure - File.chmod orig_mode, path + File.chmod orig_mode, @spec.installation_path end end diff --git a/test/rubygems/test_gem_format.rb b/test/rubygems/test_gem_format.rb index 6f169588eb..f964cab143 100644 --- a/test/rubygems/test_gem_format.rb +++ b/test/rubygems/test_gem_format.rb @@ -5,7 +5,7 @@ ###################################################################### require 'rubygems/package/tar_test_case' -require 'rubygems/simple_gem' +require 'test/rubygems/simple_gem' require 'rubygems/format' class TestGemFormat < Gem::Package::TarTestCase @@ -20,7 +20,7 @@ class TestGemFormat < Gem::Package::TarTestCase def test_class_from_file_by_path util_make_gems - gems = Dir[Gem.cache_gem('*.gem', @gemhome)] + gems = Dir[File.join(@gemhome, 'cache', '*.gem')] names = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].map do |spec| spec.original_name diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb index 71fb965460..a7f49506a6 100644 --- a/test/rubygems/test_gem_indexer.rb +++ b/test/rubygems/test_gem_indexer.rb @@ -18,20 +18,21 @@ class TestGemIndexer < Gem::TestCase util_make_gems - @d2_0 = quick_spec 'd', '2.0' do |s| + @d2_0 = quick_gem 'd', '2.0' do |s| s.date = Gem::Specification::TODAY - 86400 * 3 end util_build_gem @d2_0 - @d2_0_a = quick_spec 'd', '2.0.a' + @d2_0_a = quick_gem 'd', '2.0.a' util_build_gem @d2_0_a - @d2_0_b = quick_spec 'd', '2.0.b' + @d2_0_b = quick_gem 'd', '2.0.b' util_build_gem @d2_0_b gems = File.join(@tempdir, 'gems') FileUtils.mkdir_p gems - FileUtils.mv Dir[Gem.cache_gem('*.gem', @gemhome)], gems + cache_gems = File.join @gemhome, 'cache', '*.gem' + FileUtils.mv Dir[cache_gems], gems @indexer = Gem::Indexer.new @tempdir, :rss_title => 'ExampleForge gems', :rss_host => 'example.com', @@ -59,7 +60,7 @@ class TestGemIndexer < Gem::TestCase end def test_build_indicies - spec = quick_spec 'd', '2.0' + spec = quick_gem 'd', '2.0' spec.instance_variable_set :@original_platform, '' @indexer.make_temp_directories @@ -509,17 +510,17 @@ eighty characters.</pre> assert File.directory?(quickdir) assert File.directory?(marshal_quickdir) - @d2_1 = quick_spec 'd', '2.1' + @d2_1 = quick_gem 'd', '2.1' util_build_gem @d2_1 @d2_1_tuple = [@d2_1.name, @d2_1.version, @d2_1.original_platform] - @d2_1_a = quick_spec 'd', '2.2.a' + @d2_1_a = quick_gem 'd', '2.2.a' util_build_gem @d2_1_a @d2_1_a_tuple = [@d2_1_a.name, @d2_1_a.version, @d2_1_a.original_platform] gems = File.join @tempdir, 'gems' - FileUtils.mv Gem.cache_gem(@d2_1.file_name, @gemhome), gems - FileUtils.mv Gem.cache_gem(@d2_1_a.file_name, @gemhome), gems + FileUtils.mv File.join(@gemhome, 'cache', @d2_1.file_name), gems + FileUtils.mv File.join(@gemhome, 'cache', @d2_1_a.file_name), gems use_ui @ui do @indexer.update_index diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index fe10fd4949..937774617f 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -69,4 +69,6 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase ensure FileUtils.chmod 0755, @gemhome end + end + diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 0b73af996d..94fa4423bc 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -9,8 +9,7 @@ require 'rubygems/installer_test_case' class TestGemInstaller < Gem::InstallerTestCase def test_app_script_text - @spec.version = 2 - util_make_exec @spec, '' + util_make_exec '2', '' expected = <<-EOF #!#{Gem.ruby} @@ -31,10 +30,10 @@ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then end gem 'a', version -load Gem.bin_path('a', 'executable', version) +load Gem.bin_path('a', 'my_exec', version) EOF - wrapper = @installer.app_script_text 'executable' + wrapper = @installer.app_script_text 'my_exec' assert_equal expected, wrapper end @@ -102,7 +101,7 @@ load Gem.bin_path('a', 'executable', version) @installer.ensure_dependency @spec, dep end - assert_equal 'a requires b (> 2)', e.message + assert_equal 'a requires b (> 2, runtime)', e.message end def test_extract_files @@ -171,11 +170,11 @@ load Gem.bin_path('a', 'executable', version) def test_generate_bin_bindir @installer.wrappers = true - @spec.executables = %w[executable] + @spec.executables = ["my_exec"] @spec.bindir = '.' - exec_file = @installer.formatted_program_filename 'executable' - exec_path = File.join util_gem_dir(@spec), exec_file + exec_file = @installer.formatted_program_filename "my_exec" + exec_path = File.join util_gem_dir(@spec.version), exec_file File.open exec_path, 'w' do |f| f.puts '#!/usr/bin/ruby' end @@ -185,7 +184,7 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") assert_equal true, File.exist?(installed_exec) assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? @@ -200,7 +199,7 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") assert_equal true, File.exist?(installed_exec) assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? @@ -217,7 +216,7 @@ load Gem.bin_path('a', 'executable', version) Gem::Installer.exec_format = 'foo-%s-bar' @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join util_inst_bindir, 'foo-executable-bar' + installed_exec = File.join util_inst_bindir, 'foo-my_exec-bar' assert_equal true, File.exist?(installed_exec) ensure Gem::Installer.exec_format = nil @@ -231,7 +230,7 @@ load Gem.bin_path('a', 'executable', version) Gem::Installer.exec_format = 'foo-%s-bar' @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join util_inst_bindir, 'executable' + installed_exec = File.join util_inst_bindir, 'my_exec' assert_equal true, File.exist?(installed_exec) ensure Gem::Installer.exec_format = nil @@ -239,12 +238,12 @@ load Gem.bin_path('a', 'executable', version) def test_generate_bin_script_install_dir @installer.wrappers = true - @spec.executables = %w[executable] + @spec.executables = ["my_exec"] gem_dir = File.join "#{@gemhome}2", 'gems', @spec.full_name gem_bindir = File.join gem_dir, 'bin' FileUtils.mkdir_p gem_bindir - File.open File.join(gem_bindir, 'executable'), 'w' do |f| + File.open File.join(gem_bindir, "my_exec"), 'w' do |f| f.puts "#!/bin/ruby" end @@ -253,7 +252,7 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin - installed_exec = File.join("#{@gemhome}2", 'bin', 'executable') + installed_exec = File.join("#{@gemhome}2", 'bin', 'my_exec') assert_equal true, File.exist?(installed_exec) assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? @@ -262,12 +261,9 @@ load Gem.bin_path('a', 'executable', version) end def test_generate_bin_script_no_execs - util_execless - @installer.wrappers = true @installer.generate_bin - - refute File.exist?(util_inst_bindir), 'bin dir was created when not needed' + assert_equal false, File.exist?(util_inst_bindir) end def test_generate_bin_script_no_perms @@ -291,18 +287,18 @@ load Gem.bin_path('a', 'executable', version) def test_generate_bin_script_no_shebang @installer.wrappers = true - @spec.executables = %w[executable] + @spec.executables = ["my_exec"] gem_dir = File.join @gemhome, 'gems', @spec.full_name gem_bindir = File.join gem_dir, 'bin' FileUtils.mkdir_p gem_bindir - File.open File.join(gem_bindir, 'executable'), 'w' do |f| + File.open File.join(gem_bindir, "my_exec"), 'w' do |f| f.puts "blah blah blah" end @installer.generate_bin - installed_exec = File.join @gemhome, 'bin', 'executable' + installed_exec = File.join @gemhome, 'bin', 'my_exec' assert_equal true, File.exist?(installed_exec) assert_equal 0100755, File.stat(installed_exec).mode unless win_platform? @@ -316,9 +312,9 @@ load Gem.bin_path('a', 'executable', version) @installer.wrappers = true util_make_exec @installer.gem_dir = util_gem_dir - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") - real_exec = File.join util_gem_dir, 'bin', 'executable' + real_exec = File.join util_gem_dir, 'bin', 'my_exec' # fake --no-wrappers for previous install unless Gem.win_platform? then @@ -346,19 +342,16 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") assert_equal true, File.symlink?(installed_exec) - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + assert_equal(File.join(util_gem_dir, "bin", "my_exec"), File.readlink(installed_exec)) end def test_generate_bin_symlink_no_execs - util_execless - @installer.wrappers = false @installer.generate_bin - - refute File.exist?(util_inst_bindir) + assert_equal false, File.exist?(util_inst_bindir) end def test_generate_bin_symlink_no_perms @@ -389,8 +382,8 @@ load Gem.bin_path('a', 'executable', version) @installer.gem_dir = util_gem_dir @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + installed_exec = File.join(util_inst_bindir, "my_exec") + assert_equal(File.join(util_gem_dir, "bin", "my_exec"), File.readlink(installed_exec)) @spec = Gem::Specification.new do |s| @@ -402,12 +395,11 @@ load Gem.bin_path('a', 'executable', version) s.require_path = 'lib' end - @spec.version = 3 - util_make_exec - @installer.gem_dir = File.join util_gem_dir @spec + util_make_exec '3' + @installer.gem_dir = File.join util_gem_dir('3') @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_bindir(@spec), 'executable'), + installed_exec = File.join(util_inst_bindir, "my_exec") + assert_equal(File.join(util_gem_bindir('3'), "my_exec"), File.readlink(installed_exec), "Ensure symlink moved to latest version") end @@ -420,8 +412,8 @@ load Gem.bin_path('a', 'executable', version) @installer.gem_dir = util_gem_dir @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + installed_exec = File.join(util_inst_bindir, "my_exec") + assert_equal(File.join(util_gem_dir, "bin", "my_exec"), File.readlink(installed_exec)) spec = Gem::Specification.new do |s| @@ -433,16 +425,14 @@ load Gem.bin_path('a', 'executable', version) s.require_path = 'lib' end - util_make_exec - one = @spec.dup - one.version = 1 - @installer.gem_dir = util_gem_dir one + util_make_exec '1' + @installer.gem_dir = util_gem_dir('1') @installer.spec = spec @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + installed_exec = File.join(util_inst_bindir, "my_exec") + assert_equal(File.join(util_gem_dir('2'), "bin", "my_exec"), File.readlink(installed_exec), "Ensure symlink not moved") end @@ -455,7 +445,7 @@ load Gem.bin_path('a', 'executable', version) @installer.gem_dir = util_gem_dir @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") assert_equal true, File.exist?(installed_exec) @spec = Gem::Specification.new do |s| @@ -468,12 +458,11 @@ load Gem.bin_path('a', 'executable', version) end @installer.wrappers = false - @spec.version = 3 - util_make_exec - @installer.gem_dir = util_gem_dir + util_make_exec '3' + @installer.gem_dir = util_gem_dir '3' @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + installed_exec = File.join(util_inst_bindir, "my_exec") + assert_equal(File.join(util_gem_dir('3'), "bin", "my_exec"), File.readlink(installed_exec), "Ensure symlink moved to latest version") end @@ -490,7 +479,7 @@ load Gem.bin_path('a', 'executable', version) end assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") assert_equal true, File.exist?(installed_exec) assert_match(/Unable to use symlinks on Windows, installing wrapper/i, @@ -511,18 +500,19 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin default_shebang = Gem.ruby - shebang_line = open("#{@gemhome}/bin/executable") { |f| f.readlines.first } + shebang_line = open("#{@gemhome}/bin/my_exec") { |f| f.readlines.first } assert_match(/\A#!/, shebang_line) assert_match(/#{default_shebang}/, shebang_line) end def test_initialize - spec = quick_spec 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end + spec = quick_gem 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end gem = File.join @tempdir, spec.file_name Dir.mkdir util_inst_bindir util_build_gem spec - FileUtils.mv Gem.cache_gem(spec.file_name, @gemhome), @tempdir + FileUtils.mv File.join(@gemhome, 'cache', spec.file_name), + @tempdir installer = Gem::Installer.new gem @@ -535,7 +525,7 @@ load Gem.bin_path('a', 'executable', version) util_clear_gems gemdir = File.join @gemhome, 'gems', @spec.full_name - cache_file = Gem.cache_gem(@spec.file_name, @gemhome) + cache_file = File.join @gemhome, 'cache', @spec.file_name stub_exe = File.join @gemhome, 'bin', 'executable' rakefile = File.join gemdir, 'ext', 'a', 'Rakefile' @@ -584,42 +574,6 @@ load Gem.bin_path('a', 'executable', version) assert_same @installer, @pre_install_hook_arg end - def test_install_with_no_prior_files - Dir.mkdir util_inst_bindir - util_clear_gems - - util_setup_gem - build_rake_in do - use_ui @ui do - assert_equal @spec, @installer.install - end - end - - gemdir = File.join(@gemhome, 'gems', @spec.full_name) - assert File.exist?(File.join(gemdir, 'lib', 'code.rb')) - - util_setup_gem - # Morph spec to have lib/other.rb instead of code.rb and recreate - @spec.files = File.join('lib', 'other.rb') - Dir.chdir @tempdir do - File.open File.join('lib', 'other.rb'), 'w' do |f| f.puts '1' end - use_ui ui do - FileUtils.rm @gem - Gem::Builder.new(@spec).build - end - end - @installer = Gem::Installer.new @gem - build_rake_in do - use_ui @ui do - assert_equal @spec, @installer.install - end - end - - assert File.exist?(File.join(gemdir, 'lib', 'other.rb')) - refute(File.exist?(File.join(gemdir, 'lib', 'code.rb')), - "code.rb from prior install of same gem shouldn't remain here") - end - def test_install_bad_gem gem = nil @@ -656,7 +610,7 @@ load Gem.bin_path('a', 'executable', version) gemhome2 = "#{@gemhome}2" @spec.add_dependency 'b' - b2 = quick_spec 'b', 2 + b2 = quick_gem 'b', 2 FileUtils.mv @gemhome, gemhome2 Gem.source_index.gems.delete b2.full_name @@ -712,7 +666,7 @@ load Gem.bin_path('a', 'executable', version) end def test_install_missing_dirs - FileUtils.rm_f Gem.cache_dir + FileUtils.rm_f File.join(Gem.dir, 'cache') FileUtils.rm_f File.join(Gem.dir, 'docs') FileUtils.rm_f File.join(Gem.dir, 'specifications') @@ -722,11 +676,11 @@ load Gem.bin_path('a', 'executable', version) @installer.install end - File.directory? Gem.cache_dir + File.directory? File.join(Gem.dir, 'cache') File.directory? File.join(Gem.dir, 'docs') File.directory? File.join(Gem.dir, 'specifications') - assert File.exist?(Gem.cache_gem(@spec.file_name, @gemhome)) + assert File.exist?(File.join(@gemhome, 'cache', @spec.file_name)) assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name)) end @@ -832,13 +786,13 @@ load Gem.bin_path('a', 'executable', version) end def test_install_wrong_rubygems_version - spec = quick_spec 'old_rubygems_required', '1' do |s| + spec = quick_gem 'old_rubygems_required', '1' do |s| s.required_rubygems_version = '< 0' end util_build_gem spec - gem = Gem.cache_gem(spec.file_name, @gemhome) + gem = File.join @gemhome, 'cache', spec.file_name use_ui @ui do @installer = Gem::Installer.new gem @@ -859,49 +813,49 @@ load Gem.bin_path('a', 'executable', version) end def test_shebang - util_make_exec @spec, "#!/usr/bin/ruby" + util_make_exec '2', "#!/usr/bin/ruby" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_arguments - util_make_exec @spec, "#!/usr/bin/ruby -ws" + util_make_exec '2', "#!/usr/bin/ruby -ws" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_empty - util_make_exec @spec, '' + util_make_exec '2', '' - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_env - util_make_exec @spec, "#!/usr/bin/env ruby" + util_make_exec '2', "#!/usr/bin/env ruby" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_env_arguments - util_make_exec @spec, "#!/usr/bin/env ruby -ws" + util_make_exec '2', "#!/usr/bin/env ruby -ws" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_env_shebang - util_make_exec @spec, '' + util_make_exec '2', '' @installer.env_shebang = true - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' env_shebang = "/usr/bin/env" unless Gem.win_platform? @@ -910,49 +864,49 @@ load Gem.bin_path('a', 'executable', version) end def test_shebang_nested - util_make_exec @spec, "#!/opt/local/ruby/bin/ruby" + util_make_exec '2', "#!/opt/local/ruby/bin/ruby" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_nested_arguments - util_make_exec @spec, "#!/opt/local/ruby/bin/ruby -ws" + util_make_exec '2', "#!/opt/local/ruby/bin/ruby -ws" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_version - util_make_exec @spec, "#!/usr/bin/ruby18" + util_make_exec '2', "#!/usr/bin/ruby18" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_version_arguments - util_make_exec @spec, "#!/usr/bin/ruby18 -ws" + util_make_exec '2', "#!/usr/bin/ruby18 -ws" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_version_env - util_make_exec @spec, "#!/usr/bin/env ruby18" + util_make_exec '2', "#!/usr/bin/env ruby18" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_version_env_arguments - util_make_exec @spec, "#!/usr/bin/env ruby18 -ws" + util_make_exec '2', "#!/usr/bin/env ruby18 -ws" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby} -ws", shebang end @@ -983,41 +937,14 @@ load Gem.bin_path('a', 'executable', version) assert_equal @spec, eval(File.read(spec_file)) end - def test_write_spec_writes_cached_spec - spec_dir = File.join @gemhome, 'specifications' - spec_file = File.join spec_dir, @spec.spec_name - FileUtils.rm spec_file - refute File.exist?(spec_file) - - @spec.files = %w[a.rb b.rb c.rb] - - @installer.spec = @spec - @installer.gem_home = @gemhome - - @installer.write_spec - - # cached specs have no file manifest: - @spec.files = [] - - assert_equal @spec, eval(File.read(spec_file)) - end - def old_ruby_required - spec = quick_spec 'old_ruby_required', '1' do |s| + spec = quick_gem 'old_ruby_required', '1' do |s| s.required_ruby_version = '= 1.4.6' end util_build_gem spec - Gem.cache_gem(spec.file_name, @gemhome) - end - - def util_execless - @spec = quick_spec 'z' - - gem = File.join @tempdir, @spec.file_name - - @installer = util_installer @spec, gem, @gemhome + File.join @gemhome, 'cache', spec.file_name end end diff --git a/test/rubygems/test_gem_package_tar_output.rb b/test/rubygems/test_gem_package_tar_output.rb index 77f31852f9..7458a749dd 100644 --- a/test/rubygems/test_gem_package_tar_output.rb +++ b/test/rubygems/test_gem_package_tar_output.rb @@ -55,9 +55,6 @@ class TestGemPackageTarOutput < Gem::Package::TarTestCase if defined? OpenSSL then def test_self_open_signed - @private_key = File.expand_path('test/rubygems/private_key.pem', @@project_dir) - @public_cert = File.expand_path('test/rubygems/public_cert.pem', @@project_dir) - signer = Gem::Security::Signer.new @private_key, [@public_cert] open @file, 'wb' do |tar_io| diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index 66fb682c6c..135b2c7e53 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -99,10 +99,9 @@ gems: # REFACTOR: copied from test_gem_dependency_installer.rb @gems_dir = File.join @tempdir, 'gems' - @cache_dir = Gem.cache_dir(@gemhome) + @cache_dir = File.join @gemhome, 'cache' FileUtils.mkdir @gems_dir - # TODO: why does the remote fetcher need it written to disk? @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end Gem::RemoteFetcher.fetcher = nil @@ -209,7 +208,7 @@ gems: fetcher = util_fuck_with_fetcher a1_data - a1_cache_gem = Gem.cache_gem(@a1.file_name, @gemhome) + a1_cache_gem = File.join(@gemhome, 'cache', @a1.file_name) assert_equal a1_cache_gem, fetcher.download(@a1, 'http://gems.example.com') assert_equal("http://gems.example.com/gems/a-1.gem", fetcher.instance_variable_get(:@test_arg).to_s) @@ -221,7 +220,7 @@ gems: inst = Gem::RemoteFetcher.fetcher - assert_equal Gem.cache_gem(@a1.file_name, @gemhome), + assert_equal File.join(@gemhome, 'cache', @a1.file_name), inst.download(@a1, 'http://gems.example.com') end @@ -234,7 +233,7 @@ gems: inst = Gem::RemoteFetcher.fetcher end - assert_equal Gem.cache_gem(@a1.file_name, @gemhome), + assert_equal File.join(@gemhome, 'cache', @a1.file_name), inst.download(@a1, local_path) end @@ -249,7 +248,7 @@ gems: inst = Gem::RemoteFetcher.fetcher end - assert_equal Gem.cache_gem(@a1.file_name, @gemhome), + assert_equal File.join(@gemhome, 'cache', @a1.file_name), inst.download(@a1, local_path) end @@ -263,7 +262,7 @@ gems: install_dir = File.join @tempdir, 'more_gems' - a1_cache_gem = Gem.cache_gem(@a1.file_name, install_dir) + a1_cache_gem = File.join install_dir, 'cache', @a1.file_name FileUtils.mkdir_p(File.dirname(a1_cache_gem)) actual = fetcher.download(@a1, 'http://gems.example.com', install_dir) @@ -279,7 +278,7 @@ gems: FileUtils.mv @a1_gem, @tempdir local_path = File.join @tempdir, @a1.file_name inst = nil - File.chmod 0555, Gem.cache_dir(@gemhome) + File.chmod 0555, File.join(@gemhome, 'cache') Dir.chdir @tempdir do inst = Gem::RemoteFetcher.fetcher @@ -288,19 +287,19 @@ gems: assert_equal File.join(@tempdir, @a1.file_name), inst.download(@a1, local_path) ensure - File.chmod 0755, Gem.cache_dir(@gemhome) + File.chmod 0755, File.join(@gemhome, 'cache') end def test_download_read_only - File.chmod 0555, Gem.cache_dir(@gemhome) + File.chmod 0555, File.join(@gemhome, 'cache') File.chmod 0555, File.join(@gemhome) fetcher = util_fuck_with_fetcher File.read(@a1_gem) fetcher.download(@a1, 'http://gems.example.com') - assert File.exist?(Gem.cache_gem(@a1.file_name, Gem.user_dir)) + assert File.exist?(File.join(Gem.user_dir, 'cache', @a1.file_name)) ensure - File.chmod 0755, @gemhome - File.chmod 0755, Gem.cache_dir(@gemhome) + File.chmod 0755, File.join(@gemhome) + File.chmod 0755, File.join(@gemhome, 'cache') end end @@ -319,7 +318,7 @@ gems: fetcher = util_fuck_with_fetcher e1_data, :blow_chunks - e1_cache_gem = Gem.cache_gem(e1.file_name, @gemhome) + e1_cache_gem = File.join(@gemhome, 'cache', e1.file_name) assert_equal e1_cache_gem, fetcher.download(e1, 'http://gems.example.com') @@ -337,7 +336,7 @@ gems: inst = Gem::RemoteFetcher.fetcher end - cache_path = Gem.cache_gem(@a1.file_name, @gemhome) + cache_path = File.join @gemhome, 'cache', @a1.file_name FileUtils.mv local_path, cache_path gem = Gem::Format.from_file_by_path cache_path @@ -745,13 +744,5 @@ gems: end end - def test_correct_for_windows_path - path = "/C:/WINDOWS/Temp/gems" - assert_equal "C:/WINDOWS/Temp/gems", @fetcher.correct_for_windows_path(path) - - path = "/home/skillet" - assert_equal "/home/skillet", @fetcher.correct_for_windows_path(path) - end - end diff --git a/test/rubygems/test_gem_source_index.rb b/test/rubygems/test_gem_source_index.rb index 89e2ea3894..9846c9cc89 100644 --- a/test/rubygems/test_gem_source_index.rb +++ b/test/rubygems/test_gem_source_index.rb @@ -23,7 +23,7 @@ class TestGemSourceIndex < Gem::TestCase FileUtils.mkdir_p spec_dir - a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end + a1 = quick_gem 'a', '1' do |spec| spec.author = 'author 1' end spec_file = File.join spec_dir, a1.spec_name @@ -44,7 +44,7 @@ class TestGemSourceIndex < Gem::TestCase FileUtils.mkdir_p spec_dir - a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end + a1 = quick_gem 'a', '1' do |spec| spec.author = 'author 1' end spec_file = File.join spec_dir, a1.spec_name @@ -214,24 +214,24 @@ end end def test_latest_specs - p1_ruby = quick_spec 'p', '1' - p1_platform = quick_spec 'p', '1' do |spec| + p1_ruby = quick_gem 'p', '1' + p1_platform = quick_gem 'p', '1' do |spec| spec.platform = Gem::Platform::CURRENT end - a1_platform = quick_spec @a1.name, (@a1.version) do |s| + a1_platform = quick_gem @a1.name, (@a1.version) do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end - a2_platform = quick_spec @a2.name, (@a2.version) do |s| + a2_platform = quick_gem @a2.name, (@a2.version) do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end - a2_platform_other = quick_spec @a2.name, (@a2.version) do |s| + a2_platform_other = quick_gem @a2.name, (@a2.version) do |s| s.platform = Gem::Platform.new 'x86-other_platform1' end - a3_platform_other = quick_spec @a2.name, (@a2.version.bump) do |s| + a3_platform_other = quick_gem @a2.name, (@a2.version.bump) do |s| s.platform = Gem::Platform.new 'x86-other_platform1' end @@ -266,8 +266,8 @@ end FileUtils.mkdir_p spec_dir1 FileUtils.mkdir_p spec_dir2 - a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end - a2 = quick_spec 'a', '1' do |spec| spec.author = 'author 2' end + a1 = quick_gem 'a', '1' do |spec| spec.author = 'author 1' end + a2 = quick_gem 'a', '1' do |spec| spec.author = 'author 2' end File.open File.join(spec_dir1, a1.spec_name), 'w' do |fp| fp.write a1.to_ruby @@ -287,12 +287,12 @@ end assert_equal [], @source_index.outdated - updated = quick_spec @a2.name, (@a2.version.bump) + updated = quick_gem @a2.name, (@a2.version.bump) util_setup_spec_fetcher updated assert_equal [updated.name], @source_index.outdated - updated_platform = quick_spec @a2.name, (updated.version.bump) do |s| + updated_platform = quick_gem @a2.name, (updated.version.bump) do |s| s.platform = Gem::Platform.new 'x86-other_platform1' end @@ -302,11 +302,10 @@ end end def test_prerelease_specs_kept_in_right_place - gem_a1_alpha = quick_spec 'abba', '1.a' + gem_a1_alpha = quick_gem 'abba', '1.a' @source_index.add_spec gem_a1_alpha refute @source_index.latest_specs.include?(gem_a1_alpha) - assert @source_index.latest_specs(true).include?(gem_a1_alpha) assert @source_index.find_name(gem_a1_alpha.full_name).empty? assert @source_index.prerelease_specs.include?(gem_a1_alpha) end @@ -364,11 +363,11 @@ end def test_search_platform util_set_arch 'x86-my_platform1' - a1 = quick_spec 'a', '1' - a1_mine = quick_spec 'a', '1' do |s| + a1 = quick_gem 'a', '1' + a1_mine = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end - a1_other = quick_spec 'a', '1' do |s| + a1_other = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.new 'x86-other_platform1' end diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb index 57983a2752..6e3891b866 100644 --- a/test/rubygems/test_gem_spec_fetcher.rb +++ b/test/rubygems/test_gem_spec_fetcher.rb @@ -16,7 +16,7 @@ class TestGemSpecFetcher < Gem::TestCase util_setup_fake_fetcher - @a_pre = quick_spec 'a', '1.a' + @a_pre = quick_gem 'a', '1.a' @source_index.add_spec @pl1 @source_index.add_spec @a_pre @@ -412,10 +412,5 @@ class TestGemSpecFetcher < Gem::TestCase assert_equal @latest_specs, latest_specs end - def test_cache_dir_escapes_windows_paths - uri = URI.parse("file:///C:/WINDOWS/Temp/gem_repo") - cache_dir = @sf.cache_dir(uri) - assert cache_dir !~ /:/, "#{cache_dir} should not contain a :" - end end diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index f820d7c1c3..49862fe4bb 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -46,7 +46,6 @@ end def setup super - # TODO: there is no reason why the spec tests need to write to disk @a1 = quick_gem 'a', '1' do |s| s.executable = 'exec' s.extensions << 'ext/a/extconf.rb' @@ -168,13 +167,6 @@ end Gem::Specification.normalize_yaml_input(StringIO.new(input)) end - def test_self_normalize_yaml_input_with_192_yaml - input = "--- !ruby/object:Gem::Specification \nblah: !!null \n" - expected = "--- !ruby/object:Gem::Specification \nblah: \n" - - assert_equal expected, Gem::Specification.normalize_yaml_input(input) - end - def test_initialize spec = Gem::Specification.new do |s| s.name = "blah" @@ -302,7 +294,7 @@ end end def test_add_dependency_with_explicit_type - gem = quick_spec "awesome", "1.0" do |awesome| + gem = quick_gem "awesome", "1.0" do |awesome| awesome.add_development_dependency "monkey" end @@ -379,19 +371,18 @@ end assert_equal [rake, jabber, pqa], @a1.dependencies end - def test_dependencies - util_setup_deps - assert_equal [@bonobo, @monkey], @gem.dependencies - end + def test_dependencies_scoped_by_type + gem = quick_gem "awesome", "1.0" do |awesome| + awesome.add_runtime_dependency "bonobo", [] + awesome.add_development_dependency "monkey", [] + end - def test_runtime_dependencies - util_setup_deps - assert_equal [@bonobo], @gem.runtime_dependencies - end + bonobo = Gem::Dependency.new("bonobo", []) + monkey = Gem::Dependency.new("monkey", [], :development) - def test_development_dependencies - util_setup_deps - assert_equal [@monkey], @gem.development_dependencies + assert_equal([bonobo, monkey], gem.dependencies) + assert_equal([bonobo], gem.runtime_dependencies) + assert_equal([monkey], gem.development_dependencies) end def test_description @@ -399,8 +390,8 @@ end end def test_eql_eh - g1 = quick_spec 'gem' - g2 = quick_spec 'gem' + g1 = quick_gem 'gem' + g2 = quick_gem 'gem' assert_equal g1, g2 assert_equal g1.hash, g2.hash @@ -699,7 +690,7 @@ end end def test_prerelease_spec_adds_required_rubygems_version - @prerelease = quick_spec('tardis', '2.2.0.a') + @prerelease = quick_gem('tardis', '2.2.0.a') refute @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.3.1')) assert @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.4.0')) end @@ -725,8 +716,8 @@ end end def test_spaceship_name - s1 = quick_spec 'a', '1' - s2 = quick_spec 'b', '1' + s1 = quick_gem 'a', '1' + s2 = quick_gem 'b', '1' assert_equal(-1, (s1 <=> s2)) assert_equal( 0, (s1 <=> s1)) @@ -734,8 +725,8 @@ end end def test_spaceship_platform - s1 = quick_spec 'a', '1' - s2 = quick_spec 'a', '1' do |s| + s1 = quick_gem 'a', '1' + s2 = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end @@ -745,8 +736,8 @@ end end def test_spaceship_version - s1 = quick_spec 'a', '1' - s2 = quick_spec 'a', '2' + s1 = quick_gem 'a', '1' + s2 = quick_gem 'a', '2' assert_equal( -1, (s1 <=> s2)) assert_equal( 0, (s1 <=> s1)) @@ -812,54 +803,6 @@ end assert_equal @a2, same_spec end - def test_to_ruby_for_cache - @a2.add_runtime_dependency 'b', '1' - @a2.dependencies.first.instance_variable_set :@type, nil - @a2.required_rubygems_version = Gem::Requirement.new '> 0' - - # cached specs do not have spec.files populated: - ruby_code = @a2.to_ruby_for_cache - - expected = <<-SPEC -# -*- encoding: utf-8 -*- - -Gem::Specification.new do |s| - s.name = %q{a} - s.version = \"2\" - - s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version= - s.authors = [\"A User\"] - s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}} - s.description = %q{This is a test description} - s.email = %q{example@example.com} - s.homepage = %q{http://example.com} - s.require_paths = [\"lib\"] - s.rubygems_version = %q{#{Gem::VERSION}} - s.summary = %q{this is a summary} - - if s.respond_to? :specification_version then - s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION} - - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [\"= 1\"]) - else - s.add_dependency(%q, [\"= 1\"]) - end - else - s.add_dependency(%q, [\"= 1\"]) - end -end - SPEC - - assert_equal expected, ruby_code - - same_spec = eval ruby_code - - # cached specs do not have spec.files populated: - @a2.files = [] - assert_equal @a2, same_spec - end - def test_to_ruby_fancy @a1.platform = Gem::Platform.local ruby_code = @a1.to_ruby @@ -899,16 +842,16 @@ Gem::Specification.new do |s| if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, [\"> 0.4\"]) s.add_runtime_dependency(%q, [\"> 0.0.0\"]) - s.add_runtime_dependency(%q, [\"<= 0.6\", \"> 0.4\"]) + s.add_runtime_dependency(%q, [\"> 0.4\", \"<= 0.6\"]) else s.add_dependency(%q, [\"> 0.4\"]) s.add_dependency(%q, [\"> 0.0.0\"]) - s.add_dependency(%q, [\"<= 0.6\", \"> 0.4\"]) + s.add_dependency(%q, [\"> 0.4\", \"<= 0.6\"]) end else s.add_dependency(%q, [\"> 0.4\"]) s.add_dependency(%q, [\"> 0.0.0\"]) - s.add_dependency(%q, [\"<= 0.6\", \"> 0.4\"]) + s.add_dependency(%q, [\"> 0.4\", \"<= 0.6\"]) end end SPEC @@ -941,9 +884,6 @@ end def test_to_yaml yaml_str = @a1.to_yaml - - refute_match '!!null', yaml_str - same_spec = YAML.load(yaml_str) assert_equal @a1, same_spec @@ -1318,16 +1258,6 @@ end specfile.delete end - def util_setup_deps - @gem = quick_spec "awesome", "1.0" do |awesome| - awesome.add_runtime_dependency "bonobo", [] - awesome.add_development_dependency "monkey", [] - end - - @bonobo = Gem::Dependency.new("bonobo", []) - @monkey = Gem::Dependency.new("monkey", [], :development) - end - def util_setup_validate Dir.chdir @tempdir do FileUtils.mkdir_p File.join('ext', 'a') @@ -1339,4 +1269,6 @@ end FileUtils.touch File.join('test', 'suite.rb') end end + end + diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb index 0c08f42d01..3925ab1a63 100644 --- a/test/rubygems/test_gem_uninstaller.rb +++ b/test/rubygems/test_gem_uninstaller.rb @@ -12,19 +12,19 @@ class TestGemUninstaller < Gem::InstallerTestCase def setup super - @user_spec.executables = ["executable"] + @user_spec.executables = ["my_exec"] # HACK util_make_exec user_bin_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name, 'bin' FileUtils.mkdir_p user_bin_dir - exec_path = File.join user_bin_dir, "executable" + exec_path = File.join user_bin_dir, "my_exec" open exec_path, 'w' do |f| f.puts "#!/usr/bin/ruby" end user_bin_dir = File.join Gem.user_dir, 'bin' FileUtils.mkdir_p user_bin_dir - exec_path = File.join user_bin_dir, "executable" + exec_path = File.join user_bin_dir, "my_exec" open exec_path, 'w' do |f| f.puts "#!/usr/bin/ruby" end @@ -47,8 +47,8 @@ class TestGemUninstaller < Gem::InstallerTestCase def test_remove_executables_force_keep uninstaller = Gem::Uninstaller.new nil, :executables => false - executable = File.join Gem.user_dir, 'bin', 'executable' - assert File.exist?(executable), 'executable not written' + executable = File.join Gem.user_dir, 'bin', 'my_exec' + assert File.exist? executable use_ui @ui do uninstaller.remove_executables @user_spec @@ -62,14 +62,14 @@ class TestGemUninstaller < Gem::InstallerTestCase def test_remove_executables_force_remove uninstaller = Gem::Uninstaller.new nil, :executables => true - executable = File.join Gem.user_dir, 'bin', 'executable' - assert File.exist?(executable), 'executable not written' + executable = File.join Gem.user_dir, 'bin', 'my_exec' + assert File.exist? executable use_ui @ui do uninstaller.remove_executables @user_spec end - assert_equal "Removing executable\n", @ui.output + assert_equal "Removing my_exec\n", @ui.output refute File.exist? executable end @@ -81,47 +81,12 @@ class TestGemUninstaller < Gem::InstallerTestCase uninstaller.remove_executables @user_spec end - exec_path = File.join Gem.user_dir, 'bin', 'executable' + exec_path = File.join Gem.user_dir, 'bin', 'my_exec' assert_equal false, File.exist?(exec_path), 'removed exec from bin dir' - assert_equal "Removing executable\n", @ui.output + assert_equal "Removing my_exec\n", @ui.output end - def test_remove_executables_user_format - Gem::Installer.exec_format = 'foo-%s-bar' - - uninstaller = Gem::Uninstaller.new nil, :executables => true, :format_executable => true - - use_ui @ui do - uninstaller.remove_executables @user_spec - end - - exec_path = File.join Gem.user_dir, 'bin', 'foo-executable-bar' - assert_equal false, File.exist?(exec_path), 'removed exec from bin dir' - - assert_equal "Removing executable\n", @ui.output - ensure - Gem::Installer.exec_format = nil - end - - def test_remove_executables_user_format_disabled - Gem::Installer.exec_format = 'foo-%s-bar' - - uninstaller = Gem::Uninstaller.new nil, :executables => true - - use_ui @ui do - uninstaller.remove_executables @user_spec - end - - exec_path = File.join Gem.user_dir, 'bin', 'executable' - assert_equal false, File.exist?(exec_path), 'removed exec from bin dir' - - assert_equal "Removing executable\n", @ui.output - ensure - Gem::Installer.exec_format = nil - end - - def test_path_ok_eh uninstaller = Gem::Uninstaller.new nil @@ -164,31 +129,6 @@ class TestGemUninstaller < Gem::InstallerTestCase assert_same uninstaller, @post_uninstall_hook_arg end - def test_uninstall_not_ok - quick_gem 'z' do |s| - s.add_runtime_dependency @spec.name - end - - uninstaller = Gem::Uninstaller.new @spec.name - - gem_dir = File.join @gemhome, 'gems', @spec.full_name - executable = File.join @gemhome, 'bin', 'executable' - - assert File.exist?(gem_dir), 'gem_dir must exist' - assert File.exist?(executable), 'executable must exist' - - ui = Gem::MockGemUi.new "n\n" - - assert_raises Gem::DependencyRemovalException do - use_ui ui do - uninstaller.uninstall - end - end - - assert File.exist?(gem_dir), 'gem_dir must still exist' - assert File.exist?(executable), 'executable must still exist' - end - def test_uninstall_user uninstaller = Gem::Uninstaller.new @user_spec.name, :executables => true, :user_install => true diff --git a/test/rubygems/test_gem_validator.rb b/test/rubygems/test_gem_validator.rb index 304c141483..aa4bd38eb6 100644 --- a/test/rubygems/test_gem_validator.rb +++ b/test/rubygems/test_gem_validator.rb @@ -5,7 +5,7 @@ ###################################################################### require 'rubygems/test_case' -require "rubygems/simple_gem" +require "test/rubygems/simple_gem" require 'rubygems/validator' class TestGemValidator < Gem::TestCase diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb index d3714a2c59..98d27a6123 100644 --- a/test/rubygems/test_kernel.rb +++ b/test/rubygems/test_kernel.rb @@ -46,7 +46,7 @@ class TestKernel < Gem::TestCase gem 'a', '= 2' end - assert_match(/activate a \(= 2\)/, ex.message) + assert_match(/activate a \(= 2, runtime\)/, ex.message) assert_match(/activated a-1/, ex.message) assert_equal 'a', ex.name assert_equal Gem::Requirement.new('= 2'), ex.requirement diff --git a/version.h b/version.h index da0467e3c9..8f47eb3224 100644 --- a/version.h +++ b/version.h @@ -1,11 +1,11 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_RELEASE_DATE "2011-03-07" +#define RUBY_RELEASE_DATE "2011-02-25" #define RUBY_PATCHLEVEL -1 #define RUBY_BRANCH_NAME "trunk" #define RUBY_RELEASE_YEAR 2011 -#define RUBY_RELEASE_MONTH 3 -#define RUBY_RELEASE_DAY 7 +#define RUBY_RELEASE_MONTH 2 +#define RUBY_RELEASE_DAY 25 #include "ruby/version.h" @@ -51,4 +51,3 @@ STRINGIZE(RUBY_BIRTH_YEAR)"-" \ STRINGIZE(RUBY_RELEASE_YEAR)" " \ RUBY_AUTHOR - diff --git a/vm_eval.c b/vm_eval.c index 54debd7fec..ce7057476c 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -459,12 +459,12 @@ NORETURN(static void raise_method_missing(rb_thread_t *th, int argc, const VALUE * values. * * class Roman - * def roman_to_int(str) + * def romanToInt(str) * # ... * end * def method_missing(methId) * str = methId.id2name - * roman_to_int(str) + * romanToInt(str) * end * end * @@ -1082,12 +1082,12 @@ eval_string(VALUE self, VALUE src, VALUE scope, const char *file, int line) * optional filename and lineno parameters are * present, they will be used when reporting syntax errors. * - * def get_binding(str) + * def getBinding(str) * return binding * end * str = "hello" * eval "str + ' Fred'" #=> "hello Fred" - * eval "str + ' Fred'", get_binding("bye") #=> "bye Fred" + * eval "str + ' Fred'", getBinding("bye") #=> "bye Fred" */ VALUE diff --git a/vm_method.c b/vm_method.c index 278941aefa..f7b7534830 100644 --- a/vm_method.c +++ b/vm_method.c @@ -1152,20 +1152,20 @@ top_private(int argc, VALUE *argv) * end * class Cls * include Mod - * def call_one + * def callOne * one * end * end * Mod.one #=> "This is one" * c = Cls.new - * c.call_one #=> "This is one" + * c.callOne #=> "This is one" * module Mod * def one * "This is the new one" * end * end * Mod.one #=> "This is one" - * c.call_one #=> "This is the new one" + * c.callOne #=> "This is the new one" */ static VALUE -- cgit v1.2.3