Commit ef6d1961 authored by Stefan Behnel's avatar Stefan Behnel

Merge branch 'embray-cygwin-tests'

parents 1c9e174d 7da5f348
...@@ -13,6 +13,7 @@ cython.declare(os=object, re=object, operator=object, ...@@ -13,6 +13,7 @@ cython.declare(os=object, re=object, operator=object,
import os import os
import re import re
import shutil
import sys import sys
import operator import operator
import textwrap import textwrap
...@@ -1737,7 +1738,7 @@ class CCodeWriter(object): ...@@ -1737,7 +1738,7 @@ class CCodeWriter(object):
tmp_path = '%s.tmp%s' % (path, os.getpid()) tmp_path = '%s.tmp%s' % (path, os.getpid())
with closing(Utils.open_new_file(tmp_path)) as f: with closing(Utils.open_new_file(tmp_path)) as f:
f.write(code) f.write(code)
os.rename(tmp_path, path) shutil.move(tmp_path, path)
code = '#include "%s"\n' % path code = '#include "%s"\n' % path
self.put(code) self.put(code)
......
...@@ -90,6 +90,8 @@ class DebuggerTestCase(unittest.TestCase): ...@@ -90,6 +90,8 @@ class DebuggerTestCase(unittest.TestCase):
shutil.copy(codefile, self.destfile) shutil.copy(codefile, self.destfile)
shutil.copy(cfuncs_file, self.cfuncs_destfile + '.c') shutil.copy(cfuncs_file, self.cfuncs_destfile + '.c')
shutil.copy(cfuncs_file.replace('.c', '.h'),
self.cfuncs_destfile + '.h')
compiler = ccompiler.new_compiler() compiler = ccompiler.new_compiler()
compiler.compile(['cfuncs.c'], debug=True, extra_postargs=['-fPIC']) compiler.compile(['cfuncs.c'], debug=True, extra_postargs=['-fPIC'])
......
void some_c_function(void);
cdef extern from "stdio.h": cdef extern from "stdio.h":
int puts(char *s) int puts(char *s)
cdef extern: cdef extern from "cfuncs.h":
void some_c_function() void some_c_function()
import os import os
......
#!/usr/bin/env python #!/usr/bin/env python
import atexit
import os import os
import sys import sys
import re import re
...@@ -70,6 +71,24 @@ CY3_DIR = None ...@@ -70,6 +71,24 @@ CY3_DIR = None
from distutils.command.build_ext import build_ext as _build_ext from distutils.command.build_ext import build_ext as _build_ext
from distutils import sysconfig from distutils import sysconfig
_to_clean = []
@atexit.register
def _cleanup_files():
"""
This is only used on Cygwin to clean up shared libraries that are unsafe
to delete while the test suite is running.
"""
for filename in _to_clean:
if os.path.isdir(filename):
shutil.rmtree(filename, ignore_errors=True)
else:
try:
os.remove(filename)
except OSError:
pass
def get_distutils_distro(_cache=[]): def get_distutils_distro(_cache=[]):
if _cache: if _cache:
...@@ -678,8 +697,10 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -678,8 +697,10 @@ class CythonCompileTestCase(unittest.TestCase):
cleanup = self.cleanup_failures or self.success cleanup = self.cleanup_failures or self.success
cleanup_c_files = WITH_CYTHON and self.cleanup_workdir and cleanup cleanup_c_files = WITH_CYTHON and self.cleanup_workdir and cleanup
cleanup_lib_files = self.cleanup_sharedlibs and cleanup cleanup_lib_files = self.cleanup_sharedlibs and cleanup
is_cygwin = sys.platform == 'cygwin'
if os.path.exists(self.workdir): if os.path.exists(self.workdir):
if cleanup_c_files and cleanup_lib_files: if cleanup_c_files and cleanup_lib_files and not is_cygwin:
shutil.rmtree(self.workdir, ignore_errors=True) shutil.rmtree(self.workdir, ignore_errors=True)
else: else:
for rmfile in os.listdir(self.workdir): for rmfile in os.listdir(self.workdir):
...@@ -688,17 +709,28 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -688,17 +709,28 @@ class CythonCompileTestCase(unittest.TestCase):
rmfile[-4:] == ".cpp" or rmfile[-4:] == ".cpp" or
rmfile.endswith(".html") and rmfile.startswith(self.module)): rmfile.endswith(".html") and rmfile.startswith(self.module)):
continue continue
if not cleanup_lib_files and (rmfile.endswith(".so") or rmfile.endswith(".dll")):
is_shared_obj = rmfile.endswith(".so") or rmfile.endswith(".dll")
if not cleanup_lib_files and is_shared_obj:
continue continue
try: try:
rmfile = os.path.join(self.workdir, rmfile) rmfile = os.path.join(self.workdir, rmfile)
if os.path.isdir(rmfile): if os.path.isdir(rmfile):
shutil.rmtree(rmfile, ignore_errors=True) shutil.rmtree(rmfile, ignore_errors=True)
elif is_cygwin and is_shared_obj:
# Delete later
_to_clean.append(rmfile)
else: else:
os.remove(rmfile) os.remove(rmfile)
except IOError: except IOError:
pass pass
if cleanup_c_files and cleanup_lib_files and is_cygwin:
# Finally, remove the work dir itself
_to_clean.append(self.workdir)
def runTest(self): def runTest(self):
self.success = False self.success = False
self.runCompileTest() self.runCompileTest()
...@@ -828,10 +860,7 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -828,10 +860,7 @@ class CythonCompileTestCase(unittest.TestCase):
build_extension.compiler = COMPILER build_extension.compiler = COMPILER
ext_compile_flags = CFLAGS[:] ext_compile_flags = CFLAGS[:]
compiler = COMPILER or sysconfig.get_config_var('CC')
if self.language == 'c' and compiler == 'gcc':
ext_compile_flags.extend(['-std=c89', '-pedantic'])
if build_extension.compiler == 'mingw32': if build_extension.compiler == 'mingw32':
ext_compile_flags.append('-Wno-format') ext_compile_flags.append('-Wno-format')
if extra_extension_args is None: if extra_extension_args is None:
...@@ -1459,7 +1488,6 @@ class EmbedTest(unittest.TestCase): ...@@ -1459,7 +1488,6 @@ class EmbedTest(unittest.TestCase):
os.chdir(self.old_dir) os.chdir(self.old_dir)
def test_embed(self): def test_embed(self):
from distutils import sysconfig
libname = sysconfig.get_config_var('LIBRARY') libname = sysconfig.get_config_var('LIBRARY')
libdir = sysconfig.get_config_var('LIBDIR') libdir = sysconfig.get_config_var('LIBDIR')
if not os.path.isdir(libdir) or libname not in os.listdir(libdir): if not os.path.isdir(libdir) or libname not in os.listdir(libdir):
...@@ -1980,10 +2008,17 @@ def runtests(options, cmd_args, coverage=None): ...@@ -1980,10 +2008,17 @@ def runtests(options, cmd_args, coverage=None):
exclude_selectors.append(ShardExcludeSelector(options.shard_num, options.shard_count)) exclude_selectors.append(ShardExcludeSelector(options.shard_num, options.shard_count))
if not test_bugs: if not test_bugs:
bug_files = [
('bugs.txt', True),
('pypy_bugs.txt', IS_PYPY),
('windows_bugs.txt', sys.platform == 'win32'),
('cygwin_bugs.txt', sys.platform == 'cygwin')
]
exclude_selectors += [ exclude_selectors += [
FileListExcluder(os.path.join(ROOTDIR, bugs_file_name), verbose=verbose_excludes) FileListExcluder(os.path.join(ROOTDIR, bugs_file_name),
for bugs_file_name in ['bugs.txt'] + (['pypy_bugs.txt'] if IS_PYPY else []) + verbose=verbose_excludes)
(['windows_bugs.txt'] if sys.platform == 'win32' else []) for bugs_file_name, condition in bug_files if condition
] ]
if sys.platform in ['win32', 'cygwin'] and sys.version_info < (2,6): if sys.platform in ['win32', 'cygwin'] and sys.version_info < (2,6):
......
...@@ -17,7 +17,7 @@ setup( ...@@ -17,7 +17,7 @@ setup(
######## callingconvention.pyx ######## ######## callingconvention.pyx ########
# mode: compile # mode: compile
cdef extern from "external_callingconvention.h": cdef extern from "callingconvention.h":
pass pass
cdef extern int f1() cdef extern int f1()
...@@ -35,10 +35,19 @@ p2 = f2 ...@@ -35,10 +35,19 @@ p2 = f2
p3 = f3 p3 = f3
p4 = f4 p4 = f4
######## callingconvention.h ########
#define DLL_EXPORT
#include "external_callingconvention.h"
######## external_callingconvention.h ######## ######## external_callingconvention.h ########
#ifndef DL_IMPORT #ifndef DL_IMPORT
#define DL_IMPORT(t) t #define DL_IMPORT(t) t
#elif defined(DLL_EXPORT)
#define DL_IMPORT(t) DL_EXPORT(t)
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -17,7 +17,7 @@ setup( ...@@ -17,7 +17,7 @@ setup(
######## declarations.pyx ######## ######## declarations.pyx ########
# mode: compile # mode: compile
cdef extern from "external_declarations.h": cdef extern from "declarations.h":
pass pass
cdef extern char *cp cdef extern char *cp
...@@ -48,10 +48,19 @@ cdef char *g(): ...@@ -48,10 +48,19 @@ cdef char *g():
f() f()
g() g()
######## declarations.h ########
#define DLL_EXPORT
#include "external_declarations.h"
######## external_declarations.h ######## ######## external_declarations.h ########
#ifndef DL_IMPORT #ifndef DL_IMPORT
#define DL_IMPORT(t) t #define DL_IMPORT(t) t
#elif defined(DLL_EXPORT)
#define DL_IMPORT(t) DL_EXPORT(t)
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
......
module_api
complex_numbers_c89_T398_long_double
complex_numbers_T305_long_double
int_float_builtins_as_casts_T400_long_double
...@@ -5,14 +5,13 @@ cimport cython ...@@ -5,14 +5,13 @@ cimport cython
def test_object_conversion(o): def test_object_conversion(o):
""" """
>>> test_object_conversion(2) >>> test_object_conversion(2)
((2+0j), (2+0j), (2+0j)) ((2+0j), (2+0j))
>>> test_object_conversion(2j - 0.5) >>> test_object_conversion(2j - 0.5)
((-0.5+2j), (-0.5+2j), (-0.5+2j)) ((-0.5+2j), (-0.5+2j))
""" """
cdef float complex a = o cdef float complex a = o
cdef double complex b = o cdef double complex b = o
cdef long double complex c = o return (a, b)
return (a, b, c)
def test_arithmetic(double complex z, double complex w): def test_arithmetic(double complex z, double complex w):
""" """
......
# ticket: 305
cimport cython
def test_object_conversion(o):
"""
>>> test_object_conversion(2)
(2+0j)
>>> test_object_conversion(2j - 0.5)
(-0.5+2j)
"""
cdef long double complex a = o
return a
# ticket: 398
cdef extern from "complex_numbers_c89_T398.h": pass
include "complex_numbers_T305_long_double.pyx"
# cython: c_string_type=str # cython: c_string_type=str
# cython: c_string_encoding=ascii # cython: c_string_encoding=ascii
# distutils: extra_compile_args=-fpermissive
__doc__ = """ __doc__ = """
>>> sqrt(1) >>> sqrt(1)
......
...@@ -187,24 +187,6 @@ def double_to_float_int(double x): ...@@ -187,24 +187,6 @@ def double_to_float_int(double x):
return r return r
@cython.test_fail_if_path_exists("//SingleAssignmentNode//TypecastNode")
@cython.test_assert_path_exists(
"//PythonCapiCallNode",
"//PythonCapiCallNode/PythonCapiFunctionNode/@cname = '__Pyx_truncl'",
)
def long_double_to_float_int(long double x):
"""
>>> long_double_to_float_int(4.1)
4.0
>>> long_double_to_float_int(-4.1)
-4.0
>>> long_double_to_float_int(4)
4.0
"""
cdef float r = int(x)
return r
@cython.test_fail_if_path_exists("//SimpleCallNode") @cython.test_fail_if_path_exists("//SimpleCallNode")
@cython.test_assert_path_exists("//PythonCapiCallNode") @cython.test_assert_path_exists("//PythonCapiCallNode")
def object_float(x): def object_float(x):
......
# ticket: 400
cimport cython
@cython.test_fail_if_path_exists("//SingleAssignmentNode//TypecastNode")
@cython.test_assert_path_exists(
"//PythonCapiCallNode",
"//PythonCapiCallNode/PythonCapiFunctionNode/@cname = '__Pyx_truncl'",
)
def long_double_to_float_int(long double x):
"""
>>> long_double_to_float_int(4.1)
4.0
>>> long_double_to_float_int(-4.1)
-4.0
>>> long_double_to_float_int(4)
4.0
"""
cdef float r = int(x)
return r
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment