B
    Ûö›\C  ã               @   s”   d Z ddl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
 ddlmZ ddlmZ G dd	„ d	ejejejƒZd
d„ Zedkreeƒ ƒ dS )z'Tests for distutils.command.build_clib.é    N)Úrun_unittestÚmissing_compiler_executable)Ú
build_clib)ÚDistutilsSetupError)Úsupport)Úfind_executablec               @   sF   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Ze e	j
d	kd
¡dd„ ƒZdS )ÚBuildCLibTestCasec             C   sš   |   ¡ \}}t|ƒ}|  t|jd¡ |  t|jddg¡ |  t|jddg¡ |  t|jddg¡ |  t|jdi fd	g¡ di fdd
difg}| |¡ d S )NÚfooÚfoo1Úfoo2)é   r
   )Únamer   )r   r
   )zanother/namer   r   )Zanotherr   ÚokZgood)Úcreate_distr   ÚassertRaisesr   Zcheck_library_list)ÚselfÚpkg_dirÚdistÚcmdZlibs© r   ú0lib/python3.7/distutils/tests/test_build_clib.pyÚtest_check_library_dist   s    





z)BuildCLibTestCase.test_check_library_distc             C   sÒ   |   ¡ \}}t|ƒ}di fg|_|  t|j¡ dddifg|_|  t|j¡ ddddgifg|_|  | ¡ ddg¡ dddifg|_|  | ¡ ddg¡ dddifdddd	gifg|_|  | ¡ dddd	g¡ d S )
Nr   Úsourcesr   ÚaÚb)r   r   Zname2ÚcÚd)r   r   Ú	librariesr   r   Zget_source_filesÚassertEqual)r   r   r   r   r   r   r   Útest_get_source_files/   s    
z'BuildCLibTestCase.test_get_source_filesc             C   s€   |   ¡ \}}t|ƒ}G dd„ dƒ}|ƒ |_dddifg}|  t|j|¡ ddtƒ ifg}| |¡ ddtƒ ifg}| |¡ d S )Nc               @   s   e Zd Zdd„ ZeZdS )z<BuildCLibTestCase.test_build_libraries.<locals>.FakeCompilerc              _   s   d S )Nr   )ÚargsÚkwr   r   r   ÚcompileJ   s    zDBuildCLibTestCase.test_build_libraries.<locals>.FakeCompiler.compileN)Ú__name__Ú
__module__Ú__qualname__r"   Zcreate_static_libr   r   r   r   ÚFakeCompilerI   s   r&   r   r   Znotvalid)r   r   Zcompilerr   r   Zbuild_librariesÚlistÚtuple)r   r   r   r   r&   Úlibr   r   r   Útest_build_librariesE   s    
z&BuildCLibTestCase.test_build_librariesc             C   sh   |   ¡ \}}t|ƒ}d|_| ¡  |  |jdg¡ d |_| ¡  |  |jg ¡ d|j_|  t|j¡ d S )Nzone-dirZWONTWORK)	r   r   Zinclude_dirsZfinalize_optionsr   Zdistributionr   r   r   )r   r   r   r   r   r   r   Útest_finalize_optionsZ   s    z'BuildCLibTestCase.test_finalize_optionsÚwin32zcan't test on Windowsc             C   sž   |   ¡ \}}t|ƒ}tj |d¡}|  |d¡ dd|gifg|_tj |d¡}t |¡ ||_||_t	ƒ }|d k	r€|  
d| ¡ | ¡  |  dt |¡¡ d S )Nzfoo.czint main(void) { return 1;}
r	   r   ZbuildzThe %r command is not foundzlibfoo.a)r   r   ÚosÚpathÚjoinZ
write_filer   ÚmkdirÚ
build_tempr   ZskipTestÚrunZassertInÚlistdir)r   r   r   r   Zfoo_cr1   Zccmdr   r   r   Útest_runi   s    
zBuildCLibTestCase.test_runN)r#   r$   r%   r   r   r*   r+   ÚunittestZskipIfÚsysÚplatformr4   r   r   r   r   r      s
   r   c               C   s
   t  t¡S )N)r5   Z	makeSuiter   r   r   r   r   Ú
test_suiteƒ   s    r8   Ú__main__)Ú__doc__r5   r-   r6   Ztest.supportr   r   Zdistutils.command.build_clibr   Zdistutils.errorsr   Zdistutils.testsr   Zdistutils.spawnr   ZTempdirManagerZLoggingSilencerZTestCaser   r8   r#   r   r   r   r   Ú<module>   s   t