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