a
    åze  ã                   @   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 G dd„ dejejejƒZd	d
„ Zedkr„eeƒ ƒ dS )z'Tests for distutils.command.build_clib.é    N)Úrun_unittestÚmissing_compiler_executable)Ú
build_clib)ÚDistutilsSetupError)Úsupportc                   @   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   ú5/usr/lib/python3.9/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|_|  | ¡ g d
¢¡ d S )Nr   Úsourcesr   ÚaÚb)r   r   Zname2ÚcÚd)r   r   r   r   )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   ÚcompileI   s    zDBuildCLibTestCase.test_build_libraries.<locals>.FakeCompiler.compileN)Ú__name__Ú
__module__Ú__qualname__r#   Zcreate_static_libr   r   r   r   ÚFakeCompilerH   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_librariesD   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   Útest_finalize_optionsY   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 u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_cr2   Zccmdr   r   r   Útest_runh   s    
zBuildCLibTestCase.test_runN)r$   r%   r&   r   r   r+   r,   ÚunittestZskipIfÚsysÚplatformr5   r   r   r   r   r      s   r   c                   C   s
   t  t¡S r    )r6   Z	makeSuiter   r   r   r   r   Ú
test_suite‚   s    r9   Ú__main__)Ú__doc__r6   r.   r7   Ztest.supportr   r   Zdistutils.command.build_clibr   Zdistutils.errorsr   Zdistutils.testsr   ZTempdirManagerZLoggingSilencerZTestCaser   r9   r$   r   r   r   r   Ú<module>   s   þv