Пример #1
0
 def test_buildToLib_onDynamicOption_exportsAllSymbols(self, tmp_path):
     filename = tmp_path / ('library' + LIB_SUFFIX)
     link_unit = pytcc.CCode('int func(void) { return 123; }')
     tcc = pytcc.TCC('-rdynamic')
     tcc.build_to_lib(filename, link_unit)
     dll = ct.CDLL(str(filename))
     assert dll.func() == 123
Пример #2
0
 def test_buildToArch_createsArchiveFile(self, tcc, tmp_path):
     arch_filename = tmp_path / 'library.a'
     exe_filename = tmp_path / ('main' + EXE_SUFFIX)
     link_unit0 = pytcc.CCode('int func() { return 123; }')
     link_unit1 = pytcc.CCode('int func(); int main() { return func(); }')
     arch_tcc = pytcc.TCC()
     arch_binary = arch_tcc.build_to_arch(arch_filename, link_unit0)
     exe_binary = tcc.build_to_exe(exe_filename, link_unit1, arch_binary)
     assert subprocess.call(str(exe_filename)) == 123
Пример #3
0
 def test_init_withParams_setsAttributes(self):
     tcc = pytcc.TCC('opt1',
                     'opt2',
                     options=['opt3'],
                     include_dirs=['incl_dir'],
                     sys_include_dirs=['sys_incl_dir'],
                     library_dirs=['lib_dir'],
                     defines=dict(A='1'),
                     B='2')
     assert tcc.options == ['opt1', 'opt2', 'opt3']
     assert tcc.defines == dict(A='1', B='2')
     assert tcc.include_dirs == ['incl_dir']
     assert tcc.sys_include_dirs == ['sys_incl_dir']
     assert tcc.library_dirs == ['lib_dir']
Пример #4
0
 def test_buildToMem_onOptions_ok(self):
     tcc = pytcc.TCC('-Werror')
     link_unit = pytcc.CCode('#define REDEF 1\n'
                             '#define REDEF 2\n')  # causes warning
     with pytest.raises(pytcc.CompileError):
         tcc.build_to_mem(link_unit)
Пример #5
0
 def test_buildToMem_onIncludeSysHeader_ok(self, tmpdir):
     tcc = pytcc.TCC()
     link_unit = pytcc.CCode('#include "stdlib.h"\n'
                             'int main(void) { return(atoi("1234")); }')
     assert self.run(tcc, link_unit) == 1234
Пример #6
0
def tcc():
    return pytcc.TCC()
Пример #7
0
 def test_buildToMem_onTccSysIncludeDir_ok(self, tmpdir):
     tcc = pytcc.TCC(sys_include_dirs=[str(tmpdir)])
     tmpdir.join('incl.h').write('#define DEF  123')
     link_unit = pytcc.CCode('#include "incl.h"\n'
                             'int main(void) { return(DEF); }')
     assert self.run(tcc, link_unit) == 123
Пример #8
0
 def test_buildToMem_onLinkUnitDefineOverwritesTccDefine_restoresTccDefineAfterLinkUnit(
         self):
     tcc = pytcc.TCC(DEF=1)
     link_unit1 = pytcc.CCode("#if DEF!=2\n#error inv. DEF\n#endif", DEF=2)
     link_unit2 = pytcc.CCode("#if DEF!=1\n#error inv. DEF\n#endif")
     tcc.build_to_mem(link_unit1, link_unit2)
Пример #9
0
 def test_buildToMem_onTccDefine_compilesWithDefines(self):
     tcc = pytcc.TCC(defines={'DEF1': '12'}, DEF2=34)
     link_unit = pytcc.CCode("int main(void) { return(DEF1 + DEF2); }")
     assert self.run(tcc, link_unit) == 12 + 34