B
    È S]  ã               @   sl   d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 G dd„ dej
ƒZdd	„ Zed
krheeƒ ƒ dS )z"Tests for distutils.unixccompiler.é    N)ÚEnvironmentVarGuardÚrun_unittest)Ú	sysconfig)ÚUnixCCompilerc               @   sj   e Zd Zdd„ Zdd„ Ze ejdkd¡dd„ ƒZ	e 
ejd	kd
¡dd„ ƒZe 
ejd	kd
¡dd„ ƒZdS )ÚUnixCCompilerTestCasec             C   s,   t j| _tj| _G dd„ dtƒ}|ƒ | _d S )Nc               @   s   e Zd Zdd„ ZdS )z4UnixCCompilerTestCase.setUp.<locals>.CompilerWrapperc             S   s
   |   d¡S )Nz/foo)Zruntime_library_dir_option)Úself© r   ú3lib/python3.7/distutils/tests/test_unixccompiler.pyÚ	rpath_foo   s    z>UnixCCompilerTestCase.setUp.<locals>.CompilerWrapper.rpath_fooN)Ú__name__Ú
__module__Ú__qualname__r
   r   r   r   r	   ÚCompilerWrapper   s   r   )ÚsysÚplatformÚ_backup_platformr   Úget_config_varÚ_backup_get_config_varr   Úcc)r   r   r   r   r	   ÚsetUp   s    zUnixCCompilerTestCase.setUpc             C   s   | j t_| jt_d S )N)r   r   r   r   r   r   )r   r   r   r	   ÚtearDown   s    zUnixCCompilerTestCase.tearDownZwin32zcan't test on Windowsc             C   sX  dt _|  | j ¡ d¡ dt _tj}dd„ }|t_|  | j ¡ ddg¡ dd„ }|t_|  | j ¡ ddg¡ d	d„ }|t_|  | j ¡ ddg¡ |t_d
t _dd„ }|t_|  | j ¡ d¡ d
t _dd„ }|t_|  | j ¡ d¡ d
t _dd„ }|t_|  | j ¡ d¡ d
t _dd„ }|t_|  | j ¡ d¡ d
t _dd„ }|t_|  | j ¡ d¡ d S )NÚdarwinz-L/foozhp-uxc             S   s   dS )NZxxxr   )Úvr   r   r	   Úgcv%   s    z=UnixCCompilerTestCase.test_runtime_libdir_option.<locals>.gcvz+sc             S   s   dS )NÚgccr   )r   r   r   r	   r   *   s    z-Wl,+sc             S   s   dS )Nzg++r   )r   r   r   r	   r   /   s    Zbarc             S   s   | dkrdS | dkrdS d S )NÚCCr   ÚGNULDÚyesr   )r   r   r   r	   r   8   s    z
-Wl,-R/fooc             S   s   | dkrdS | dkrdS d S )Nr   r   r   Únor   )r   r   r   r	   r   B   s    z-Wl,--disable-new-dtags,-R/fooc             S   s   | dkrdS | dkrdS d S )Nr   zx86_64-pc-linux-gnu-gcc-4.4.2r   r   r   )r   r   r   r	   r   M   s    z-Wl,--enable-new-dtags,-R/fooc             S   s   | dkrdS | dkrdS d S )Nr   r   r   r   r   )r   r   r   r	   r   W   s    z-R/fooc             S   s   | dkrdS | dkrdS d S )Nr   r   r   r   r   )r   r   r   r	   r   a   s    )r   r   ÚassertEqualr   r
   r   r   )r   Zold_gcvr   r   r   r	   Útest_runtime_libdir_option   sD    z0UnixCCompilerTestCase.test_runtime_libdir_optionr   ztest only relevant for OS Xc          	   C   sR   dd„ }|t _tƒ  }d|d< |d= t  | j¡ W d Q R X |  | jjd d¡ d S )Nc             S   s   | dkrdS dS )NÚLDSHAREDz*gcc-4.2 -bundle -undefined dynamic_lookup zgcc-4.2r   )r   r   r   r	   r   m   s    zAUnixCCompilerTestCase.test_osx_cc_overrides_ldshared.<locals>.gcvÚmy_ccr   r!   r   )r   r   r   Úcustomize_compilerr   r   Ú	linker_so)r   r   Úenvr   r   r	   Útest_osx_cc_overrides_ldsharedi   s    z4UnixCCompilerTestCase.test_osx_cc_overrides_ldsharedc          	   C   sT   dd„ }|t _tƒ "}d|d< d|d< t  | j¡ W d Q R X |  | jjd d¡ d S )	Nc             S   s   | dkrdS dS )Nr!   z*gcc-4.2 -bundle -undefined dynamic_lookup zgcc-4.2r   )r   r   r   r	   r   }   s    z=UnixCCompilerTestCase.test_osx_explicit_ldshared.<locals>.gcvr"   r   zmy_ld -bundle -dynamicr!   r   Zmy_ld)r   r   r   r#   r   r   r$   )r   r   r%   r   r   r	   Útest_osx_explicit_ldsharedx   s    z0UnixCCompilerTestCase.test_osx_explicit_ldsharedN)r   r   r   r   r   ÚunittestZskipIfr   r   r    Z
skipUnlessr&   r'   r   r   r   r	   r   	   s
   Rr   c               C   s
   t  t¡S )N)r(   Z	makeSuiter   r   r   r   r	   Ú
test_suite‰   s    r)   Ú__main__)Ú__doc__r   r(   Ztest.supportr   r   Z	distutilsr   Zdistutils.unixccompilerr   ZTestCaser   r)   r   r   r   r   r	   Ú<module>   s    