# mode: run

PYTHON setup.py build_ext --inplace
PYTHON -c "import a"

######## setup.py ########

from Cython.Build.Dependencies import cythonize

import sys
from distutils.core import setup
try:
    # io.StringIO cannot handle 'str' in Py2
    from StringIO import StringIO
except ImportError:
    from io import StringIO

old_stderr = sys.stderr
captured = sys.stderr = StringIO()
try:
    setup(
      ext_modules = cythonize(
          "*.pyx", include_path=['subdir'],
          compiler_directives={'cdivision': True},
          show_all_warnings=True,
      ),
    )
    output = sys.stderr.getvalue()
finally:
    sys.stderr = old_stderr
    sys.stderr.write(captured.getvalue())

assert "Unraisable exception in function" in output, output


######## subdir/x.pxd ########

######## subdir/y.pxi ########

######## a.pyx ########

cimport x
include "y.pxi"

# cdivision from setup.py
def mod_int_c(int a, int b):
    return a % b

assert mod_int_c(-1, 10) < 0

# unraisable exceptions should produce a warning
cdef int no_exc_propagate():
    raise TypeError()
