| 1 | from rpython.translator.translator import TranslationContext |
| 2 | from rpython.translator.c.genc import CStandaloneBuilder |
| 3 | from rpython.annotator.listdef import s_list_of_strings |
| 4 | from rpython.rtyper.lltypesystem import rffi, lltype |
| 5 | from rpython.rtyper.tool.rffi_platform import CompilationError |
| 6 | |
| 7 | import os |
| 8 | import py |
| 9 | try: |
| 10 | import pyexpat |
| 11 | except ImportError: |
| 12 | py.test.skip("No module expat") |
| 13 | |
| 14 | try: |
| 15 | from pypy.module.pyexpat import interp_pyexpat |
| 16 | except (ImportError, CompilationError): |
| 17 | py.test.skip("Expat not installed") |
| 18 | |
| 19 | def test_build(): |
| 20 | def entry_point(argv): |
| 21 | parser = interp_pyexpat.XML_ParserCreate("test") |
| 22 | interp_pyexpat.XML_ParserFree(parser) |
| 23 | res = interp_pyexpat.XML_ErrorString(3) |
| 24 | os.write(1, rffi.constcharp2str(res)) |
| 25 | return 0 |
| 26 | |
| 27 | t = TranslationContext() |
| 28 | t.buildannotator().build_types(entry_point, [s_list_of_strings]) |
| 29 | t.buildrtyper().specialize() |
| 30 | |
| 31 | builder = CStandaloneBuilder(t, entry_point, t.config) |
| 32 | builder.generate_source() |
| 33 | builder.compile() |
| 34 | data = builder.cmdexec() |
| 35 | assert data == pyexpat.ErrorString(3) |