1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2011-03-07 08:39:39 +00:00
parent c414d861c1
commit eb807d42ec
67 changed files with 773 additions and 1845 deletions

8
.gitignore vendored
View file

@ -97,9 +97,6 @@
/ext/-test-/*/Makefile /ext/-test-/*/Makefile
/ext/-test-/*/extconf.h /ext/-test-/*/extconf.h
/ext/-test-/*/mkmf.log /ext/-test-/*/mkmf.log
/ext/-test-/*/*/Makefile
/ext/-test-/*/*/extconf.h
/ext/-test-/*/*/mkmf.log
# /ext/bigdecimal/ # /ext/bigdecimal/
/ext/bigdecimal/*.def /ext/bigdecimal/*.def
@ -449,11 +446,6 @@
/ext/zlib/zlib.a /ext/zlib/zlib.a
/ext/zlib/conftest.dSYM /ext/zlib/conftest.dSYM
# /ext/date/
/ext/date/Makefile
/ext/date/extconf.h
/ext/date/mkmf.log
# /lib/rexml/ # /lib/rexml/
# /spec/ # /spec/

View file

@ -1,3 +1,9 @@
Mon Mar 7 17:13:00 2011 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <nobu@ruby-lang.org> Mon Mar 7 09:05:18 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* process.c: NUM2RLIM is defined but no getrlimit and setrlimit on * 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 For the changes before 1.8.0, see doc/ChangeLog-1.8.0
Local variables: Local variables:
coding: us-ascii
add-log-time-format: (lambda () add-log-time-format: (lambda ()
(let* ((time (current-time)) (let* ((time (current-time))
(system-time-locale "C") (system-time-locale "C")

6
NEWS
View file

@ -72,7 +72,6 @@ with all sufficient information, see the ChangeLog file.
* String#unpack supports endian modifiers * String#unpack supports endian modifiers
* new method: * new method:
* String#prepend * String#prepend
* String#byteslice
* Time * Time
* extended method: * extended method:
@ -154,3 +153,8 @@ with all sufficient information, see the ChangeLog file.
* Kernel#respond_to? * Kernel#respond_to?
See above. 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.

View file

@ -9,7 +9,7 @@ require 'rubygems'
require 'rubygems/gem_runner' require 'rubygems/gem_runner'
require 'rubygems/exceptions' 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 unless required_version.satisfied_by? Gem.ruby_version then
abort "Expected Ruby Version #{required_version}, is #{Gem.ruby_version}" abort "Expected Ruby Version #{required_version}, is #{Gem.ruby_version}"

10
class.c
View file

@ -988,14 +988,14 @@ rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod)
* <i>obj</i>'s ancestors. * <i>obj</i>'s ancestors.
* *
* class Klass * class Klass
* def klass_method() * def kMethod()
* end * end
* end * end
* k = Klass.new * k = Klass.new
* k.methods[0..9] #=> [:klass_method, :nil?, :===, * k.methods[0..9] #=> [:kMethod, :freeze, :nil?, :is_a?,
* # :==~, :!, :eql? * # :class, :instance_variable_set,
* # :hash, :<=>, :class, :singleton_class] * # :methods, :extend, :__send__, :instance_eval]
* k.methods.length #=> 57 * k.methods.length #=> 42
*/ */
VALUE VALUE

View file

@ -97,6 +97,7 @@ void
rb_exec_end_proc(void) rb_exec_end_proc(void)
{ {
struct end_proc_data *volatile link; struct end_proc_data *volatile link;
struct end_proc_data *tmp;
int status; int status;
volatile int safe = rb_safe_level(); volatile int safe = rb_safe_level();

View file

@ -2237,7 +2237,7 @@ static int gnAlloc=0; /* Memory allocation counter */
VP_EXPORT void * VP_EXPORT void *
VpMemAlloc(size_t mb) VpMemAlloc(size_t mb)
{ {
void *p = xmalloc(mb); void *p = xmalloc((unsigned int)mb);
if(!p) { if(!p) {
VpException(VP_EXCEPTION_MEMORY,"failed to allocate memory",1); VpException(VP_EXCEPTION_MEMORY,"failed to allocate memory",1);
} }

View file

@ -202,7 +202,7 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
* keeping this behaviour for backward compatibility. * keeping this behaviour for backward compatibility.
*/ */
const char *cname = rb_class2name(rb_obj_class(self)); 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", "use %s#pkcs5_keyivgen to derive key and IV",
cname, cname, cname); cname, cname, cname);
StringValue(pass); StringValue(pass);

View file

@ -11,14 +11,14 @@
#include "ossl.h" #include "ossl.h"
#define WrapSPKI(klass, obj, spki) do { \ #define WrapSPKI(klass, obj, spki) do { \
if (!(spki)) { \ if (!spki) { \
ossl_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \ 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) } while (0)
#define GetSPKI(obj, spki) do { \ #define GetSPKI(obj, spki) do { \
Data_Get_Struct((obj), NETSCAPE_SPKI, (spki)); \ Data_Get_Struct(obj, NETSCAPE_SPKI, spki); \
if (!(spki)) { \ if (!spki) { \
ossl_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \ ossl_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \
} \ } \
} while (0) } while (0)

View file

@ -14,55 +14,55 @@
#if defined(OSSL_OCSP_ENABLED) #if defined(OSSL_OCSP_ENABLED)
#define WrapOCSPReq(klass, obj, req) do { \ #define WrapOCSPReq(klass, obj, req) do { \
if(!(req)) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \ if(!req) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \
(obj) = Data_Wrap_Struct((klass), 0, OCSP_REQUEST_free, (req)); \ obj = Data_Wrap_Struct(klass, 0, OCSP_REQUEST_free, req); \
} while (0) } while (0)
#define GetOCSPReq(obj, req) do { \ #define GetOCSPReq(obj, req) do { \
Data_Get_Struct((obj), OCSP_REQUEST, (req)); \ Data_Get_Struct(obj, OCSP_REQUEST, req); \
if(!(req)) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \ if(!req) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \
} while (0) } while (0)
#define SafeGetOCSPReq(obj, req) do { \ #define SafeGetOCSPReq(obj, req) do { \
OSSL_Check_Kind((obj), cOCSPReq); \ OSSL_Check_Kind(obj, cOCSPReq); \
GetOCSPReq((obj), (req)); \ GetOCSPReq(obj, req); \
} while (0) } while (0)
#define WrapOCSPRes(klass, obj, res) do { \ #define WrapOCSPRes(klass, obj, res) do { \
if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
(obj) = Data_Wrap_Struct((klass), 0, OCSP_RESPONSE_free, (res)); \ obj = Data_Wrap_Struct(klass, 0, OCSP_RESPONSE_free, res); \
} while (0) } while (0)
#define GetOCSPRes(obj, res) do { \ #define GetOCSPRes(obj, res) do { \
Data_Get_Struct((obj), OCSP_RESPONSE, (res)); \ Data_Get_Struct(obj, OCSP_RESPONSE, res); \
if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
} while (0) } while (0)
#define SafeGetOCSPRes(obj, res) do { \ #define SafeGetOCSPRes(obj, res) do { \
OSSL_Check_Kind((obj), cOCSPRes); \ OSSL_Check_Kind(obj, cOCSPRes); \
GetOCSPRes((obj), (res)); \ GetOCSPRes(obj, res); \
} while (0) } while (0)
#define WrapOCSPBasicRes(klass, obj, res) do { \ #define WrapOCSPBasicRes(klass, obj, res) do { \
if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
(obj) = Data_Wrap_Struct((klass), 0, OCSP_BASICRESP_free, (res)); \ obj = Data_Wrap_Struct(klass, 0, OCSP_BASICRESP_free, res); \
} while (0) } while (0)
#define GetOCSPBasicRes(obj, res) do { \ #define GetOCSPBasicRes(obj, res) do { \
Data_Get_Struct((obj), OCSP_BASICRESP, (res)); \ Data_Get_Struct(obj, OCSP_BASICRESP, res); \
if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \ if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
} while (0) } while (0)
#define SafeGetOCSPBasicRes(obj, res) do { \ #define SafeGetOCSPBasicRes(obj, res) do { \
OSSL_Check_Kind((obj), cOCSPBasicRes); \ OSSL_Check_Kind(obj, cOCSPBasicRes); \
GetOCSPBasicRes((obj), (res)); \ GetOCSPBasicRes(obj, res); \
} while (0) } while (0)
#define WrapOCSPCertId(klass, obj, cid) do { \ #define WrapOCSPCertId(klass, obj, cid) do { \
if(!(cid)) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \ if(!cid) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \
(obj) = Data_Wrap_Struct((klass), 0, OCSP_CERTID_free, (cid)); \ obj = Data_Wrap_Struct(klass, 0, OCSP_CERTID_free, cid); \
} while (0) } while (0)
#define GetOCSPCertId(obj, cid) do { \ #define GetOCSPCertId(obj, cid) do { \
Data_Get_Struct((obj), OCSP_CERTID, (cid)); \ Data_Get_Struct(obj, OCSP_CERTID, cid); \
if(!(cid)) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \ if(!cid) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \
} while (0) } while (0)
#define SafeGetOCSPCertId(obj, cid) do { \ #define SafeGetOCSPCertId(obj, cid) do { \
OSSL_Check_Kind((obj), cOCSPCertId); \ OSSL_Check_Kind(obj, cOCSPCertId); \
GetOCSPCertId((obj), (cid)); \ GetOCSPCertId(obj, cid); \
} while (0) } while (0)
VALUE mOCSP; VALUE mOCSP;

View file

@ -6,18 +6,18 @@
#include "ossl.h" #include "ossl.h"
#define WrapPKCS12(klass, obj, p12) do { \ #define WrapPKCS12(klass, obj, p12) do { \
if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \ if(!p12) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \
(obj) = Data_Wrap_Struct((klass), 0, PKCS12_free, (p12)); \ obj = Data_Wrap_Struct(klass, 0, PKCS12_free, p12); \
} while (0) } while (0)
#define GetPKCS12(obj, p12) do { \ #define GetPKCS12(obj, p12) do { \
Data_Get_Struct((obj), PKCS12, (p12)); \ Data_Get_Struct(obj, PKCS12, p12); \
if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \ if(!p12) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \
} while (0) } while (0)
#define SafeGetPKCS12(obj, p12) do { \ #define SafeGetPKCS12(obj, p12) do { \
OSSL_Check_Kind((obj), cPKCS12); \ OSSL_Check_Kind(obj, cPKCS12); \
GetPKCS12((obj), (p12)); \ GetPKCS12(obj, p12); \
} while (0) } while (0)
#define ossl_pkcs12_set_key(o,v) rb_iv_set((o), "@key", (v)) #define ossl_pkcs12_set_key(o,v) rb_iv_set((o), "@key", (v))

View file

@ -11,57 +11,57 @@
#include "ossl.h" #include "ossl.h"
#define WrapPKCS7(klass, obj, pkcs7) do { \ #define WrapPKCS7(klass, obj, pkcs7) do { \
if (!(pkcs7)) { \ if (!pkcs7) { \
ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \ 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) } while (0)
#define GetPKCS7(obj, pkcs7) do { \ #define GetPKCS7(obj, pkcs7) do { \
Data_Get_Struct((obj), PKCS7, (pkcs7)); \ Data_Get_Struct(obj, PKCS7, pkcs7); \
if (!(pkcs7)) { \ if (!pkcs7) { \
ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \ ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
} \ } \
} while (0) } while (0)
#define SafeGetPKCS7(obj, pkcs7) do { \ #define SafeGetPKCS7(obj, pkcs7) do { \
OSSL_Check_Kind((obj), cPKCS7); \ OSSL_Check_Kind(obj, cPKCS7); \
GetPKCS7((obj), (pkcs7)); \ GetPKCS7(obj, pkcs7); \
} while (0) } while (0)
#define WrapPKCS7si(klass, obj, p7si) do { \ #define WrapPKCS7si(klass, obj, p7si) do { \
if (!(p7si)) { \ if (!p7si) { \
ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \ 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) } while (0)
#define GetPKCS7si(obj, p7si) do { \ #define GetPKCS7si(obj, p7si) do { \
Data_Get_Struct((obj), PKCS7_SIGNER_INFO, (p7si)); \ Data_Get_Struct(obj, PKCS7_SIGNER_INFO, p7si); \
if (!(p7si)) { \ if (!p7si) { \
ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \ ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \
} \ } \
} while (0) } while (0)
#define SafeGetPKCS7si(obj, p7si) do { \ #define SafeGetPKCS7si(obj, p7si) do { \
OSSL_Check_Kind((obj), cPKCS7Signer); \ OSSL_Check_Kind(obj, cPKCS7Signer); \
GetPKCS7si((obj), (p7si)); \ GetPKCS7si(obj, p7si); \
} while (0) } while (0)
#define WrapPKCS7ri(klass, obj, p7ri) do { \ #define WrapPKCS7ri(klass, obj, p7ri) do { \
if (!(p7ri)) { \ if (!p7ri) { \
ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \ 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) } while (0)
#define GetPKCS7ri(obj, p7ri) do { \ #define GetPKCS7ri(obj, p7ri) do { \
Data_Get_Struct((obj), PKCS7_RECIP_INFO, (p7ri)); \ Data_Get_Struct(obj, PKCS7_RECIP_INFO, p7ri); \
if (!(p7ri)) { \ if (!p7ri) { \
ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \ ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \
} \ } \
} while (0) } while (0)
#define SafeGetPKCS7ri(obj, p7ri) do { \ #define SafeGetPKCS7ri(obj, p7ri) do { \
OSSL_Check_Kind((obj), cPKCS7Recipient); \ OSSL_Check_Kind(obj, cPKCS7Recipient); \
GetPKCS7ri((obj), (p7ri)); \ GetPKCS7ri(obj, p7ri); \
} while (0) } 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_set_data(o,v) rb_iv_set((o), "@data", (v))
#define ossl_pkcs7_get_data(o) rb_iv_get((o), "@data") #define ossl_pkcs7_get_data(o) rb_iv_get((o), "@data")

View file

@ -21,21 +21,21 @@ extern ID id_private_q;
#define OSSL_PKEY_IS_PRIVATE(obj) (rb_iv_get((obj), "private") == Qtrue) #define OSSL_PKEY_IS_PRIVATE(obj) (rb_iv_get((obj), "private") == Qtrue)
#define WrapPKey(klass, obj, pkey) do { \ #define WrapPKey(klass, obj, pkey) do { \
if (!(pkey)) { \ if (!pkey) { \
rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!"); \ 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); \ OSSL_PKEY_SET_PUBLIC(obj); \
} while (0) } while (0)
#define GetPKey(obj, pkey) do {\ #define GetPKey(obj, pkey) do {\
Data_Get_Struct((obj), EVP_PKEY, (pkey));\ Data_Get_Struct(obj, EVP_PKEY, pkey);\
if (!(pkey)) { \ if (!pkey) { \
rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!");\ rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!");\
} \ } \
} while (0) } while (0)
#define SafeGetPKey(obj, pkey) do { \ #define SafeGetPKey(obj, pkey) do { \
OSSL_Check_Kind((obj), cPKey); \ OSSL_Check_Kind(obj, cPKey); \
GetPKey((obj), (pkey)); \ GetPKey(obj, pkey); \
} while (0) } while (0)
void ossl_generate_cb(int, int, void *); 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) \ #define DEF_OSSL_PKEY_BN(class, keytype, name) \
do { \ do { \
rb_define_method((class), #name, ossl_##keytype##_get_##name, 0); \ 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##_set_##name, 1);\
} while (0) } while (0)
#endif /* _OSSL_PKEY_H_ */ #endif /* _OSSL_PKEY_H_ */

View file

@ -13,8 +13,8 @@
#include "ossl.h" #include "ossl.h"
#define GetPKeyDH(obj, pkey) do { \ #define GetPKeyDH(obj, pkey) do { \
GetPKey((obj), (pkey)); \ GetPKey(obj, pkey); \
if (EVP_PKEY_type((pkey)->type) != EVP_PKEY_DH) { /* PARANOIA? */ \ if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DH) { /* PARANOIA? */ \
ossl_raise(rb_eRuntimeError, "THIS IS NOT A DH!") ; \ ossl_raise(rb_eRuntimeError, "THIS IS NOT A DH!") ; \
} \ } \
} while (0) } while (0)

View file

@ -13,8 +13,8 @@
#include "ossl.h" #include "ossl.h"
#define GetPKeyDSA(obj, pkey) do { \ #define GetPKeyDSA(obj, pkey) do { \
GetPKey((obj), (pkey)); \ GetPKey(obj, pkey); \
if (EVP_PKEY_type((pkey)->type) != EVP_PKEY_DSA) { /* PARANOIA? */ \ if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DSA) { /* PARANOIA? */ \
ossl_raise(rb_eRuntimeError, "THIS IS NOT A DSA!"); \ ossl_raise(rb_eRuntimeError, "THIS IS NOT A DSA!"); \
} \ } \
} while (0) } while (0)

56
gc.c
View file

@ -78,6 +78,47 @@ void *alloca ();
#ifndef GC_MALLOC_LIMIT #ifndef GC_MALLOC_LIMIT
#define GC_MALLOC_LIMIT 8000000 #define GC_MALLOC_LIMIT 8000000
#endif #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] #define nomem_error GET_VM()->special_exceptions[ruby_error_nomemory]
@ -297,9 +338,6 @@ struct sorted_heaps_slot {
struct heaps_slot *slot; struct heaps_slot *slot;
}; };
#define HEAP_MIN_SLOTS 10000
#define FREE_MIN 4096
struct gc_list { struct gc_list {
VALUE *varptr; VALUE *varptr;
struct gc_list *next; struct gc_list *next;
@ -363,7 +401,7 @@ typedef struct rb_objspace {
static int ruby_initial_gc_stress = 0; static int ruby_initial_gc_stress = 0;
int *ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress; int *ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress;
#else #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; int *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress;
#endif #endif
#define malloc_limit objspace->malloc_params.limit #define malloc_limit objspace->malloc_params.limit
@ -394,7 +432,7 @@ rb_objspace_alloc(void)
{ {
rb_objspace_t *objspace = malloc(sizeof(rb_objspace_t)); rb_objspace_t *objspace = malloc(sizeof(rb_objspace_t));
memset(objspace, 0, sizeof(*objspace)); memset(objspace, 0, sizeof(*objspace));
malloc_limit = GC_MALLOC_LIMIT; malloc_limit = initial_malloc_limit;
ruby_gc_stress = ruby_initial_gc_stress; ruby_gc_stress = ruby_initial_gc_stress;
return objspace; return objspace;
@ -998,7 +1036,7 @@ init_heap(rb_objspace_t *objspace)
{ {
size_t add, i; size_t add, i;
add = HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT; add = initial_heap_min_slots / HEAP_OBJ_LIMIT;
if (!add) { if (!add) {
add = 1; add = 1;
@ -1986,9 +2024,9 @@ before_gc_sweep(rb_objspace_t *objspace)
freelist = 0; freelist = 0;
objspace->heap.do_heap_free = (size_t)((heaps_used * HEAP_OBJ_LIMIT) * 0.65); 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); 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.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.sweep_slots = heaps;
objspace->heap.free_num = 0; objspace->heap.free_num = 0;
@ -2011,7 +2049,7 @@ after_gc_sweep(rb_objspace_t *objspace)
if (malloc_increase > malloc_limit) { if (malloc_increase > malloc_limit) {
malloc_limit += (size_t)((malloc_increase - malloc_limit) * (double)objspace->heap.live_num / (heaps_used * HEAP_OBJ_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; malloc_increase = 0;

View file

@ -112,11 +112,3 @@ class Enumerator
alias old_inspect inspect alias old_inspect inspect
alias inspect old_to_s alias inspect old_to_s
end end
class Symbol
def call(*args, &block)
proc do |recv|
recv.__send__(self, *args, &block)
end
end
end

View file

@ -424,6 +424,7 @@ VALUE rb_gc_enable(void);
VALUE rb_gc_disable(void); VALUE rb_gc_disable(void);
VALUE rb_gc_start(void); VALUE rb_gc_start(void);
#define Init_stack(addr) ruby_init_stack(addr) #define Init_stack(addr) ruby_init_stack(addr)
void rb_gc_set_params(void);
/* hash.c */ /* hash.c */
void st_foreach_safe(struct st_table *, int (*)(ANYARGS), st_data_t); void st_foreach_safe(struct st_table *, int (*)(ANYARGS), st_data_t);
VALUE rb_check_hash_type(VALUE); VALUE rb_check_hash_type(VALUE);

View file

@ -5,6 +5,10 @@
# #
# Documentation: William Webber <william@williamwebber.com> # Documentation: William Webber <william@williamwebber.com>
# #
#--
# $Id: date.rb,v 2.37 2008-01-17 20:16:31+09 tadf Exp $
#++
#
# == Overview # == Overview
# #
# This file provides two classes for working with # This file provides two classes for working with
@ -276,15 +280,6 @@ class Date
end end
end end
def to_f
return 0 if @d == 0
if @d > 0
Float::INFINITY
else
-Float::INFINITY
end
end
end end
# The Julian Day Number of the Day of Calendar Reform for Italy # 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] # [commercial_year, week_of_year, day_of_week]
def jd_to_commercial(jd, sg=GREGORIAN) # :nodoc: def jd_to_commercial(jd, sg=GREGORIAN) # :nodoc:
a = jd_to_civil(jd - 3, sg)[0] a = jd_to_civil(jd - 3, sg)[0]
j = commercial_to_jd(a + 1, 1, 1, sg) y = if jd >= commercial_to_jd(a + 1, 1, 1, sg) then a + 1 else a end
if jd >= j w = 1 + ((jd - commercial_to_jd(y, 1, 1, sg)) / 7).floor
y = a + 1
else
j = commercial_to_jd(a, 1, 1, sg)
y = a
end
w = 1 + ((jd - j) / 7).floor
d = (jd + 1) % 7 d = (jd + 1) % 7
d = 7 if d == 0 d = 7 if d == 0
return y, w, d 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 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 :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) !!_valid_jd?(jd, sg)
end end
private_class_method :valid_jd_r? def self.valid_ordinal? (y, d, sg=ITALY)
def self.valid_ordinal_r? (y, d, sg=ITALY)
!!_valid_ordinal?(y, d, sg) !!_valid_ordinal?(y, d, sg)
end end
private_class_method :valid_ordinal_r? def self.valid_civil? (y, m, d, sg=ITALY)
def self.valid_civil_r? (y, m, d, sg=ITALY)
!!_valid_civil?(y, m, d, sg) !!_valid_civil?(y, m, d, sg)
end 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) !!_valid_commercial?(y, w, d, sg)
end end
private_class_method :valid_commercial_r?
def self.valid_weeknum? (y, w, d, f, sg=ITALY) # :nodoc: def self.valid_weeknum? (y, w, d, f, sg=ITALY) # :nodoc:
!!_valid_weeknum?(y, w, d, f, sg) !!_valid_weeknum?(y, w, d, f, sg)
end end
@ -773,28 +757,16 @@ class Date
private_class_method :valid_time? 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. # Create a new Date object from a Julian Day Number.
# #
# +jd+ is the Julian Day Number; if not specified, it defaults to # +jd+ is the Julian Day Number; if not specified, it defaults to
# 0. # 0.
# +sg+ specifies the Day of Calendar Reform. # +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) 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 end
private_class_method :jd_r
# Create a new Date object from an Ordinal Date, specified # Create a new Date object from an Ordinal Date, specified
# by year +y+ and day-of-year +d+. +d+ can be negative, # by year +y+ and day-of-year +d+. +d+ can be negative,
# in which it counts backwards from the end of the year. # in which it counts backwards from the end of the year.
@ -805,15 +777,13 @@ class Date
# Number day 0. # Number day 0.
# #
# +sg+ specifies the Day of Calendar Reform. # +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) unless jd = _valid_ordinal?(y, d, sg)
raise ArgumentError, 'invalid date' raise ArgumentError, 'invalid date'
end end
new_r!(jd_to_ajd(jd, 0, 0), 0, sg) new!(jd_to_ajd(jd, 0, 0), 0, sg)
end end
private_class_method :ordinal_r
# Create a new Date object for the Civil Date specified by # Create a new Date object for the Civil Date specified by
# year +y+, month +m+, and day-of-month +d+. # year +y+, month +m+, and day-of-month +d+.
# #
@ -827,14 +797,14 @@ class Date
# Julian Day Number day 0. # Julian Day Number day 0.
# #
# +sg+ specifies the Day of Calendar Reform. # +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) unless jd = _valid_civil?(y, m, d, sg)
raise ArgumentError, 'invalid date' raise ArgumentError, 'invalid date'
end end
new_r!(jd_to_ajd(jd, 0, 0), 0, sg) new!(jd_to_ajd(jd, 0, 0), 0, sg)
end end
private_class_method :civil_r class << self; alias_method :new, :civil end
# Create a new Date object for the Commercial Date specified by # Create a new Date object for the Commercial Date specified by
# year +y+, week-of-year +w+, and day-of-week +d+. # year +y+, week-of-year +w+, and day-of-week +d+.
@ -850,15 +820,13 @@ class Date
# Julian Day Number day 0. # Julian Day Number day 0.
# #
# +sg+ specifies the Day of Calendar Reform. # +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) unless jd = _valid_commercial?(y, w, d, sg)
raise ArgumentError, 'invalid date' raise ArgumentError, 'invalid date'
end end
new_r!(jd_to_ajd(jd, 0, 0), 0, sg) new!(jd_to_ajd(jd, 0, 0), 0, sg)
end end
private_class_method :commercial_r
def self.weeknum(y=-4712, w=0, d=1, f=0, sg=ITALY) def self.weeknum(y=-4712, w=0, d=1, f=0, sg=ITALY)
unless jd = _valid_weeknum?(y, w, d, f, sg) unless jd = _valid_weeknum?(y, w, d, f, sg)
raise ArgumentError, 'invalid date' raise ArgumentError, 'invalid date'
@ -1131,7 +1099,7 @@ class Date
alias_method :__#{id.object_id}__, :#{id.to_s} alias_method :__#{id.object_id}__, :#{id.to_s}
private :__#{id.object_id}__ private :__#{id.object_id}__
def #{id.to_s}(*args) def #{id.to_s}(*args)
__ca__[#{id.object_id}] ||= __#{id.object_id}__(*args) @__ca__[#{id.object_id}] ||= __#{id.object_id}__(*args)
end end
end; end;
end end
@ -1141,69 +1109,96 @@ class Date
end 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. # 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 once :daynum
private :daynum private :daynum
# Get the date as a Julian Day Number. # 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. # 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. # 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 # Get the date as the number of days since the Day of Calendar
# Reform (in Italy and the Catholic countries). # 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 once :jd, :day_fraction, :mjd, :ld
private :jd_r, :day_fraction_r, :mjd_r, :ld_r
# Get the date as a Civil Date, [year, month, day_of_month] # 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] # 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] # 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 weeknum0() jd_to_weeknum(jd, 0, @sg) end # :nodoc:
def weeknum1() jd_to_weeknum(jd, 1, start) end # :nodoc: def weeknum1() jd_to_weeknum(jd, 1, @sg) end # :nodoc:
once :civil, :ordinal, :commercial, :weeknum0, :weeknum1 once :civil, :ordinal, :commercial, :weeknum0, :weeknum1
private :civil, :ordinal, :commercial, :weeknum0, :weeknum1 private :civil, :ordinal, :commercial, :weeknum0, :weeknum1
# Get the year of this date. # 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. # Get the day-of-the-year of this date.
# #
# January 1 is day-of-the-year 1 # 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. # Get the month of this date.
# #
# January is month 1. # 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. # 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 wnum0() weeknum0[1] end # :nodoc:
def wnum1_r() weeknum1[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, # Get the time of this date as [hours, minutes, seconds,
# fraction_of_a_second] # fraction_of_a_second]
@ -1215,20 +1210,25 @@ class Date
private :time, :time_wo_sf, :time_sf private :time, :time_wo_sf, :time_sf
# Get the hour of this date. # 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. # 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. # 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. # Get the fraction-of-a-second of this date.
def sec_fraction_r() time_sf end # 4p def sec_fraction() time_sf end # 4p
private :hour_r, :min_r, :sec_r, :sec_fraction_r alias_method :minute, :min
alias_method :second, :sec
alias_method :second_fraction, :sec_fraction
def zone_r # :nodoc: # 4p - strftime('%:z') private :hour, :min, :sec, :sec_fraction,
:minute, :second, :second_fraction
def zone # 4p - strftime('%:z')
sign = if offset < 0 then '-' else '+' end sign = if offset < 0 then '-' else '+' end
fr = offset.abs fr = offset.abs
ss = fr.div(SECONDS_IN_DAY) ss = fr.div(SECONDS_IN_DAY)
@ -1237,27 +1237,24 @@ class Date
format('%s%02d:%02d', sign, hh, mm) format('%s%02d:%02d', sign, hh, mm)
end end
private :zone_r private :zone
# Get the commercial year of this date. See *Commercial* *Date* # Get the commercial year of this date. See *Commercial* *Date*
# in the introduction for how this differs from the normal year. # 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. # 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 # Get the commercial day of the week of this date. Monday is
# commercial day-of-week 1; Sunday is commercial day-of-week 7. # commercial day-of-week 1; Sunday is commercial day-of-week 7.
def cwday_r() commercial[2] end # :nodoc: def cwday() commercial[2] end
private :cwyear_r, :cweek_r, :cwday_r
# Get the week day of this date. Sunday is day-of-week 0; # Get the week day of this date. Sunday is day-of-week 0;
# Saturday is day-of-week 6. # 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 once :wday
private :wday_r
=begin =begin
MONTHNAMES.each_with_index do |n, i| MONTHNAMES.each_with_index do |n, i|
@ -1271,20 +1268,19 @@ class Date
define_method(n.downcase + '?'){wday == i} define_method(n.downcase + '?'){wday == i}
end end
def nth_kday? (n, k) # :nodoc: def nth_kday? (n, k)
k == wday && jd === nth_kday_to_jd(year, mon, n, k, start) k == wday && jd === nth_kday_to_jd(year, mon, n, k, start)
end end
private :nth_kday? private :nth_kday?
# Is the current date old-style (Julian Calendar)? # 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)? # Is the current date new-style (Gregorian Calendar)?
def gregorian_r? () !julian? end # :nodoc: def gregorian? () !julian? end
once :julian_r?, :gregorian_r? once :julian?, :gregorian?
private :julian_r?, :gregorian_r?
def fix_style # :nodoc: def fix_style # :nodoc:
if julian? if julian?
@ -1295,21 +1291,18 @@ class Date
private :fix_style private :fix_style
# Is this a leap year? # Is this a leap year?
def leap_r? # :nodoc: def leap?
jd_to_civil(civil_to_jd(year, 3, 1, fix_style) - 1, jd_to_civil(civil_to_jd(year, 3, 1, fix_style) - 1,
fix_style)[-1] == 29 fix_style)[-1] == 29
end end
once :leap_r? once :leap?
private :leap_r?
# When is the Day of Calendar Reform for this Date object? # 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. # 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: def new_start(sg=self.class::ITALY) self.class.new!(@ajd, @of, sg) end
private :start_r, :new_start_r
# Create a copy of this Date object that uses the Italian/Catholic # Create a copy of this Date object that uses the Italian/Catholic
# Day of Calendar Reform. # Day of Calendar Reform.
@ -1327,16 +1320,16 @@ class Date
# Calendar. # Calendar.
def gregorian() new_start(self.class::GREGORIAN) end 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 if String === of
of = Rational(zone_to_diff(of) || 0, 86400) of = Rational(zone_to_diff(of) || 0, 86400)
elsif Float === of
of = Rational((of * 86400).round, 86400)
end end
self.class.new_r!(ajd, of, start) self.class.new!(@ajd, of, @sg)
end end
private :new_offset_r private :offset, :new_offset
# Return a new Date object that is +n+ days later than the # Return a new Date object that is +n+ days later than the
# current one. # current one.
@ -1347,19 +1340,13 @@ class Date
# #
# If +n+ is not a Numeric, a TypeError will be thrown. In # If +n+ is not a Numeric, a TypeError will be thrown. In
# particular, two Dates cannot be added to each other. # particular, two Dates cannot be added to each other.
def plus_r (n) # :nodoc: def + (n)
case n case n
when Numeric when Numeric; return self.class.new!(@ajd + n, @of, @sg)
if Float === n
n = Rational((n * 86400000000000).round, 86400000000000)
end
return self.class.new_r!(ajd + n, offset, start)
end end
raise TypeError, 'expected numeric' raise TypeError, 'expected numeric'
end end
private :plus_r
# If +x+ is a Numeric value, create a new Date object that is # If +x+ is a Numeric value, create a new Date object that is
# +x+ days earlier than the current one. # +x+ days earlier than the current one.
# #
@ -1368,21 +1355,14 @@ class Date
# date is than +x+. # date is than +x+.
# #
# If +x+ is neither Numeric nor a Date, a TypeError is raised. # If +x+ is neither Numeric nor a Date, a TypeError is raised.
def minus_r (x) # :nodoc: def - (x)
case x case x
when Numeric when Numeric; return self.class.new!(@ajd - x, @of, @sg)
if Float === x when Date; return @ajd - x.ajd
x = Rational((x * 86400000000000).round, 86400000000000)
end
return self.class.new_r!(ajd - x, offset, start)
when Date
return ajd - x.ajd
end end
raise TypeError, 'expected numeric or date' raise TypeError, 'expected numeric or date'
end end
private :minus_r
# Compare this date with another date. # Compare this date with another date.
# #
# +other+ can also be a Numeric value, in which case it is # +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 # two DateTime instances. When comparing a DateTime instance
# with a Date instance, the time of the latter will be # with a Date instance, the time of the latter will be
# considered as falling on midnight UTC. # considered as falling on midnight UTC.
def cmp_r (other) # :nodoc: def <=> (other)
case other case other
when Numeric; return ajd <=> other when Numeric; return @ajd <=> other
when Date; return ajd <=> other.ajd when Date; return @ajd <=> other.ajd
else else
begin begin
l, r = other.coerce(self) l, r = other.coerce(self)
@ -1408,15 +1388,13 @@ class Date
nil nil
end end
private :cmp_r
# The relationship operator for Date. # The relationship operator for Date.
# #
# Compares dates by Julian Day Number. When comparing # Compares dates by Julian Day Number. When comparing
# two DateTime instances, or a DateTime with a Date, # two DateTime instances, or a DateTime with a Date,
# the instances will be regarded as equivalent if they # the instances will be regarded as equivalent if they
# fall on the same date in local time. # fall on the same date in local time.
def equal_r (other) # :nodoc: def === (other)
case other case other
when Numeric; return jd == other when Numeric; return jd == other
when Date; return jd == other.jd when Date; return jd == other.jd
@ -1430,8 +1408,6 @@ class Date
false false
end end
private :equal_r
def next_day(n=1) self + n end def next_day(n=1) self + n end
def prev_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) y, m = (year * 12 + (mon - 1) + n).divmod(12)
m, = (m + 1) .divmod(1) m, = (m + 1) .divmod(1)
d = mday d = mday
until jd2 = _valid_civil?(y, m, d, start) until jd2 = _valid_civil?(y, m, d, @sg)
d -= 1 d -= 1
raise ArgumentError, 'invalid date' unless d > 0 raise ArgumentError, 'invalid date' unless d > 0
end end
@ -1510,28 +1486,29 @@ class Date
# Is this Date equal to +other+? # Is this Date equal to +other+?
# #
# +other+ must both be a Date object, and represent the same date. # +other+ must both be a Date object, and represent the same date.
def eql_r? (other) Date === other && self == other end # :nodoc: def eql? (other) Date === other && self == other end
private :eql_r?
# Calculate a hash value for this date. # Calculate a hash value for this date.
def hash_r() ajd.hash end # :nodoc: def hash() @ajd.hash end
private :hash_r
# Return internal object state as a programmer-readable string. # Return internal object state as a programmer-readable string.
def inspect_r # :nodoc: def inspect
format('#<%s[R]: %s (%s,%s,%s)>', self.class, to_s_r, ajd, offset, start) format('#<%s: %s (%s,%s,%s)>', self.class, to_s, @ajd, @of, @sg)
end end
private :inspect_r
# Return the date as a human-readable string. # Return the date as a human-readable string.
# #
# The format used is YYYY-MM-DD. # 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
private :to_s_r # Dump to Marshal format.
def marshal_dump() [@ajd, @of, @sg] end
# Load from Marshal format.
def marshal_load(a)
@ajd, @of, @sg, = a
@__ca__ = {}
end
end end
@ -1585,19 +1562,6 @@ end
# #
class DateTime < Date 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 # Create a new DateTime object corresponding to the specified
# Julian Day Number +jd+ and hour +h+, minute +min+, second +s+. # 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. # +sg+ specifies the Day of Calendar Reform.
# #
# All day/time values default to 0. # 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)) && unless (jd = _valid_jd?(jd, sg)) &&
(fr = _valid_time?(h, min, s)) (fr = _valid_time?(h, min, s))
raise ArgumentError, 'invalid date' raise ArgumentError, 'invalid date'
end end
if String === of if String === of
of = Rational(zone_to_diff(of) || 0, 86400) of = Rational(zone_to_diff(of) || 0, 86400)
elsif Float === of
of = Rational((of * 86400).round, 86400)
end end
new_r!(jd_to_ajd(jd, fr, of), of, sg) new!(jd_to_ajd(jd, fr, of), of, sg)
end end
private_class_method :jd_r
# Create a new DateTime object corresponding to the specified # Create a new DateTime object corresponding to the specified
# Ordinal Date and hour +h+, minute +min+, second +s+. # 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 # +y+ defaults to -4712, and +d+ to 1; this is Julian Day Number
# day 0. The time values default to 0. # 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)) && unless (jd = _valid_ordinal?(y, d, sg)) &&
(fr = _valid_time?(h, min, s)) (fr = _valid_time?(h, min, s))
raise ArgumentError, 'invalid date' raise ArgumentError, 'invalid date'
end end
if String === of if String === of
of = Rational(zone_to_diff(of) || 0, 86400) of = Rational(zone_to_diff(of) || 0, 86400)
elsif Float === of
of = Rational((of * 86400).round, 86400)
end end
new_r!(jd_to_ajd(jd, fr, of), of, sg) new!(jd_to_ajd(jd, fr, of), of, sg)
end end
private_class_method :ordinal_r
# Create a new DateTime object corresponding to the specified # Create a new DateTime object corresponding to the specified
# Civil Date and hour +h+, minute +min+, second +s+. # 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 # +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is Julian Day
# Number day 0. The time values default to 0. # 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)) && unless (jd = _valid_civil?(y, m, d, sg)) &&
(fr = _valid_time?(h, min, s)) (fr = _valid_time?(h, min, s))
raise ArgumentError, 'invalid date' raise ArgumentError, 'invalid date'
end end
if String === of if String === of
of = Rational(zone_to_diff(of) || 0, 86400) of = Rational(zone_to_diff(of) || 0, 86400)
elsif Float === of
of = Rational((of * 86400).round, 86400)
end end
new_r!(jd_to_ajd(jd, fr, of), of, sg) new!(jd_to_ajd(jd, fr, of), of, sg)
end end
private_class_method :civil_r class << self; alias_method :new, :civil end
# Create a new DateTime object corresponding to the specified # Create a new DateTime object corresponding to the specified
# Commercial Date and hour +h+, minute +min+, second +s+. # 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 # +y+ defaults to -4712, +w+ to 1, and +d+ to 1; this is
# Julian Day Number day 0. # Julian Day Number day 0.
# The time values default to 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)) && unless (jd = _valid_commercial?(y, w, d, sg)) &&
(fr = _valid_time?(h, min, s)) (fr = _valid_time?(h, min, s))
raise ArgumentError, 'invalid date' raise ArgumentError, 'invalid date'
end end
if String === of if String === of
of = Rational(zone_to_diff(of) || 0, 86400) of = Rational(zone_to_diff(of) || 0, 86400)
elsif Float === of
of = Rational((of * 86400).round, 86400)
end end
new_r!(jd_to_ajd(jd, fr, of), of, sg) new!(jd_to_ajd(jd, fr, of), of, sg)
end 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: 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)) && unless (jd = _valid_weeknum?(y, w, d, f, sg)) &&
(fr = _valid_time?(h, min, s)) (fr = _valid_time?(h, min, s))
@ -1721,8 +1671,6 @@ class DateTime < Date
end end
if String === of if String === of
of = Rational(zone_to_diff(of) || 0, 86400) of = Rational(zone_to_diff(of) || 0, 86400)
elsif Float === of
of = Rational((of * 86400).round, 86400)
end end
new!(jd_to_ajd(jd, fr, of), of, sg) new!(jd_to_ajd(jd, fr, of), of, sg)
end end
@ -1736,8 +1684,6 @@ class DateTime < Date
end end
if String === of if String === of
of = Rational(zone_to_diff(of) || 0, 86400) of = Rational(zone_to_diff(of) || 0, 86400)
elsif Float === of
of = Rational((of * 86400).round, 86400)
end end
new!(jd_to_ajd(jd, fr, of), of, sg) new!(jd_to_ajd(jd, fr, of), of, sg)
end end
@ -1824,13 +1770,14 @@ class DateTime < Date
new_by_frags(elem, sg) new_by_frags(elem, sg)
end 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', format('%.4d-%02d-%02dT%02d:%02d:%02d%s',
year, mon, mday, hour, min, sec, zone) year, mon, mday, hour, min, sec, zone)
end end
private :to_s_r
end end
class Time class Time
@ -1857,7 +1804,30 @@ class Date
def to_time() Time.local(year, mon, mday) end def to_time() Time.local(year, mon, mday) end
def to_date() self 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 end
@ -1872,9 +1842,10 @@ class DateTime < Date
getlocal getlocal
end 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 def to_datetime() self end
end private_class_method :today
public_class_method :now
require 'date_core' end

View file

@ -96,11 +96,11 @@ class Tempfile < DelegateClass(File)
# element, and end with the second element. For example: # element, and end with the second element. For example:
# #
# file = Tempfile.new('hello') # 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: # # Use the Array form to enforce an extension in the filename:
# file = Tempfile.new(['hello', '.jpg']) # 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 # The temporary file will be placed in the directory as specified
# by the +tmpdir+ parameter. By default, this is +Dir.tmpdir+. # by the +tmpdir+ parameter. By default, this is +Dir.tmpdir+.
@ -110,7 +110,7 @@ class Tempfile < DelegateClass(File)
# come from environment variables (e.g. <tt>$TMPDIR</tt>). # come from environment variables (e.g. <tt>$TMPDIR</tt>).
# #
# file = Tempfile.new('hello', '/home/aisaka') # 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 # You can also pass an options hash. Under the hood, Tempfile creates
# the temporary file using +File.open+. These options will be passed to # the temporary file using +File.open+. These options will be passed to

View file

@ -876,7 +876,7 @@ clear_dump_arg(struct dump_arg *arg)
* def initialize(str) * def initialize(str)
* @str = str * @str = str
* end * end
* def say_hello * def sayHello
* @str * @str
* end * end
* end * end
@ -886,7 +886,7 @@ clear_dump_arg(struct dump_arg *arg)
* o = Klass.new("hello\n") * o = Klass.new("hello\n")
* data = Marshal.dump(o) * data = Marshal.dump(o)
* obj = Marshal.load(data) * obj = Marshal.load(data)
* obj.say_hello #=> "hello\n" * obj.sayHello #=> "hello\n"
* *
* Marshal can't dump following objects: * Marshal can't dump following objects:
* * anonymous Class/Module. * * anonymous Class/Module.

14
proc.c
View file

@ -336,10 +336,10 @@ rb_binding_new(void)
* calling +eval+ to execute the evaluated command in this * calling +eval+ to execute the evaluated command in this
* environment. Also see the description of class +Binding+. * environment. Also see the description of class +Binding+.
* *
* def get_binding(param) * def getBinding(param)
* return binding * return binding
* end * end
* b = get_binding("hello") * b = getBinding("hello")
* eval("param", b) #=> "hello" * eval("param", b) #=> "hello"
*/ */
@ -358,10 +358,10 @@ rb_f_binding(VALUE self)
* <em>lineno</em> parameters are present, they will be used when * <em>lineno</em> parameters are present, they will be used when
* reporting syntax errors. * reporting syntax errors.
* *
* def get_binding(param) * def getBinding(param)
* return binding * return binding
* end * end
* b = get_binding("hello") * b = getBinding("hello")
* b.eval("param") #=> "hello" * b.eval("param") #=> "hello"
*/ */
@ -2211,15 +2211,15 @@ Init_Proc(void)
* def initialize(n) * def initialize(n)
* @secret = n * @secret = n
* end * end
* def get_binding * def getBinding
* return binding() * return binding()
* end * end
* end * end
* *
* k1 = Demo.new(99) * k1 = Demo.new(99)
* b1 = k1.get_binding * b1 = k1.getBinding
* k2 = Demo.new(-3) * k2 = Demo.new(-3)
* b2 = k2.get_binding * b2 = k2.getBinding
* *
* eval("@secret", b1) #=> 99 * eval("@secret", b1) #=> 99
* eval("@secret", b2) #=> -3 * eval("@secret", b2) #=> -3

View file

@ -122,6 +122,17 @@ static VALUE rb_cProcessTms;
#endif #endif
#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) \ #define preserving_errno(stmts) \
do {int saved_errno = errno; stmts; errno = saved_errno;} while (0) do {int saved_errno = errno; stmts; errno = saved_errno;} while (0)
@ -1283,7 +1294,7 @@ enum {
}; };
static VALUE static VALUE
check_exec_redirect_fd(VALUE v, int iskey) check_exec_redirect_fd(VALUE v)
{ {
VALUE tmp; VALUE tmp;
int fd; int fd;
@ -1315,11 +1326,6 @@ check_exec_redirect_fd(VALUE v, int iskey)
wrong: wrong:
rb_raise(rb_eArgError, "negative file descriptor"); 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); return INT2FIX(fd);
} }
@ -1357,7 +1363,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
break; break;
case T_FILE: case T_FILE:
val = check_exec_redirect_fd(val, 0); val = check_exec_redirect_fd(val);
/* fall through */ /* fall through */
case T_FIXNUM: case T_FIXNUM:
index = EXEC_OPTION_DUP2; 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) && if (RARRAY_LEN(val) == 2 && SYMBOL_P(path) &&
SYM2ID(path) == rb_intern("child")) { SYM2ID(path) == rb_intern("child")) {
index = EXEC_OPTION_DUP2_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 { else {
index = EXEC_OPTION_OPEN; index = EXEC_OPTION_OPEN;
@ -1393,7 +1399,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
path = val; path = val;
FilePathValue(path); FilePathValue(path);
if (TYPE(key) == T_FILE) 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)) if (FIXNUM_P(key) && (FIX2INT(key) == 1 || FIX2INT(key) == 2))
flags = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC); flags = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC);
else else
@ -1413,21 +1419,21 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
rb_ary_store(options, index, ary); rb_ary_store(options, index, ary);
} }
if (TYPE(key) != T_ARRAY) { 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))); rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
} }
else { else {
int i, n=0; int i, n=0;
for (i = 0 ; i < RARRAY_LEN(key); i++) { for (i = 0 ; i < RARRAY_LEN(key); i++) {
VALUE v = RARRAY_PTR(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))); rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
n++; n++;
} }
} }
} }
#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM) #ifdef RLIM2NUM
static int rlimit_type_by_lname(const char *name); static int rlimit_type_by_lname(const char *name);
#endif #endif
@ -1465,7 +1471,7 @@ rb_exec_arg_addopt(struct rb_exec_arg *e, VALUE key, VALUE val)
} }
else else
#endif #endif
#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM) #ifdef RLIM2NUM
if (strncmp("rlimit_", rb_id2name(id), 7) == 0 && if (strncmp("rlimit_", rb_id2name(id), 7) == 0 &&
(rtype = rlimit_type_by_lname(rb_id2name(id)+7)) != -1) { (rtype = rlimit_type_by_lname(rb_id2name(id)+7)) != -1) {
VALUE ary = rb_ary_entry(options, EXEC_OPTION_RLIMIT); 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 #endif
#if defined(HAVE_SETRLIMIT) && defined(RLIM2NUM) #ifdef RLIM2NUM
static int static int
run_exec_rlimit(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen) 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 #endif
#if defined(HAVE_SETRLIMIT) && defined(RLIM2NUM) #ifdef RLIM2NUM
obj = rb_ary_entry(options, EXEC_OPTION_RLIMIT); obj = rb_ary_entry(options, EXEC_OPTION_RLIMIT);
if (!NIL_P(obj)) { if (!NIL_P(obj)) {
if (run_exec_rlimit(obj, soptions, errmsg, errmsg_buflen) == -1) 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 #define proc_setpriority rb_f_notimplement
#endif #endif
#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM) #if defined(RLIM2NUM)
static int static int
rlimit_resource_name2int(const char *name, int casetype) rlimit_resource_name2int(const char *name, int casetype)
{ {
@ -4520,28 +4526,7 @@ proc_setgid(VALUE obj, VALUE id)
#endif #endif
/* static int maxgroups = 32;
* 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;
#ifdef HAVE_GETGROUPS #ifdef HAVE_GETGROUPS
@ -4563,13 +4548,9 @@ proc_getgroups(VALUE obj)
int i, ngroups; int i, ngroups;
rb_gid_t *groups; rb_gid_t *groups;
ngroups = getgroups(0, NULL); groups = ALLOCA_N(rb_gid_t, maxgroups);
if (ngroups == -1)
rb_sys_fail(0);
groups = ALLOCA_N(rb_gid_t, ngroups); ngroups = getgroups(maxgroups, groups);
ngroups = getgroups(ngroups, groups);
if (ngroups == -1) if (ngroups == -1)
rb_sys_fail(0); rb_sys_fail(0);
@ -4706,13 +4687,10 @@ proc_getmaxgroups(VALUE obj)
static VALUE static VALUE
proc_setmaxgroups(VALUE obj, VALUE val) proc_setmaxgroups(VALUE obj, VALUE val)
{ {
int ngroups = FIX2INT(val); int ngroups = FIX2UINT(val);
if (ngroups <= 0) if (ngroups > 4096)
rb_raise(rb_eArgError, "maxgroups %d shold be positive", ngroups); ngroups = 4096;
if (ngroups > RB_MAX_GROUPS)
ngroups = RB_MAX_GROUPS;
maxgroups = ngroups; 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, "getrlimit", proc_getrlimit, 1);
rb_define_module_function(rb_mProcess, "setrlimit", proc_setrlimit, -1); rb_define_module_function(rb_mProcess, "setrlimit", proc_setrlimit, -1);
#if defined(RLIM2NUM) && defined(RLIM_INFINITY) #ifdef RLIM2NUM
{ {
VALUE inf = RLIM2NUM(RLIM_INFINITY); VALUE inf = RLIM2NUM(RLIM_INFINITY);
#ifdef RLIM_SAVED_MAX #ifdef RLIM_SAVED_MAX

1
ruby.c
View file

@ -1544,6 +1544,7 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
rb_define_readonly_boolean("$-a", opt->do_split); rb_define_readonly_boolean("$-a", opt->do_split);
rb_set_safe_level(opt->safe_level); rb_set_safe_level(opt->safe_level);
rb_gc_set_params();
return iseq; return iseq;
} }

View file

@ -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); \ i = rb_strftime_with_timespec(s, endp - s, (fmt), vtm, timev, ts, gmt); \
if (!i) return 0; \ if (!i) return 0; \
if (precision > i) {\ if (precision > i) {\
if (start + maxsize < s + precision) { \
errno = ERANGE; \
return 0; \
} \
memmove(s + precision - i, s, i);\ memmove(s + precision - i, s, i);\
memset(s, padding ? padding : ' ', precision - i); \ memset(s, padding ? padding : ' ', precision - i); \
s += precision; \ s += precision; \

View file

@ -5164,7 +5164,7 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
else c = NUM2INT(tmp); else c = NUM2INT(tmp);
} }
else { else {
c = cflag ? last : errc; c = errc;
} }
if (c != errc) { if (c != errc) {
tlen = rb_enc_codelen(c, enc); tlen = rb_enc_codelen(c, enc);

View file

@ -1776,37 +1776,4 @@ End
end end
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 end

View file

@ -962,7 +962,6 @@ class TestM17N < Test::Unit::TestCase
assert_equal("X\u3042\u3044X", "A\u3042\u3044\u3046".tr("^\u3042\u3044", "X")) 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("\u3042\u3046" * 100, ("\u3042\u3044" * 100).tr("\u3044", "\u3046"))
assert_equal("Y", "\u3042".tr("^X", "Y"))
end end
def test_tr_s def test_tr_s

View file

@ -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]) Process.wait Process.spawn(*ECHO["c"], STDERR=>STDOUT, STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
assert_equal("c", File.read("out").chomp) assert_equal("c", File.read("out").chomp)
File.open("out", "w") {|f| 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) assert_equal("d", File.read("out").chomp)
} }
opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]} Process.wait Process.spawn(*ECHO["e"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644],
if /mswin|mingw/ !~ RUBY_PLATFORM 3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT)
opts.merge(3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT)
end
Process.wait Process.spawn(*ECHO["e"], opts)
assert_equal("e", File.read("out").chomp) assert_equal("e", File.read("out").chomp)
opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]} Process.wait Process.spawn(*ECHO["ee"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644],
if /mswin|mingw/ !~ RUBY_PLATFORM 3=>0, 4=>:in, 5=>STDIN,
opts.merge(3=>0, 4=>:in, 5=>STDIN, 6=>1, 7=>:out, 8=>STDOUT, 9=>2, 10=>:err, 11=>STDERR) 6=>1, 7=>:out, 8=>STDOUT,
end 9=>2, 10=>:err, 11=>STDERR)
Process.wait Process.spawn(*ECHO["ee"], opts)
assert_equal("ee", File.read("out").chomp) assert_equal("ee", File.read("out").chomp)
if /mswin|mingw/ !~ RUBY_PLATFORM if /mswin|mingw/ !~ RUBY_PLATFORM
# passing non-stdio fds is not supported on Windows # passing non-stdio fds is not supported on Windows

View file

@ -1944,36 +1944,4 @@ class TestString < Test::Unit::TestCase
assert_equal(S("hello world"), a) assert_equal(S("hello world"), a)
assert_equal(S("hello "), b) assert_equal(S("hello "), b)
end 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 end

View file

@ -91,13 +91,24 @@ class TestSystem < Test::Unit::TestCase
def test_system_at def test_system_at
if /mswin|mingw/ =~ RUBY_PLATFORM if /mswin|mingw/ =~ RUBY_PLATFORM
bug4393 = '[ruby-core:35218]' bug4393 = '[ruby-core:35218]'
bug4396 = '[ruby-core:35227]'
# @ + builtin command # @ + builtin command
assert_equal("foo\n", `@echo foo`, bug4393); assert_equal("foo\n", `@echo foo`, bug4393);
assert_equal("foo\n", `@@echo foo`, bug4393); 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| Dir.mktmpdir("ruby_script_tmp") {|tmpdir|
tmpfilename = "#{tmpdir}/ruby_script_tmp.#{$$}" tmpfilename = "#{tmpdir}/ruby_script_tmp.#{$$}"
@ -105,23 +116,16 @@ class TestSystem < Test::Unit::TestCase
tmp.print "foo\nbar\nbaz\n@foo"; tmp.print "foo\nbar\nbaz\n@foo";
tmp.close tmp.close
# @ + non builtin command
assert_match(/\Abar\nbaz\n?\z/, `@@findstr "ba" #{tmpfilename.gsub("/", "\\")}`, bug4393); 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
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 def test_empty_evstr
assert_equal("", eval('"#{}"', nil, __FILE__, __LINE__), "[ruby-dev:25113]") assert_equal("", eval('"#{}"', nil, __FILE__, __LINE__), "[ruby-dev:25113]")
end end

View file

@ -26,352 +26,6 @@ class TestGem < Gem::TestCase
util_remove_interrupt_command util_remove_interrupt_command
end 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 def test_self_all_load_paths
util_make_gems util_make_gems
@ -417,7 +71,7 @@ class TestGem < Gem::TestCase
end end
def test_self_bin_path_nonexistent_binfile def test_self_bin_path_nonexistent_binfile
quick_spec 'a', '2' do |s| quick_gem 'a', '2' do |s|
s.executables = ['exec'] s.executables = ['exec']
end end
assert_raises(Gem::GemNotFoundException) do assert_raises(Gem::GemNotFoundException) do
@ -426,7 +80,7 @@ class TestGem < Gem::TestCase
end end
def test_self_bin_path_no_bin_file def test_self_bin_path_no_bin_file
quick_spec 'a', '1' quick_gem 'a', '1'
assert_raises(Gem::Exception) do assert_raises(Gem::Exception) do
Gem.bin_path('a', nil, '1') Gem.bin_path('a', nil, '1')
end end
@ -440,7 +94,7 @@ class TestGem < Gem::TestCase
def test_self_bin_path_bin_file_gone_in_latest def test_self_bin_path_bin_file_gone_in_latest
util_exec_gem util_exec_gem
quick_spec 'a', '10' do |s| quick_gem 'a', '10' do |s|
s.executables = [] s.executables = []
s.default_executable = nil s.default_executable = nil
end end
@ -496,7 +150,7 @@ class TestGem < Gem::TestCase
fp.puts 'blah' fp.puts 'blah'
end 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 install_gem foo
end end
@ -558,7 +212,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories @gemhome Gem.ensure_gem_subdirectories @gemhome
assert File.directory?(Gem.cache_dir(@gemhome)) assert File.directory?(File.join(@gemhome, "cache"))
end end
def test_self_ensure_gem_directories_missing_parents def test_self_ensure_gem_directories_missing_parents
@ -570,7 +224,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories gemdir Gem.ensure_gem_subdirectories gemdir
assert File.directory?(Gem.cache_dir(gemdir)) assert File.directory?("#{gemdir}/cache")
end end
unless win_platform? then # only for FS that support write protection unless win_platform? then # only for FS that support write protection
@ -584,7 +238,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories gemdir Gem.ensure_gem_subdirectories gemdir
refute File.exist?(Gem.cache_dir(gemdir)) refute File.exist?("#{gemdir}/cache")
ensure ensure
FileUtils.chmod 0600, gemdir FileUtils.chmod 0600, gemdir
end end
@ -601,7 +255,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories gemdir Gem.ensure_gem_subdirectories gemdir
refute File.exist?(Gem.cache_dir(gemdir)) refute File.exist?("#{gemdir}/cache")
ensure ensure
FileUtils.chmod 0600, parent FileUtils.chmod 0600, parent
end end
@ -622,8 +276,8 @@ class TestGem < Gem::TestCase
def test_self_find_files def test_self_find_files
discover_path = File.join 'lib', 'sff', 'discover.rb' discover_path = File.join 'lib', 'sff', 'discover.rb'
cwd = File.expand_path("test/rubygems", @@project_dir) cwd = File.expand_path '..', __FILE__
$LOAD_PATH.unshift cwd $LOAD_PATH.unshift cwd.dup
foo1 = quick_gem 'sff', '1' do |s| foo1 = quick_gem 'sff', '1' do |s|
s.files << discover_path s.files << discover_path
@ -647,7 +301,7 @@ class TestGem < Gem::TestCase
Gem.searcher = nil Gem.searcher = nil
expected = [ 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(foo2.full_gem_path, discover_path),
File.join(foo1.full_gem_path, discover_path), File.join(foo1.full_gem_path, discover_path),
] ]
@ -673,7 +327,7 @@ class TestGem < Gem::TestCase
end end
def test_self_loaded_specs def test_self_loaded_specs
foo = quick_spec 'foo' foo = quick_gem 'foo'
install_gem foo install_gem foo
Gem.source_index = nil Gem.source_index = nil
@ -776,12 +430,22 @@ class TestGem < Gem::TestCase
end end
def test_self_prefix 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 end
def test_self_prefix_libdir def test_self_prefix_libdir
orig_libdir = Gem::ConfigMap[: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 assert_nil Gem.prefix
ensure ensure
@ -790,7 +454,12 @@ class TestGem < Gem::TestCase
def test_self_prefix_sitelibdir def test_self_prefix_sitelibdir
orig_sitelibdir = Gem::ConfigMap[: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 assert_nil Gem.prefix
ensure ensure
@ -954,20 +623,6 @@ class TestGem < Gem::TestCase
end end
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 if Gem.win_platform? then
def test_self_user_home_userprofile def test_self_user_home_userprofile
skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION 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 Dir.chdir @tempdir do
FileUtils.mkdir_p 'lib' FileUtils.mkdir_p 'lib'
File.open plugin_path, "w" do |fp| 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 end
foo = quick_spec 'foo', '1' do |s| foo = quick_gem 'foo', '1' do |s|
s.files << plugin_path s.files << plugin_path
end end
@ -1030,7 +685,6 @@ class TestGem < Gem::TestCase
end end
Gem.source_index = nil Gem.source_index = nil
Gem.searcher = nil
gem 'foo' gem 'foo'
@ -1041,24 +695,23 @@ class TestGem < Gem::TestCase
def test_load_env_plugins def test_load_env_plugins
with_plugin('load') { Gem.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 util_remove_interrupt_command
# Should attempt to cause a StandardError # Should attempt to cause a StandardError
with_plugin('standarderror') { Gem.load_env_plugins } 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 util_remove_interrupt_command
# Should attempt to cause an Exception # Should attempt to cause an Exception
with_plugin('exception') { Gem.load_env_plugins } with_plugin('exception') { Gem.load_env_plugins }
assert_equal :loaded, TEST_PLUGIN_EXCEPTION rescue nil assert_equal :loaded, TEST_PLUGIN_EXCEPTION
end end
def with_plugin(path) def with_plugin(path)
test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}", test_plugin_path = File.expand_path "../plugin/#{path}", __FILE__
@@project_dir)
# A single test plugin should get loaded once only, in order to preserve # A single test plugin should get loaded once only, in order to preserve
# sane test semantics. # sane test semantics.
@ -1080,7 +733,7 @@ class TestGem < Gem::TestCase
end end
def util_exec_gem def util_exec_gem
spec, _ = quick_spec 'a', '4' do |s| spec, _ = quick_gem 'a', '4' do |s|
s.default_executable = 'exec' s.default_executable = 'exec'
s.executables = ['exec', 'abin'] s.executables = ['exec', 'abin']
end end
@ -1124,5 +777,6 @@ class TestGem < Gem::TestCase
Gem::Commands.send :remove_const, :InterruptCommand if Gem::Commands.send :remove_const, :InterruptCommand if
Gem::Commands.const_defined? :InterruptCommand Gem::Commands.const_defined? :InterruptCommand
end end
end end

View file

@ -10,7 +10,7 @@ require 'rubygems/builder'
class TestGemBuilder < Gem::TestCase class TestGemBuilder < Gem::TestCase
def test_build def test_build
builder = Gem::Builder.new quick_spec('a') builder = Gem::Builder.new quick_gem('a')
use_ui @ui do use_ui @ui do
Dir.chdir @tempdir do Dir.chdir @tempdir do

View file

@ -17,7 +17,7 @@ class TestGemCommandManager < Gem::TestCase
def test_run_interrupt def test_run_interrupt
old_load_path = $:.dup old_load_path = $:.dup
$: << File.expand_path("test/rubygems", @@project_dir) $: << "test/rubygems"
Gem.load_env_plugins Gem.load_env_plugins
use_ui @ui do use_ui @ui do
@ -33,7 +33,7 @@ class TestGemCommandManager < Gem::TestCase
def test_run_crash_command def test_run_crash_command
old_load_path = $:.dup old_load_path = $:.dup
$: << File.expand_path("test/rubygems", @@project_dir) $: << "test/rubygems"
@command_manager.register_command :crash @command_manager.register_command :crash
use_ui @ui do use_ui @ui do

View file

@ -13,7 +13,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
def setup def setup
super super
@gem = quick_spec 'some_gem' do |s| @gem = quick_gem 'some_gem' do |s|
s.rubyforge_project = 'example' s.rubyforge_project = 'example'
end end

View file

@ -6,7 +6,6 @@
require 'rubygems/test_case' require 'rubygems/test_case'
require 'rubygems/commands/cert_command' require 'rubygems/commands/cert_command'
require 'rubygems/fix_openssl_warnings' if RUBY_VERSION < "1.9"
unless defined? OpenSSL then unless defined? OpenSSL then
warn "`gem cert` tests are being skipped, module OpenSSL not found" warn "`gem cert` tests are being skipped, module OpenSSL not found"
@ -22,7 +21,7 @@ class TestGemCommandsCertCommand < Gem::TestCase
@cmd = Gem::Commands::CertCommand.new @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-private_key.pem'), @tempdir
FileUtils.cp File.join(root, 'data', 'gem-public_cert.pem'), @tempdir FileUtils.cp File.join(root, 'data', 'gem-public_cert.pem'), @tempdir

View file

@ -32,7 +32,7 @@ class TestGemCommandsDependencyCommand < Gem::TestCase
@cmd.execute @cmd.execute
end 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 @ui.output
assert_equal '', @ui.error assert_equal '', @ui.error
end end
@ -83,7 +83,7 @@ Gem pl-1-x86-linux
end end
def test_execute_pipe_format def test_execute_pipe_format
quick_spec 'foo' do |gem| quick_gem 'foo' do |gem|
gem.add_dependency 'bar', '> 1' gem.add_dependency 'bar', '> 1'
end end
@ -127,7 +127,6 @@ Gem b-2
end end
def test_execute_reverse def test_execute_reverse
# FIX: this shouldn't need to write out, but fails if you switch it
quick_gem 'foo' do |gem| quick_gem 'foo' do |gem|
gem.add_dependency 'bar', '> 1' gem.add_dependency 'bar', '> 1'
end end
@ -147,9 +146,9 @@ Gem b-2
expected = <<-EOF expected = <<-EOF
Gem foo-2 Gem foo-2
bar (> 1) bar (> 1, runtime)
Used by Used by
baz-2 (foo (>= 0)) baz-2 (foo (>= 0, runtime))
EOF EOF
@ -195,7 +194,7 @@ ERROR: Only reverse dependencies for local gems are supported.
@cmd.execute @cmd.execute
end 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 assert_equal '', @ui.error
end end

View file

@ -22,7 +22,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
util_setup_spec_fetcher @a2 util_setup_spec_fetcher @a2
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = @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] @cmd.options[:args] = [@a2.name]
@ -41,9 +41,9 @@ class TestGemCommandsFetchCommand < Gem::TestCase
util_setup_spec_fetcher @a2, @a2_pre util_setup_spec_fetcher @a2, @a2_pre
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = @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}"] = @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[:args] = [@a2.name]
@cmd.options[:prerelease] = true @cmd.options[:prerelease] = true
@ -63,7 +63,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
util_setup_spec_fetcher @a1, @a2 util_setup_spec_fetcher @a1, @a2
@fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] = @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[:args] = [@a2.name]
@cmd.options[:version] = Gem::Requirement.new '1' @cmd.options[:version] = Gem::Requirement.new '1'

View file

@ -7,12 +7,6 @@
require 'rubygems/test_case' require 'rubygems/test_case'
require 'rubygems/commands/install_command' require 'rubygems/commands/install_command'
begin
gem "rdoc"
rescue Gem::LoadError
# ignore
end
class TestGemCommandsInstallCommand < Gem::TestCase class TestGemCommandsInstallCommand < Gem::TestCase
def setup def setup
@ -28,9 +22,9 @@ class TestGemCommandsInstallCommand < Gem::TestCase
util_setup_spec_fetcher @a2, @a2_pre util_setup_spec_fetcher @a2, @a2_pre
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = @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}"] = @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] @cmd.options[:args] = [@a2.name]
@ -50,12 +44,11 @@ class TestGemCommandsInstallCommand < Gem::TestCase
util_setup_spec_fetcher @a2, @a2_pre util_setup_spec_fetcher @a2, @a2_pre
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = @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}"] = @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, @cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s]
"--no-ri", "--no-rdoc"]
assert @cmd.options[:prerelease] assert @cmd.options[:prerelease]
assert @cmd.options[:version].satisfied_by?(@a2_pre.version) assert @cmd.options[:version].satisfied_by?(@a2_pre.version)
@ -92,7 +85,8 @@ class TestGemCommandsInstallCommand < Gem::TestCase
util_setup_fake_fetcher util_setup_fake_fetcher
@cmd.options[:domain] = :local @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] @cmd.options[:args] = [@a2.name]
@ -121,7 +115,8 @@ class TestGemCommandsInstallCommand < Gem::TestCase
util_setup_fake_fetcher util_setup_fake_fetcher
@cmd.options[:user_install] = false @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] @cmd.options[:args] = [@a2.name]
@ -188,7 +183,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase
correctly_spelled = "non_existent_with_hint" correctly_spelled = "non_existent_with_hint"
util_setup_fake_fetcher 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] @cmd.options[:args] = [misspelled]
@ -212,9 +207,9 @@ ERROR: Possible alternatives: non_existent_with_hint
util_setup_spec_fetcher @a2, @a2_pre util_setup_spec_fetcher @a2, @a2_pre
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = @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}"] = @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[:prerelease] = true
@cmd.options[:args] = [@a2_pre.name] @cmd.options[:args] = [@a2_pre.name]
@ -238,7 +233,7 @@ ERROR: Possible alternatives: non_existent_with_hint
util_setup_spec_fetcher @a2 util_setup_spec_fetcher @a2
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = @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] @cmd.options[:args] = [@a2.name]
@ -265,9 +260,11 @@ ERROR: Possible alternatives: non_existent_with_hint
util_setup_fake_fetcher util_setup_fake_fetcher
@cmd.options[:domain] = :local @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] @cmd.options[:args] = [@a2.name, @b2.name]
@ -296,7 +293,7 @@ ERROR: Possible alternatives: non_existent_with_hint
util_setup_spec_fetcher @b2 util_setup_spec_fetcher @b2
@fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] = @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) uninstall_gem(@b2)

View file

@ -51,7 +51,7 @@ gem 'a', '= 1'
expected = <<-EXPECTED expected = <<-EXPECTED
require 'rubygems' require 'rubygems'
gem 'd', '= 1' gem 'd', '= 1'
# Unable to satisfy 'z (>= 0)' from currently installed gems # Unable to satisfy 'z (>= 0, runtime)' from currently installed gems
EXPECTED EXPECTED
assert_equal expected, @ui.output assert_equal expected, @ui.output

View file

@ -22,11 +22,14 @@ class TestGemCommandsOutdatedCommand < Gem::TestCase
def test_execute def test_execute
quick_gem 'foo', '0.1' quick_gem 'foo', '0.1'
quick_gem 'foo', '0.2' quick_gem 'foo', '0.2'
remote_10 = quick_spec 'foo', '1.0' remote_10 = quick_gem 'foo', '1.0'
remote_20 = quick_spec 'foo', '2.0' remote_20 = quick_gem 'foo', '2.0'
remote_spec_file = File.join @gemhome, 'specifications', remote_10.spec_name 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 remote_spec_file = File.join @gemhome, 'specifications', remote_20.spec_name
FileUtils.rm remote_spec_file
@fetcher = Gem::FakeFetcher.new @fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher Gem::RemoteFetcher.fetcher = @fetcher

View file

@ -15,7 +15,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end end
def test_execute 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') FileUtils.mkdir_p File.join(@tempdir, 'bin')
File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp| File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
fp.puts "#!/usr/bin/ruby" fp.puts "#!/usr/bin/ruby"
@ -45,7 +45,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end end
def test_execute_all 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') FileUtils.mkdir_p File.join(@tempdir, 'bin')
File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp| File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
fp.puts "#!/usr/bin/ruby" fp.puts "#!/usr/bin/ruby"
@ -73,29 +73,15 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end end
def test_execute_missing_cache_gem def test_execute_missing_cache_gem
a = quick_spec 'a' do |s| a = quick_gem 'a' do |s| s.executables = %w[foo] end
s.executables = %w[foo]
end
FileUtils.mkdir_p File.join(@tempdir, 'bin') FileUtils.mkdir_p File.join(@tempdir, 'bin')
File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp| File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
fp.puts "#!/usr/bin/ruby" fp.puts "#!/usr/bin/ruby"
end end
install_gem a install_gem a
a_data = nil FileUtils.rm File.join(@gemhome, 'cache', a.file_name)
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)
@cmd.options[:args] = %w[a] @cmd.options[:args] = %w[a]
@ -105,17 +91,11 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n" out = @ui.output.split "\n"
[ assert_equal "Restoring gem\(s\) to pristine condition...", out.shift
"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_empty out, out.inspect 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 end
def test_execute_no_gem def test_execute_no_gem

View file

@ -16,7 +16,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end end
def test_execute def test_execute
foo = quick_spec 'foo' foo = quick_gem 'foo'
Gem.source_index.add_spec foo Gem.source_index.add_spec foo
@cmd.options[:args] = %w[foo] @cmd.options[:args] = %w[foo]
@ -31,8 +31,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end end
def test_execute_all def test_execute_all
quick_spec 'foo', '0.0.1' quick_gem 'foo', '0.0.1'
quick_spec 'foo', '0.0.2' quick_gem 'foo', '0.0.2'
@cmd.options[:args] = %w[foo] @cmd.options[:args] = %w[foo]
@cmd.options[:all] = true @cmd.options[:all] = true
@ -62,8 +62,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end end
def test_execute_exact_match def test_execute_exact_match
quick_spec 'foo' quick_gem 'foo'
quick_spec 'foo_bar' quick_gem 'foo_bar'
@cmd.options[:args] = %w[foo] @cmd.options[:args] = %w[foo]
@ -77,7 +77,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end end
def test_execute_field def test_execute_field
foo = quick_spec 'foo' foo = quick_gem 'foo'
Gem.source_index.add_spec foo Gem.source_index.add_spec foo
@cmd.options[:args] = %w[foo name] @cmd.options[:args] = %w[foo name]
@ -90,7 +90,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end end
def test_execute_marshal def test_execute_marshal
foo = quick_spec 'foo' foo = quick_gem 'foo'
Gem.source_index.add_spec foo Gem.source_index.add_spec foo
@cmd.options[:args] = %w[foo] @cmd.options[:args] = %w[foo]
@ -126,7 +126,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end end
def test_execute_ruby def test_execute_ruby
foo = quick_spec 'foo' foo = quick_gem 'foo'
Gem.source_index.add_spec foo Gem.source_index.add_spec foo
@cmd.options[:args] = %w[foo] @cmd.options[:args] = %w[foo]

View file

@ -16,11 +16,10 @@ class TestGemCommandsStaleCommand < Gem::TestCase
def test_execute_sorts def test_execute_sorts
files = %w[lib/foo_bar.rb Rakefile] 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 gem.files = files
end end
bar_baz = quick_gem 'bar_baz' do |gem|
bar_baz = quick_spec 'bar_baz' do |gem|
gem.files = files gem.files = files
end end
@ -37,7 +36,6 @@ class TestGemCommandsStaleCommand < Gem::TestCase
use_ui @ui do use_ui @ui do
@cmd.execute @cmd.execute
end end
lines = @ui.output.split("\n") lines = @ui.output.split("\n")
assert_equal("#{foo_bar.name}-#{foo_bar.version}", lines[0].split.first) assert_equal("#{foo_bar.name}-#{foo_bar.version}", lines[0].split.first)
assert_equal("#{bar_baz.name}-#{bar_baz.version}", lines[1].split.first) assert_equal("#{bar_baz.name}-#{bar_baz.version}", lines[1].split.first)

View file

@ -33,7 +33,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end end
end end
if win_platform? then if win_platform?
assert File.exist?(@executable) assert File.exist?(@executable)
else else
assert File.symlink?(@executable) assert File.symlink?(@executable)
@ -42,9 +42,9 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
# Evil hack to prevent false removal success # Evil hack to prevent false removal success
FileUtils.rm_f @executable 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 use_ui @ui do
@cmd.execute @cmd.execute
end end
@ -56,25 +56,6 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
assert_nil output.shift, "UI output should have contained only two lines" assert_nil output.shift, "UI output should have contained only two lines"
end 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 def test_execute_not_installed
@cmd.options[:args] = ["foo"] @cmd.options[:args] = ["foo"]
e = assert_raises Gem::InstallError do e = assert_raises Gem::InstallError do
@ -89,7 +70,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end end
def test_execute_prerelease def test_execute_prerelease
@spec = quick_spec "pre", "2.b" @spec = quick_gem "pre", "2.b"
@gem = File.join @tempdir, @spec.file_name @gem = File.join @tempdir, @spec.file_name
FileUtils.touch @gem FileUtils.touch @gem

View file

@ -22,7 +22,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
assert_equal( assert_equal(
@cmd.find_in_cache(@a1.file_name), @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' 'found a-1.gem in the cache'
) )
end end
@ -34,7 +34,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
a1_data = nil 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 a1_data = fp.read
end end
@ -44,15 +44,15 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
dep = Gem::Dependency.new(@a1.name, @a1.version) dep = Gem::Dependency.new(@a1.name, @a1.version)
assert_equal( assert_equal(
@cmd.get_path(dep), @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' '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( assert_equal(
@cmd.get_path(dep), @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' 'when removed from cache, refetches a-1'
) )
end end
@ -74,8 +74,6 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
def test_execute_gem_path def test_execute_gem_path
util_make_gems util_make_gems
util_setup_spec_fetcher
util_setup_fake_fetcher
Gem.clear_paths Gem.clear_paths
@ -123,7 +121,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
util_clear_gems util_clear_gems
a2_data = nil 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 a2_data = fp.read
end end
@ -177,8 +175,8 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end end
def test_execute_exact_match def test_execute_exact_match
foo_spec = quick_spec 'foo' foo_spec = quick_gem 'foo'
foo_bar_spec = quick_spec 'foo_bar' foo_bar_spec = quick_gem 'foo_bar'
use_ui @ui do use_ui @ui do
Dir.chdir @tempdir do Dir.chdir @tempdir do

View file

@ -7,12 +7,6 @@
require 'rubygems/test_case' require 'rubygems/test_case'
require 'rubygems/commands/update_command' require 'rubygems/commands/update_command'
begin
gem "rdoc"
rescue Gem::LoadError
# ignore
end
class TestGemCommandsUpdateCommand < Gem::TestCase class TestGemCommandsUpdateCommand < Gem::TestCase
def setup def setup
@ -25,8 +19,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
util_setup_fake_fetcher util_setup_fake_fetcher
@a1_path = Gem.cache_gem(@a1.file_name, @gemhome) @a1_path = File.join @gemhome, 'cache', @a1.file_name
@a2_path = Gem.cache_gem(@a2.file_name, @gemhome) @a2_path = File.join @gemhome, 'cache', @a2.file_name
util_setup_spec_fetcher @a1, @a2 util_setup_spec_fetcher @a1, @a2
@ -42,8 +36,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
Gem::Installer.new(@a1_path).install Gem::Installer.new(@a1_path).install
@cmd.options[:args] = [] @cmd.options[:args] = []
@cmd.options[:generate_rdoc] = false @cmd.options[:generate_rdoc] = true
@cmd.options[:generate_ri] = false @cmd.options[:generate_ri] = true
use_ui @ui do use_ui @ui do
@cmd.execute @cmd.execute
@ -54,153 +48,12 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
assert_equal "Updating #{@a2.name}", out.shift assert_equal "Updating #{@a2.name}", out.shift
assert_equal "Successfully installed #{@a2.full_name}", out.shift assert_equal "Successfully installed #{@a2.full_name}", out.shift
assert_equal "Gems updated: #{@a2.name}", out.shift assert_equal "Gems updated: #{@a2.name}", out.shift
assert_empty out assert_equal "Installing ri documentation for a-2...", out.shift
end assert_equal "Installing RDoc documentation for a-2...", out.shift
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 assert_empty out
end 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_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: # before:
# a1 -> c1.2 # a1 -> c1.2
# after: # after:
@ -210,7 +63,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_dependencies def test_execute_dependencies
@a1.add_dependency 'c', '1.2' @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.files = %w[lib/code.rb]
s.require_paths = %w[lib] s.require_paths = %w[lib]
end end
@ -218,9 +71,9 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@a2.add_dependency 'c', '2' @a2.add_dependency 'c', '2'
@a2.add_dependency 'b', '2' @a2.add_dependency 'b', '2'
@b2_path = Gem.cache_gem(@b2.file_name, @gemhome) @b2_path = File.join @gemhome, 'cache', @b2.file_name
@c1_2_path = Gem.cache_gem(@c1_2.file_name, @gemhome) @c1_2_path = File.join @gemhome, 'cache', @c1_2.file_name
@c2_path = Gem.cache_gem(@c2.file_name, @gemhome) @c2_path = File.join @gemhome, 'cache', @c2.file_name
@source_index = Gem::SourceIndex.new @source_index = Gem::SourceIndex.new
@source_index.add_spec @a1 @source_index.add_spec @a1
@ -319,39 +172,4 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
assert_empty out assert_empty out
end 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 end

View file

@ -283,20 +283,6 @@ class TestGemConfigFile < Gem::TestCase
assert_equal "701229f217cdf23b1344c7b4b54ca97", @cfg.rubygems_api_key assert_equal "701229f217cdf23b1344c7b4b54ca97", @cfg.rubygems_api_key
end 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) def util_config_file(args = @cfg_args)
@cfg = Gem::ConfigFile.new args @cfg = Gem::ConfigFile.new args
end end

View file

@ -106,45 +106,6 @@ class TestGemDependency < Gem::TestCase
refute_equal dep("pkg", :development), dep("pkg", :runtime), "type" refute_equal dep("pkg", :development), dep("pkg", :runtime), "type"
end 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 def test_prerelease_eh
d = dep "pkg", "= 1" d = dep "pkg", "= 1"

View file

@ -6,7 +6,6 @@
require 'rubygems/test_case' require 'rubygems/test_case'
require 'rubygems/dependency_installer' require 'rubygems/dependency_installer'
require 'rubygems/security'
class TestGemDependencyInstaller < Gem::TestCase class TestGemDependencyInstaller < Gem::TestCase
@ -14,20 +13,59 @@ class TestGemDependencyInstaller < Gem::TestCase
super super
@gems_dir = File.join @tempdir, 'gems' @gems_dir = File.join @tempdir, 'gems'
@cache_dir = Gem.cache_dir(@gemhome) @cache_dir = File.join @gemhome, 'cache'
FileUtils.mkdir @gems_dir FileUtils.mkdir @gems_dir
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 @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' @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_dependency 'a'
s.add_development_dependency 'aa' s.add_development_dependency 'aa'
end end
Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new @b1_pre, @b1_pre_gem = util_gem 'b', '1.a' do |s|
s.add_dependency 'a'
s.add_development_dependency 'aa'
end
util_reset_gems @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_clear_gems
end end
def test_install 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_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
assert Gem.cache_gem(@a1.file_name, @gemhome) assert File.exist?(File.join(@tempdir, 'cache', @a1.file_name))
assert Gem.cache_gem(@b1.file_name, @gemhome) assert File.exist?(File.join(@tempdir, 'cache', @b1.file_name))
end end
def test_install_dependencies_satisfied def test_install_dependencies_satisfied
@ -130,10 +168,6 @@ class TestGemDependencyInstaller < Gem::TestCase
end end
def test_install_dependency_development def test_install_dependency_development
@aa1, @aa1_gem = util_gem 'aa', '1'
util_reset_gems
FileUtils.mv @a1_gem, @tempdir FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @aa1_gem, @tempdir FileUtils.mv @aa1_gem, @tempdir
FileUtils.mv @b1_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_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?(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 end
def test_install_domain_both def test_install_domain_both
@ -342,13 +376,12 @@ class TestGemDependencyInstaller < Gem::TestCase
Gem.source_index.remove_spec @a1_pre.full_name Gem.source_index.remove_spec @a1_pre.full_name
Dir.chdir @tempdir do Dir.chdir @tempdir do
e = assert_raises Gem::DependencyError do e = assert_raises Gem::InstallError do
inst = Gem::DependencyInstaller.new :domain => :local inst = Gem::DependencyInstaller.new :domain => :local
inst.install 'b' inst.install 'b'
end end
expected = "Unable to resolve dependencies: b requires a (>= 0)" assert_equal 'b requires a (>= 0, runtime)', e.message
assert_equal expected, e.message
end end
assert_equal [], inst.installed_gems.map { |s| s.full_name } 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 } assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
end 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 def test_install_remote
a1_data = nil a1_data = nil
File.open @a1_gem, 'rb' do |fp| 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 } assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
end 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| a2_o, a2_o_gem = util_gem 'a', '2' do |s|
s.platform = Gem::Platform.new %w[cpu other_platform 1] s.platform = Gem::Platform.new %w[cpu other_platform 1]
end end
@ -471,6 +488,22 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
end 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 if defined? OpenSSL then
def test_install_security_policy def test_install_security_policy
data = File.open(@a1_gem, 'rb') { |f| f.read } data = File.open(@a1_gem, 'rb') { |f| f.read }
@ -506,8 +539,6 @@ class TestGemDependencyInstaller < Gem::TestCase
end end
def test_install_version def test_install_version
util_setup_d
data = File.open(@d2_gem, 'rb') { |f| f.read } data = File.open(@d2_gem, 'rb') { |f| f.read }
@fetcher.data['http://gems.example.com/gems/d-2.gem'] = data @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data
@ -522,8 +553,6 @@ class TestGemDependencyInstaller < Gem::TestCase
end end
def test_install_version_default def test_install_version_default
util_setup_d
data = File.open(@d2_gem, 'rb') { |f| f.read } data = File.open(@d2_gem, 'rb') { |f| f.read }
@fetcher.data['http://gems.example.com/gems/d-2.gem'] = data @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data
@ -590,22 +619,7 @@ class TestGemDependencyInstaller < Gem::TestCase
util_setup_spec_fetcher(*specs) util_setup_spec_fetcher(*specs)
inst = Gem::DependencyInstaller.new inst = Gem::DependencyInstaller.new
inst.find_spec_by_name_and_version specs.first.name inst.find_spec_by_name_and_version 'a'
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.gather_dependencies inst.gather_dependencies
actual = inst.gems_to_install.map { |s| s.full_name } 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 } assert_equal %w[a-1 b-1], inst.gems_to_install.map { |s| s.full_name }
end 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 def test_gather_dependencies_platform_alternate
util_setup_wxyz
util_set_arch 'cpu-my_platform1' 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 end
def test_gather_dependencies_platform_bump 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 end
def test_gather_dependencies_prerelease 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 end
def test_gather_dependencies_old_required def test_gather_dependencies_old_required
util_setup_d e1, = util_gem 'e', '1', 'd' => '= 1'
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
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
@w1, @w1_gem = util_spec 'w', '1', 'x' => nil
@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
util_reset_gems
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 util_clear_gems
util_setup_spec_fetcher @d1, @d2, e1
inst = Gem::DependencyInstaller.new
inst.find_spec_by_name_and_version 'e'
inst.gather_dependencies
assert_equal %w[d-1 e-1], inst.gems_to_install.map { |s| s.full_name }
end end
end end

View file

@ -14,17 +14,17 @@ class TestGemDependencyList < Gem::TestCase
@deplist = Gem::DependencyList.new @deplist = Gem::DependencyList.new
@a1 = quick_spec 'a', '1' @a1 = quick_gem 'a', '1'
@a2 = quick_spec 'a', '2' @a2 = quick_gem 'a', '2'
@a3 = quick_spec 'a', '3' @a3 = quick_gem 'a', '3'
@b1 = quick_spec 'b', '1' do |s| s.add_dependency 'a', '>= 1' end @b1 = quick_gem 'b', '1' do |s| s.add_dependency 'a', '>= 1' end
@b2 = quick_spec 'b', '2' 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 @c1 = quick_gem 'c', '1' do |s| s.add_dependency 'b', '>= 1' end
@c2 = quick_spec 'c', '2' @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 end
def test_self_from_source_index def test_self_from_source_index
@ -72,9 +72,9 @@ class TestGemDependencyList < Gem::TestCase
end end
def test_dependency_order_development def test_dependency_order_development
e1 = quick_spec 'e', '1' e1 = quick_gem 'e', '1'
f1 = quick_spec 'f', '1' f1 = quick_gem 'f', '1'
g1 = quick_spec 'g', '1' g1 = quick_gem 'g', '1'
@a1.add_dependency 'e' @a1.add_dependency 'e'
@a1.add_dependency 'f' @a1.add_dependency 'f'
@ -100,7 +100,7 @@ class TestGemDependencyList < Gem::TestCase
def test_dependency_order_diamond def test_dependency_order_diamond
util_diamond util_diamond
e1 = quick_spec 'e', '1' e1 = quick_gem 'e', '1'
@deplist.add e1 @deplist.add e1
@a1.add_dependency 'e', '>= 1' @a1.add_dependency 'e', '>= 1'
@ -128,8 +128,6 @@ class TestGemDependencyList < Gem::TestCase
end end
def test_ok_eh def test_ok_eh
util_clear_gems
assert @deplist.ok?, 'no dependencies' assert @deplist.ok?, 'no dependencies'
@deplist.add @b2 @deplist.add @b2
@ -141,30 +139,14 @@ class TestGemDependencyList < Gem::TestCase
assert @deplist.ok?, 'satisfied dependency' assert @deplist.ok?, 'satisfied dependency'
end 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 def test_ok_eh_mismatch
a1 = quick_spec 'a', '1' a1 = quick_gem 'a', '1'
a2 = quick_spec 'a', '2' a2 = quick_gem 'a', '2'
b = quick_spec 'b', '1' do |s| s.add_dependency 'a', '= 1' end b = quick_gem 'b', '1' do |s| s.add_dependency 'a', '= 1' end
c = quick_spec 'c', '1' do |s| s.add_dependency 'a', '= 2' 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 'b'
s.add_dependency 'c' s.add_dependency 'c'
end end
@ -210,8 +192,6 @@ class TestGemDependencyList < Gem::TestCase
end end
def test_remove_by_name def test_remove_by_name
util_clear_gems
@deplist.add @a1, @b2 @deplist.add @a1, @b2
@deplist.remove_by_name "a-1" @deplist.remove_by_name "a-1"

View file

@ -12,26 +12,25 @@ class TestGemDocManager < Gem::TestCase
def setup def setup
super super
@spec = quick_gem 'a', 2 @spec = quick_gem 'a'
@manager = Gem::DocManager.new(@spec) @manager = Gem::DocManager.new(@spec)
end end
def test_uninstall_doc_unwritable def test_uninstall_doc_unwritable
path = @spec.installation_path orig_mode = File.stat(@spec.installation_path).mode
orig_mode = File.stat(path).mode
# File.chmod has no effect on MS Windows directories (it needs ACL). # File.chmod has no effect on MS Windows directories (it needs ACL).
if win_platform? if win_platform?
skip("test_uninstall_doc_unwritable skipped on MS Windows") skip("test_uninstall_doc_unwritable skipped on MS Windows")
else else
File.chmod 0000, path File.chmod(0, @spec.installation_path)
end end
assert_raises Gem::FilePermissionError do assert_raises Gem::FilePermissionError do
@manager.uninstall_doc @manager.uninstall_doc
end end
ensure ensure
File.chmod orig_mode, path File.chmod orig_mode, @spec.installation_path
end end
end end

View file

@ -5,7 +5,7 @@
###################################################################### ######################################################################
require 'rubygems/package/tar_test_case' require 'rubygems/package/tar_test_case'
require 'rubygems/simple_gem' require 'test/rubygems/simple_gem'
require 'rubygems/format' require 'rubygems/format'
class TestGemFormat < Gem::Package::TarTestCase class TestGemFormat < Gem::Package::TarTestCase
@ -20,7 +20,7 @@ class TestGemFormat < Gem::Package::TarTestCase
def test_class_from_file_by_path def test_class_from_file_by_path
util_make_gems 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| names = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].map do |spec|
spec.original_name spec.original_name

View file

@ -18,20 +18,21 @@ class TestGemIndexer < Gem::TestCase
util_make_gems 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 s.date = Gem::Specification::TODAY - 86400 * 3
end end
util_build_gem @d2_0 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 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 util_build_gem @d2_0_b
gems = File.join(@tempdir, 'gems') gems = File.join(@tempdir, 'gems')
FileUtils.mkdir_p 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', @indexer = Gem::Indexer.new @tempdir, :rss_title => 'ExampleForge gems',
:rss_host => 'example.com', :rss_host => 'example.com',
@ -59,7 +60,7 @@ class TestGemIndexer < Gem::TestCase
end end
def test_build_indicies def test_build_indicies
spec = quick_spec 'd', '2.0' spec = quick_gem 'd', '2.0'
spec.instance_variable_set :@original_platform, '' spec.instance_variable_set :@original_platform, ''
@indexer.make_temp_directories @indexer.make_temp_directories
@ -509,17 +510,17 @@ eighty characters.&lt;/pre&gt;
assert File.directory?(quickdir) assert File.directory?(quickdir)
assert File.directory?(marshal_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 util_build_gem @d2_1
@d2_1_tuple = [@d2_1.name, @d2_1.version, @d2_1.original_platform] @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 util_build_gem @d2_1_a
@d2_1_a_tuple = [@d2_1_a.name, @d2_1_a.version, @d2_1_a.original_platform] @d2_1_a_tuple = [@d2_1_a.name, @d2_1_a.version, @d2_1_a.original_platform]
gems = File.join @tempdir, 'gems' gems = File.join @tempdir, 'gems'
FileUtils.mv Gem.cache_gem(@d2_1.file_name, @gemhome), gems FileUtils.mv File.join(@gemhome, 'cache', @d2_1.file_name), gems
FileUtils.mv Gem.cache_gem(@d2_1_a.file_name, @gemhome), gems FileUtils.mv File.join(@gemhome, 'cache', @d2_1_a.file_name), gems
use_ui @ui do use_ui @ui do
@indexer.update_index @indexer.update_index

View file

@ -69,4 +69,6 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
ensure ensure
FileUtils.chmod 0755, @gemhome FileUtils.chmod 0755, @gemhome
end end
end end

View file

@ -9,8 +9,7 @@ require 'rubygems/installer_test_case'
class TestGemInstaller < Gem::InstallerTestCase class TestGemInstaller < Gem::InstallerTestCase
def test_app_script_text def test_app_script_text
@spec.version = 2 util_make_exec '2', ''
util_make_exec @spec, ''
expected = <<-EOF expected = <<-EOF
#!#{Gem.ruby} #!#{Gem.ruby}
@ -31,10 +30,10 @@ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
end end
gem 'a', version gem 'a', version
load Gem.bin_path('a', 'executable', version) load Gem.bin_path('a', 'my_exec', version)
EOF EOF
wrapper = @installer.app_script_text 'executable' wrapper = @installer.app_script_text 'my_exec'
assert_equal expected, wrapper assert_equal expected, wrapper
end end
@ -102,7 +101,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.ensure_dependency @spec, dep @installer.ensure_dependency @spec, dep
end end
assert_equal 'a requires b (> 2)', e.message assert_equal 'a requires b (> 2, runtime)', e.message
end end
def test_extract_files def test_extract_files
@ -171,11 +170,11 @@ load Gem.bin_path('a', 'executable', version)
def test_generate_bin_bindir def test_generate_bin_bindir
@installer.wrappers = true @installer.wrappers = true
@spec.executables = %w[executable] @spec.executables = ["my_exec"]
@spec.bindir = '.' @spec.bindir = '.'
exec_file = @installer.formatted_program_filename 'executable' exec_file = @installer.formatted_program_filename "my_exec"
exec_path = File.join util_gem_dir(@spec), exec_file exec_path = File.join util_gem_dir(@spec.version), exec_file
File.open exec_path, 'w' do |f| File.open exec_path, 'w' do |f|
f.puts '#!/usr/bin/ruby' f.puts '#!/usr/bin/ruby'
end end
@ -185,7 +184,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.generate_bin @installer.generate_bin
assert_equal true, File.directory?(util_inst_bindir) 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 true, File.exist?(installed_exec)
assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? 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 @installer.generate_bin
assert_equal true, File.directory?(util_inst_bindir) 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 true, File.exist?(installed_exec)
assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? 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' Gem::Installer.exec_format = 'foo-%s-bar'
@installer.generate_bin @installer.generate_bin
assert_equal true, File.directory?(util_inst_bindir) 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) assert_equal true, File.exist?(installed_exec)
ensure ensure
Gem::Installer.exec_format = nil Gem::Installer.exec_format = nil
@ -231,7 +230,7 @@ load Gem.bin_path('a', 'executable', version)
Gem::Installer.exec_format = 'foo-%s-bar' Gem::Installer.exec_format = 'foo-%s-bar'
@installer.generate_bin @installer.generate_bin
assert_equal true, File.directory?(util_inst_bindir) 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 true, File.exist?(installed_exec)
ensure ensure
Gem::Installer.exec_format = nil Gem::Installer.exec_format = nil
@ -239,12 +238,12 @@ load Gem.bin_path('a', 'executable', version)
def test_generate_bin_script_install_dir def test_generate_bin_script_install_dir
@installer.wrappers = true @installer.wrappers = true
@spec.executables = %w[executable] @spec.executables = ["my_exec"]
gem_dir = File.join "#{@gemhome}2", 'gems', @spec.full_name gem_dir = File.join "#{@gemhome}2", 'gems', @spec.full_name
gem_bindir = File.join gem_dir, 'bin' gem_bindir = File.join gem_dir, 'bin'
FileUtils.mkdir_p gem_bindir 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" f.puts "#!/bin/ruby"
end end
@ -253,7 +252,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.generate_bin @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 true, File.exist?(installed_exec)
assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform?
@ -262,12 +261,9 @@ load Gem.bin_path('a', 'executable', version)
end end
def test_generate_bin_script_no_execs def test_generate_bin_script_no_execs
util_execless
@installer.wrappers = true @installer.wrappers = true
@installer.generate_bin @installer.generate_bin
assert_equal false, File.exist?(util_inst_bindir)
refute File.exist?(util_inst_bindir), 'bin dir was created when not needed'
end end
def test_generate_bin_script_no_perms 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 def test_generate_bin_script_no_shebang
@installer.wrappers = true @installer.wrappers = true
@spec.executables = %w[executable] @spec.executables = ["my_exec"]
gem_dir = File.join @gemhome, 'gems', @spec.full_name gem_dir = File.join @gemhome, 'gems', @spec.full_name
gem_bindir = File.join gem_dir, 'bin' gem_bindir = File.join gem_dir, 'bin'
FileUtils.mkdir_p gem_bindir 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" f.puts "blah blah blah"
end end
@installer.generate_bin @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 true, File.exist?(installed_exec)
assert_equal 0100755, File.stat(installed_exec).mode unless win_platform? 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 @installer.wrappers = true
util_make_exec util_make_exec
@installer.gem_dir = util_gem_dir @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 # fake --no-wrappers for previous install
unless Gem.win_platform? then unless Gem.win_platform? then
@ -346,19 +342,16 @@ load Gem.bin_path('a', 'executable', version)
@installer.generate_bin @installer.generate_bin
assert_equal true, File.directory?(util_inst_bindir) 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 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)) File.readlink(installed_exec))
end end
def test_generate_bin_symlink_no_execs def test_generate_bin_symlink_no_execs
util_execless
@installer.wrappers = false @installer.wrappers = false
@installer.generate_bin @installer.generate_bin
assert_equal false, File.exist?(util_inst_bindir)
refute File.exist?(util_inst_bindir)
end end
def test_generate_bin_symlink_no_perms 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.gem_dir = util_gem_dir
@installer.generate_bin @installer.generate_bin
installed_exec = File.join(util_inst_bindir, 'executable') installed_exec = File.join(util_inst_bindir, "my_exec")
assert_equal(File.join(util_gem_dir, 'bin', 'executable'), assert_equal(File.join(util_gem_dir, "bin", "my_exec"),
File.readlink(installed_exec)) File.readlink(installed_exec))
@spec = Gem::Specification.new do |s| @spec = Gem::Specification.new do |s|
@ -402,12 +395,11 @@ load Gem.bin_path('a', 'executable', version)
s.require_path = 'lib' s.require_path = 'lib'
end end
@spec.version = 3 util_make_exec '3'
util_make_exec @installer.gem_dir = File.join util_gem_dir('3')
@installer.gem_dir = File.join util_gem_dir @spec
@installer.generate_bin @installer.generate_bin
installed_exec = File.join(util_inst_bindir, 'executable') installed_exec = File.join(util_inst_bindir, "my_exec")
assert_equal(File.join(util_gem_bindir(@spec), 'executable'), assert_equal(File.join(util_gem_bindir('3'), "my_exec"),
File.readlink(installed_exec), File.readlink(installed_exec),
"Ensure symlink moved to latest version") "Ensure symlink moved to latest version")
end end
@ -420,8 +412,8 @@ load Gem.bin_path('a', 'executable', version)
@installer.gem_dir = util_gem_dir @installer.gem_dir = util_gem_dir
@installer.generate_bin @installer.generate_bin
installed_exec = File.join(util_inst_bindir, 'executable') installed_exec = File.join(util_inst_bindir, "my_exec")
assert_equal(File.join(util_gem_dir, 'bin', 'executable'), assert_equal(File.join(util_gem_dir, "bin", "my_exec"),
File.readlink(installed_exec)) File.readlink(installed_exec))
spec = Gem::Specification.new do |s| spec = Gem::Specification.new do |s|
@ -433,16 +425,14 @@ load Gem.bin_path('a', 'executable', version)
s.require_path = 'lib' s.require_path = 'lib'
end end
util_make_exec util_make_exec '1'
one = @spec.dup @installer.gem_dir = util_gem_dir('1')
one.version = 1
@installer.gem_dir = util_gem_dir one
@installer.spec = spec @installer.spec = spec
@installer.generate_bin @installer.generate_bin
installed_exec = File.join(util_inst_bindir, 'executable') installed_exec = File.join(util_inst_bindir, "my_exec")
assert_equal(File.join(util_gem_dir, 'bin', 'executable'), assert_equal(File.join(util_gem_dir('2'), "bin", "my_exec"),
File.readlink(installed_exec), File.readlink(installed_exec),
"Ensure symlink not moved") "Ensure symlink not moved")
end end
@ -455,7 +445,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.gem_dir = util_gem_dir @installer.gem_dir = util_gem_dir
@installer.generate_bin @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) assert_equal true, File.exist?(installed_exec)
@spec = Gem::Specification.new do |s| @spec = Gem::Specification.new do |s|
@ -468,12 +458,11 @@ load Gem.bin_path('a', 'executable', version)
end end
@installer.wrappers = false @installer.wrappers = false
@spec.version = 3 util_make_exec '3'
util_make_exec @installer.gem_dir = util_gem_dir '3'
@installer.gem_dir = util_gem_dir
@installer.generate_bin @installer.generate_bin
installed_exec = File.join(util_inst_bindir, 'executable') installed_exec = File.join(util_inst_bindir, "my_exec")
assert_equal(File.join(util_gem_dir, 'bin', 'executable'), assert_equal(File.join(util_gem_dir('3'), "bin", "my_exec"),
File.readlink(installed_exec), File.readlink(installed_exec),
"Ensure symlink moved to latest version") "Ensure symlink moved to latest version")
end end
@ -490,7 +479,7 @@ load Gem.bin_path('a', 'executable', version)
end end
assert_equal true, File.directory?(util_inst_bindir) 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 true, File.exist?(installed_exec)
assert_match(/Unable to use symlinks on Windows, installing wrapper/i, 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 @installer.generate_bin
default_shebang = Gem.ruby 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(/\A#!/, shebang_line)
assert_match(/#{default_shebang}/, shebang_line) assert_match(/#{default_shebang}/, shebang_line)
end end
def test_initialize 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 gem = File.join @tempdir, spec.file_name
Dir.mkdir util_inst_bindir Dir.mkdir util_inst_bindir
util_build_gem spec 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 installer = Gem::Installer.new gem
@ -535,7 +525,7 @@ load Gem.bin_path('a', 'executable', version)
util_clear_gems util_clear_gems
gemdir = File.join @gemhome, 'gems', @spec.full_name 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' stub_exe = File.join @gemhome, 'bin', 'executable'
rakefile = File.join gemdir, 'ext', 'a', 'Rakefile' 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 assert_same @installer, @pre_install_hook_arg
end 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 def test_install_bad_gem
gem = nil gem = nil
@ -656,7 +610,7 @@ load Gem.bin_path('a', 'executable', version)
gemhome2 = "#{@gemhome}2" gemhome2 = "#{@gemhome}2"
@spec.add_dependency 'b' @spec.add_dependency 'b'
b2 = quick_spec 'b', 2 b2 = quick_gem 'b', 2
FileUtils.mv @gemhome, gemhome2 FileUtils.mv @gemhome, gemhome2
Gem.source_index.gems.delete b2.full_name Gem.source_index.gems.delete b2.full_name
@ -712,7 +666,7 @@ load Gem.bin_path('a', 'executable', version)
end end
def test_install_missing_dirs 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, 'docs')
FileUtils.rm_f File.join(Gem.dir, 'specifications') FileUtils.rm_f File.join(Gem.dir, 'specifications')
@ -722,11 +676,11 @@ load Gem.bin_path('a', 'executable', version)
@installer.install @installer.install
end 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, 'docs')
File.directory? File.join(Gem.dir, 'specifications') 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)) assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name))
end end
@ -832,13 +786,13 @@ load Gem.bin_path('a', 'executable', version)
end end
def test_install_wrong_rubygems_version 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' s.required_rubygems_version = '< 0'
end end
util_build_gem spec util_build_gem spec
gem = Gem.cache_gem(spec.file_name, @gemhome) gem = File.join @gemhome, 'cache', spec.file_name
use_ui @ui do use_ui @ui do
@installer = Gem::Installer.new gem @installer = Gem::Installer.new gem
@ -859,49 +813,49 @@ load Gem.bin_path('a', 'executable', version)
end end
def test_shebang 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 assert_equal "#!#{Gem.ruby}", shebang
end end
def test_shebang_arguments 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 assert_equal "#!#{Gem.ruby} -ws", shebang
end end
def test_shebang_empty 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 assert_equal "#!#{Gem.ruby}", shebang
end end
def test_shebang_env 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 assert_equal "#!#{Gem.ruby}", shebang
end end
def test_shebang_env_arguments 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 assert_equal "#!#{Gem.ruby} -ws", shebang
end end
def test_shebang_env_shebang def test_shebang_env_shebang
util_make_exec @spec, '' util_make_exec '2', ''
@installer.env_shebang = true @installer.env_shebang = true
shebang = @installer.shebang 'executable' shebang = @installer.shebang 'my_exec'
env_shebang = "/usr/bin/env" unless Gem.win_platform? env_shebang = "/usr/bin/env" unless Gem.win_platform?
@ -910,49 +864,49 @@ load Gem.bin_path('a', 'executable', version)
end end
def test_shebang_nested 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 assert_equal "#!#{Gem.ruby}", shebang
end end
def test_shebang_nested_arguments 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 assert_equal "#!#{Gem.ruby} -ws", shebang
end end
def test_shebang_version 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 assert_equal "#!#{Gem.ruby}", shebang
end end
def test_shebang_version_arguments 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 assert_equal "#!#{Gem.ruby} -ws", shebang
end end
def test_shebang_version_env 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 assert_equal "#!#{Gem.ruby}", shebang
end end
def test_shebang_version_env_arguments 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 assert_equal "#!#{Gem.ruby} -ws", shebang
end end
@ -983,41 +937,14 @@ load Gem.bin_path('a', 'executable', version)
assert_equal @spec, eval(File.read(spec_file)) assert_equal @spec, eval(File.read(spec_file))
end 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 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' s.required_ruby_version = '= 1.4.6'
end end
util_build_gem spec util_build_gem spec
Gem.cache_gem(spec.file_name, @gemhome) File.join @gemhome, 'cache', spec.file_name
end
def util_execless
@spec = quick_spec 'z'
gem = File.join @tempdir, @spec.file_name
@installer = util_installer @spec, gem, @gemhome
end end
end end

View file

@ -55,9 +55,6 @@ class TestGemPackageTarOutput < Gem::Package::TarTestCase
if defined? OpenSSL then if defined? OpenSSL then
def test_self_open_signed 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] signer = Gem::Security::Signer.new @private_key, [@public_cert]
open @file, 'wb' do |tar_io| open @file, 'wb' do |tar_io|

View file

@ -99,10 +99,9 @@ gems:
# REFACTOR: copied from test_gem_dependency_installer.rb # REFACTOR: copied from test_gem_dependency_installer.rb
@gems_dir = File.join @tempdir, 'gems' @gems_dir = File.join @tempdir, 'gems'
@cache_dir = Gem.cache_dir(@gemhome) @cache_dir = File.join @gemhome, 'cache'
FileUtils.mkdir @gems_dir 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 @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
Gem::RemoteFetcher.fetcher = nil Gem::RemoteFetcher.fetcher = nil
@ -209,7 +208,7 @@ gems:
fetcher = util_fuck_with_fetcher a1_data 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 a1_cache_gem, fetcher.download(@a1, 'http://gems.example.com')
assert_equal("http://gems.example.com/gems/a-1.gem", assert_equal("http://gems.example.com/gems/a-1.gem",
fetcher.instance_variable_get(:@test_arg).to_s) fetcher.instance_variable_get(:@test_arg).to_s)
@ -221,7 +220,7 @@ gems:
inst = Gem::RemoteFetcher.fetcher 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') inst.download(@a1, 'http://gems.example.com')
end end
@ -234,7 +233,7 @@ gems:
inst = Gem::RemoteFetcher.fetcher inst = Gem::RemoteFetcher.fetcher
end end
assert_equal Gem.cache_gem(@a1.file_name, @gemhome), assert_equal File.join(@gemhome, 'cache', @a1.file_name),
inst.download(@a1, local_path) inst.download(@a1, local_path)
end end
@ -249,7 +248,7 @@ gems:
inst = Gem::RemoteFetcher.fetcher inst = Gem::RemoteFetcher.fetcher
end end
assert_equal Gem.cache_gem(@a1.file_name, @gemhome), assert_equal File.join(@gemhome, 'cache', @a1.file_name),
inst.download(@a1, local_path) inst.download(@a1, local_path)
end end
@ -263,7 +262,7 @@ gems:
install_dir = File.join @tempdir, 'more_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)) FileUtils.mkdir_p(File.dirname(a1_cache_gem))
actual = fetcher.download(@a1, 'http://gems.example.com', install_dir) actual = fetcher.download(@a1, 'http://gems.example.com', install_dir)
@ -279,7 +278,7 @@ gems:
FileUtils.mv @a1_gem, @tempdir FileUtils.mv @a1_gem, @tempdir
local_path = File.join @tempdir, @a1.file_name local_path = File.join @tempdir, @a1.file_name
inst = nil inst = nil
File.chmod 0555, Gem.cache_dir(@gemhome) File.chmod 0555, File.join(@gemhome, 'cache')
Dir.chdir @tempdir do Dir.chdir @tempdir do
inst = Gem::RemoteFetcher.fetcher inst = Gem::RemoteFetcher.fetcher
@ -288,19 +287,19 @@ gems:
assert_equal File.join(@tempdir, @a1.file_name), assert_equal File.join(@tempdir, @a1.file_name),
inst.download(@a1, local_path) inst.download(@a1, local_path)
ensure ensure
File.chmod 0755, Gem.cache_dir(@gemhome) File.chmod 0755, File.join(@gemhome, 'cache')
end end
def test_download_read_only 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) File.chmod 0555, File.join(@gemhome)
fetcher = util_fuck_with_fetcher File.read(@a1_gem) fetcher = util_fuck_with_fetcher File.read(@a1_gem)
fetcher.download(@a1, 'http://gems.example.com') 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 ensure
File.chmod 0755, @gemhome File.chmod 0755, File.join(@gemhome)
File.chmod 0755, Gem.cache_dir(@gemhome) File.chmod 0755, File.join(@gemhome, 'cache')
end end
end end
@ -319,7 +318,7 @@ gems:
fetcher = util_fuck_with_fetcher e1_data, :blow_chunks 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') assert_equal e1_cache_gem, fetcher.download(e1, 'http://gems.example.com')
@ -337,7 +336,7 @@ gems:
inst = Gem::RemoteFetcher.fetcher inst = Gem::RemoteFetcher.fetcher
end 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 FileUtils.mv local_path, cache_path
gem = Gem::Format.from_file_by_path cache_path gem = Gem::Format.from_file_by_path cache_path
@ -745,13 +744,5 @@ gems:
end end
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 end

View file

@ -23,7 +23,7 @@ class TestGemSourceIndex < Gem::TestCase
FileUtils.mkdir_p spec_dir 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 spec_file = File.join spec_dir, a1.spec_name
@ -44,7 +44,7 @@ class TestGemSourceIndex < Gem::TestCase
FileUtils.mkdir_p spec_dir 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 spec_file = File.join spec_dir, a1.spec_name
@ -214,24 +214,24 @@ end
end end
def test_latest_specs def test_latest_specs
p1_ruby = quick_spec 'p', '1' p1_ruby = quick_gem 'p', '1'
p1_platform = quick_spec 'p', '1' do |spec| p1_platform = quick_gem 'p', '1' do |spec|
spec.platform = Gem::Platform::CURRENT spec.platform = Gem::Platform::CURRENT
end 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' s.platform = Gem::Platform.new 'x86-my_platform1'
end 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' s.platform = Gem::Platform.new 'x86-my_platform1'
end 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' s.platform = Gem::Platform.new 'x86-other_platform1'
end 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' s.platform = Gem::Platform.new 'x86-other_platform1'
end end
@ -266,8 +266,8 @@ end
FileUtils.mkdir_p spec_dir1 FileUtils.mkdir_p spec_dir1
FileUtils.mkdir_p spec_dir2 FileUtils.mkdir_p spec_dir2
a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end a1 = quick_gem 'a', '1' do |spec| spec.author = 'author 1' end
a2 = quick_spec 'a', '1' do |spec| spec.author = 'author 2' 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| File.open File.join(spec_dir1, a1.spec_name), 'w' do |fp|
fp.write a1.to_ruby fp.write a1.to_ruby
@ -287,12 +287,12 @@ end
assert_equal [], @source_index.outdated 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 util_setup_spec_fetcher updated
assert_equal [updated.name], @source_index.outdated 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' s.platform = Gem::Platform.new 'x86-other_platform1'
end end
@ -302,11 +302,10 @@ end
end end
def test_prerelease_specs_kept_in_right_place 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 @source_index.add_spec gem_a1_alpha
refute @source_index.latest_specs.include?(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.find_name(gem_a1_alpha.full_name).empty?
assert @source_index.prerelease_specs.include?(gem_a1_alpha) assert @source_index.prerelease_specs.include?(gem_a1_alpha)
end end
@ -364,11 +363,11 @@ end
def test_search_platform def test_search_platform
util_set_arch 'x86-my_platform1' util_set_arch 'x86-my_platform1'
a1 = quick_spec 'a', '1' a1 = quick_gem 'a', '1'
a1_mine = quick_spec 'a', '1' do |s| a1_mine = quick_gem 'a', '1' do |s|
s.platform = Gem::Platform.new 'x86-my_platform1' s.platform = Gem::Platform.new 'x86-my_platform1'
end 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' s.platform = Gem::Platform.new 'x86-other_platform1'
end end

View file

@ -16,7 +16,7 @@ class TestGemSpecFetcher < Gem::TestCase
util_setup_fake_fetcher 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 @pl1
@source_index.add_spec @a_pre @source_index.add_spec @a_pre
@ -412,10 +412,5 @@ class TestGemSpecFetcher < Gem::TestCase
assert_equal @latest_specs, latest_specs assert_equal @latest_specs, latest_specs
end 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 end

View file

@ -46,7 +46,6 @@ end
def setup def setup
super super
# TODO: there is no reason why the spec tests need to write to disk
@a1 = quick_gem 'a', '1' do |s| @a1 = quick_gem 'a', '1' do |s|
s.executable = 'exec' s.executable = 'exec'
s.extensions << 'ext/a/extconf.rb' s.extensions << 'ext/a/extconf.rb'
@ -168,13 +167,6 @@ end
Gem::Specification.normalize_yaml_input(StringIO.new(input)) Gem::Specification.normalize_yaml_input(StringIO.new(input))
end 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 def test_initialize
spec = Gem::Specification.new do |s| spec = Gem::Specification.new do |s|
s.name = "blah" s.name = "blah"
@ -302,7 +294,7 @@ end
end end
def test_add_dependency_with_explicit_type 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" awesome.add_development_dependency "monkey"
end end
@ -379,19 +371,18 @@ end
assert_equal [rake, jabber, pqa], @a1.dependencies assert_equal [rake, jabber, pqa], @a1.dependencies
end end
def test_dependencies def test_dependencies_scoped_by_type
util_setup_deps gem = quick_gem "awesome", "1.0" do |awesome|
assert_equal [@bonobo, @monkey], @gem.dependencies awesome.add_runtime_dependency "bonobo", []
awesome.add_development_dependency "monkey", []
end end
def test_runtime_dependencies bonobo = Gem::Dependency.new("bonobo", [])
util_setup_deps monkey = Gem::Dependency.new("monkey", [], :development)
assert_equal [@bonobo], @gem.runtime_dependencies
end
def test_development_dependencies assert_equal([bonobo, monkey], gem.dependencies)
util_setup_deps assert_equal([bonobo], gem.runtime_dependencies)
assert_equal [@monkey], @gem.development_dependencies assert_equal([monkey], gem.development_dependencies)
end end
def test_description def test_description
@ -399,8 +390,8 @@ end
end end
def test_eql_eh def test_eql_eh
g1 = quick_spec 'gem' g1 = quick_gem 'gem'
g2 = quick_spec 'gem' g2 = quick_gem 'gem'
assert_equal g1, g2 assert_equal g1, g2
assert_equal g1.hash, g2.hash assert_equal g1.hash, g2.hash
@ -699,7 +690,7 @@ end
end end
def test_prerelease_spec_adds_required_rubygems_version 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')) 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')) assert @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.4.0'))
end end
@ -725,8 +716,8 @@ end
end end
def test_spaceship_name def test_spaceship_name
s1 = quick_spec 'a', '1' s1 = quick_gem 'a', '1'
s2 = quick_spec 'b', '1' s2 = quick_gem 'b', '1'
assert_equal(-1, (s1 <=> s2)) assert_equal(-1, (s1 <=> s2))
assert_equal( 0, (s1 <=> s1)) assert_equal( 0, (s1 <=> s1))
@ -734,8 +725,8 @@ end
end end
def test_spaceship_platform def test_spaceship_platform
s1 = quick_spec 'a', '1' s1 = quick_gem 'a', '1'
s2 = quick_spec 'a', '1' do |s| s2 = quick_gem 'a', '1' do |s|
s.platform = Gem::Platform.new 'x86-my_platform1' s.platform = Gem::Platform.new 'x86-my_platform1'
end end
@ -745,8 +736,8 @@ end
end end
def test_spaceship_version def test_spaceship_version
s1 = quick_spec 'a', '1' s1 = quick_gem 'a', '1'
s2 = quick_spec 'a', '2' s2 = quick_gem 'a', '2'
assert_equal( -1, (s1 <=> s2)) assert_equal( -1, (s1 <=> s2))
assert_equal( 0, (s1 <=> s1)) assert_equal( 0, (s1 <=> s1))
@ -812,54 +803,6 @@ end
assert_equal @a2, same_spec assert_equal @a2, same_spec
end 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<b>, [\"= 1\"])
else
s.add_dependency(%q<b>, [\"= 1\"])
end
else
s.add_dependency(%q<b>, [\"= 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 def test_to_ruby_fancy
@a1.platform = Gem::Platform.local @a1.platform = Gem::Platform.local
ruby_code = @a1.to_ruby 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 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rake>, [\"> 0.4\"]) s.add_runtime_dependency(%q<rake>, [\"> 0.4\"])
s.add_runtime_dependency(%q<jabber4r>, [\"> 0.0.0\"]) s.add_runtime_dependency(%q<jabber4r>, [\"> 0.0.0\"])
s.add_runtime_dependency(%q<pqa>, [\"<= 0.6\", \"> 0.4\"]) s.add_runtime_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
else else
s.add_dependency(%q<rake>, [\"> 0.4\"]) s.add_dependency(%q<rake>, [\"> 0.4\"])
s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"]) s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
s.add_dependency(%q<pqa>, [\"<= 0.6\", \"> 0.4\"]) s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
end end
else else
s.add_dependency(%q<rake>, [\"> 0.4\"]) s.add_dependency(%q<rake>, [\"> 0.4\"])
s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"]) s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
s.add_dependency(%q<pqa>, [\"<= 0.6\", \"> 0.4\"]) s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
end end
end end
SPEC SPEC
@ -941,9 +884,6 @@ end
def test_to_yaml def test_to_yaml
yaml_str = @a1.to_yaml yaml_str = @a1.to_yaml
refute_match '!!null', yaml_str
same_spec = YAML.load(yaml_str) same_spec = YAML.load(yaml_str)
assert_equal @a1, same_spec assert_equal @a1, same_spec
@ -1318,16 +1258,6 @@ end
specfile.delete specfile.delete
end 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 def util_setup_validate
Dir.chdir @tempdir do Dir.chdir @tempdir do
FileUtils.mkdir_p File.join('ext', 'a') FileUtils.mkdir_p File.join('ext', 'a')
@ -1339,4 +1269,6 @@ end
FileUtils.touch File.join('test', 'suite.rb') FileUtils.touch File.join('test', 'suite.rb')
end end
end end
end end

View file

@ -12,19 +12,19 @@ class TestGemUninstaller < Gem::InstallerTestCase
def setup def setup
super super
@user_spec.executables = ["executable"] @user_spec.executables = ["my_exec"]
# HACK util_make_exec # HACK util_make_exec
user_bin_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name, 'bin' user_bin_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name, 'bin'
FileUtils.mkdir_p user_bin_dir 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| open exec_path, 'w' do |f|
f.puts "#!/usr/bin/ruby" f.puts "#!/usr/bin/ruby"
end end
user_bin_dir = File.join Gem.user_dir, 'bin' user_bin_dir = File.join Gem.user_dir, 'bin'
FileUtils.mkdir_p user_bin_dir 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| open exec_path, 'w' do |f|
f.puts "#!/usr/bin/ruby" f.puts "#!/usr/bin/ruby"
end end
@ -47,8 +47,8 @@ class TestGemUninstaller < Gem::InstallerTestCase
def test_remove_executables_force_keep def test_remove_executables_force_keep
uninstaller = Gem::Uninstaller.new nil, :executables => false uninstaller = Gem::Uninstaller.new nil, :executables => false
executable = File.join Gem.user_dir, 'bin', 'executable' executable = File.join Gem.user_dir, 'bin', 'my_exec'
assert File.exist?(executable), 'executable not written' assert File.exist? executable
use_ui @ui do use_ui @ui do
uninstaller.remove_executables @user_spec uninstaller.remove_executables @user_spec
@ -62,14 +62,14 @@ class TestGemUninstaller < Gem::InstallerTestCase
def test_remove_executables_force_remove def test_remove_executables_force_remove
uninstaller = Gem::Uninstaller.new nil, :executables => true uninstaller = Gem::Uninstaller.new nil, :executables => true
executable = File.join Gem.user_dir, 'bin', 'executable' executable = File.join Gem.user_dir, 'bin', 'my_exec'
assert File.exist?(executable), 'executable not written' assert File.exist? executable
use_ui @ui do use_ui @ui do
uninstaller.remove_executables @user_spec uninstaller.remove_executables @user_spec
end end
assert_equal "Removing executable\n", @ui.output assert_equal "Removing my_exec\n", @ui.output
refute File.exist? executable refute File.exist? executable
end end
@ -81,47 +81,12 @@ class TestGemUninstaller < Gem::InstallerTestCase
uninstaller.remove_executables @user_spec uninstaller.remove_executables @user_spec
end 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 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 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 def test_path_ok_eh
uninstaller = Gem::Uninstaller.new nil uninstaller = Gem::Uninstaller.new nil
@ -164,31 +129,6 @@ class TestGemUninstaller < Gem::InstallerTestCase
assert_same uninstaller, @post_uninstall_hook_arg assert_same uninstaller, @post_uninstall_hook_arg
end 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 def test_uninstall_user
uninstaller = Gem::Uninstaller.new @user_spec.name, :executables => true, uninstaller = Gem::Uninstaller.new @user_spec.name, :executables => true,
:user_install => true :user_install => true

View file

@ -5,7 +5,7 @@
###################################################################### ######################################################################
require 'rubygems/test_case' require 'rubygems/test_case'
require "rubygems/simple_gem" require "test/rubygems/simple_gem"
require 'rubygems/validator' require 'rubygems/validator'
class TestGemValidator < Gem::TestCase class TestGemValidator < Gem::TestCase

View file

@ -46,7 +46,7 @@ class TestKernel < Gem::TestCase
gem 'a', '= 2' gem 'a', '= 2'
end end
assert_match(/activate a \(= 2\)/, ex.message) assert_match(/activate a \(= 2, runtime\)/, ex.message)
assert_match(/activated a-1/, ex.message) assert_match(/activated a-1/, ex.message)
assert_equal 'a', ex.name assert_equal 'a', ex.name
assert_equal Gem::Requirement.new('= 2'), ex.requirement assert_equal Gem::Requirement.new('= 2'), ex.requirement

View file

@ -1,11 +1,11 @@
#define RUBY_VERSION "1.9.3" #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_PATCHLEVEL -1
#define RUBY_BRANCH_NAME "trunk" #define RUBY_BRANCH_NAME "trunk"
#define RUBY_RELEASE_YEAR 2011 #define RUBY_RELEASE_YEAR 2011
#define RUBY_RELEASE_MONTH 3 #define RUBY_RELEASE_MONTH 2
#define RUBY_RELEASE_DAY 7 #define RUBY_RELEASE_DAY 25
#include "ruby/version.h" #include "ruby/version.h"
@ -51,4 +51,3 @@
STRINGIZE(RUBY_BIRTH_YEAR)"-" \ STRINGIZE(RUBY_BIRTH_YEAR)"-" \
STRINGIZE(RUBY_RELEASE_YEAR)" " \ STRINGIZE(RUBY_RELEASE_YEAR)" " \
RUBY_AUTHOR RUBY_AUTHOR

View file

@ -459,12 +459,12 @@ NORETURN(static void raise_method_missing(rb_thread_t *th, int argc, const VALUE
* values. * values.
* *
* class Roman * class Roman
* def roman_to_int(str) * def romanToInt(str)
* # ... * # ...
* end * end
* def method_missing(methId) * def method_missing(methId)
* str = methId.id2name * str = methId.id2name
* roman_to_int(str) * romanToInt(str)
* end * end
* end * end
* *
@ -1082,12 +1082,12 @@ eval_string(VALUE self, VALUE src, VALUE scope, const char *file, int line)
* optional <em>filename</em> and <em>lineno</em> parameters are * optional <em>filename</em> and <em>lineno</em> parameters are
* present, they will be used when reporting syntax errors. * present, they will be used when reporting syntax errors.
* *
* def get_binding(str) * def getBinding(str)
* return binding * return binding
* end * end
* str = "hello" * str = "hello"
* eval "str + ' Fred'" #=> "hello Fred" * eval "str + ' Fred'" #=> "hello Fred"
* eval "str + ' Fred'", get_binding("bye") #=> "bye Fred" * eval "str + ' Fred'", getBinding("bye") #=> "bye Fred"
*/ */
VALUE VALUE

View file

@ -1152,20 +1152,20 @@ top_private(int argc, VALUE *argv)
* end * end
* class Cls * class Cls
* include Mod * include Mod
* def call_one * def callOne
* one * one
* end * end
* end * end
* Mod.one #=> "This is one" * Mod.one #=> "This is one"
* c = Cls.new * c = Cls.new
* c.call_one #=> "This is one" * c.callOne #=> "This is one"
* module Mod * module Mod
* def one * def one
* "This is the new one" * "This is the new one"
* end * end
* end * end
* Mod.one #=> "This is one" * Mod.one #=> "This is one"
* c.call_one #=> "This is the new one" * c.callOne #=> "This is the new one"
*/ */
static VALUE static VALUE