o
    JAf1  ã                   @   s”   d Z ddl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rHeeƒ ƒ dS dS )z'Tests for distutils.command.build_clib.é    N)Úrun_unittestÚmissing_compiler_executable)Ú
build_clib)ÚDistutilsSetupError)Úsupportc                       sb   e Zd Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Ze	 
ejdkd¡dd„ ƒZ‡  ZS )ÚBuildCLibTestCasec                    s   t ƒ  ¡  ttjƒ| _d S ©N)ÚsuperÚsetUpÚdictÚ	sysconfigÚ_CONFIG_VARSÚ_backup_CONFIG_VARS©Úself©Ú	__class__© ú6/usr/lib/python3.10/distutils/tests/test_build_clib.pyr
      s   
zBuildCLibTestCase.setUpc                    s&   t ƒ  ¡  tj ¡  tj | j¡ d S r   )r	   ÚtearDownr   r   ÚclearÚupdater   r   r   r   r   r      s   

zBuildCLibTestCase.tearDownc                 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)r   Úpkg_dirÚdistÚcmdZlibsr   r   r   Ú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_files8   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 r   r   )ÚargsÚkwr   r   r   ÚcompileS   s   zDBuildCLibTestCase.test_build_libraries.<locals>.FakeCompiler.compileN)Ú__name__Ú
__module__Ú__qualname__r/   Zcreate_static_libr   r   r   r   ÚFakeCompilerR   s    r3   r   r$   Znotvalid)r   r   Zcompilerr   r   Zbuild_librariesÚlistÚtuple)r   r    r!   r"   r3   Úlibr   r   r   Útest_build_librariesN   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_optionsc   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_cr>   Zccmdr   r   r   Útest_runr   s   
zBuildCLibTestCase.test_run)r0   r1   r2   r
   r   r#   r,   r7   r8   ÚunittestZskipIfÚsysÚplatformrA   Ú__classcell__r   r   r   r   r      s    r   c                   C   s
   t  t¡S r   )rB   Z	makeSuiter   r   r   r   r   Ú
test_suiteŒ   s   
rF   Ú__main__)Ú__doc__rB   r:   rC   r   Ztest.supportr   r   Zdistutils.command.build_clibr   Zdistutils.errorsr   Zdistutils.testsr   ZTempdirManagerZLoggingSilencerZTestCaser   rF   r0   r   r   r   r   Ú<module>   s"    þÿ