cython: add 1 basic test
This commit is contained in:
parent
b9f33c2380
commit
74ed27f776
|
@ -54,8 +54,8 @@ from run_tests import guess_backend
|
|||
|
||||
ALL_TESTS = ['cmake', 'common', 'native', 'warning-meson', 'failing-meson', 'failing-build', 'failing-test',
|
||||
'keyval', 'platform-osx', 'platform-windows', 'platform-linux',
|
||||
'java', 'C#', 'vala', 'rust', 'd', 'objective c', 'objective c++',
|
||||
'fortran', 'swift', 'cuda', 'python3', 'python', 'fpga', 'frameworks', 'nasm', 'wasm'
|
||||
'java', 'C#', 'vala', 'cython', 'rust', 'd', 'objective c', 'objective c++',
|
||||
'fortran', 'swift', 'cuda', 'python3', 'python', 'fpga', 'frameworks', 'nasm', 'wasm',
|
||||
]
|
||||
|
||||
|
||||
|
@ -1016,6 +1016,7 @@ def detect_tests_to_run(only: T.Dict[str, T.List[str]], use_tmp: bool) -> T.List
|
|||
TestCategory('java', 'java', backend is not Backend.ninja or mesonlib.is_osx() or not have_java()),
|
||||
TestCategory('C#', 'csharp', skip_csharp(backend)),
|
||||
TestCategory('vala', 'vala', backend is not Backend.ninja or not shutil.which(os.environ.get('VALAC', 'valac'))),
|
||||
TestCategory('cython', 'cython', backend is not Backend.ninja or not shutil.which(os.environ.get('CYTHON', 'cython'))),
|
||||
TestCategory('rust', 'rust', should_skip_rust(backend)),
|
||||
TestCategory('d', 'd', backend is not Backend.ninja or not have_d_compiler()),
|
||||
TestCategory('objective c', 'objc', backend not in (Backend.ninja, Backend.xcode) or not have_objc_compiler(options.use_tmpdir)),
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from storer import Storer
|
||||
|
||||
s = Storer()
|
||||
|
||||
if s.get_value() != 0:
|
||||
raise SystemExit('Initial value incorrect.')
|
||||
|
||||
s.set_value(42)
|
||||
|
||||
if s.get_value() != 42:
|
||||
raise SystemExit('Setting value failed.')
|
||||
|
||||
try:
|
||||
s.set_value('not a number')
|
||||
raise SystemExit('Using wrong argument type did not fail.')
|
||||
except TypeError:
|
||||
pass
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
cdef extern from "storer.h":
|
||||
ctypedef struct Storer:
|
||||
pass
|
||||
|
||||
Storer* storer_new();
|
||||
void storer_destroy(Storer *s);
|
||||
int storer_get_value(Storer *s);
|
||||
void storer_set_value(Storer *s, int v);
|
|
@ -0,0 +1,8 @@
|
|||
slib = py3.extension_module(
|
||||
'storer',
|
||||
'storer.pyx',
|
||||
'storer.c',
|
||||
dependencies : py3_dep
|
||||
)
|
||||
|
||||
pydir = meson.current_build_dir()
|
|
@ -0,0 +1,24 @@
|
|||
#include"storer.h"
|
||||
#include<stdlib.h>
|
||||
|
||||
struct _Storer {
|
||||
int value;
|
||||
};
|
||||
|
||||
Storer* storer_new() {
|
||||
Storer *s = malloc(sizeof(struct _Storer));
|
||||
s->value = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
void storer_destroy(Storer *s) {
|
||||
free(s);
|
||||
}
|
||||
|
||||
int storer_get_value(Storer *s) {
|
||||
return s->value;
|
||||
}
|
||||
|
||||
void storer_set_value(Storer *s, int v) {
|
||||
s->value = v;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
typedef struct _Storer Storer;
|
||||
|
||||
Storer* storer_new();
|
||||
void storer_destroy(Storer *s);
|
||||
int storer_get_value(Storer *s);
|
||||
void storer_set_value(Storer *s, int v);
|
|
@ -0,0 +1,16 @@
|
|||
cimport cstorer
|
||||
|
||||
cdef class Storer:
|
||||
cdef cstorer.Storer* _c_storer
|
||||
|
||||
def __cinit__(self):
|
||||
self._c_storer = cstorer.storer_new()
|
||||
|
||||
def __dealloc__(self):
|
||||
cstorer.storer_destroy(self._c_storer)
|
||||
|
||||
cpdef int get_value(self):
|
||||
return cstorer.storer_get_value(self._c_storer)
|
||||
|
||||
cpdef set_value(self, int value):
|
||||
cstorer.storer_set_value(self._c_storer, value)
|
|
@ -0,0 +1,20 @@
|
|||
project(
|
||||
'basic cython project',
|
||||
['cython', 'c'],
|
||||
default_options : ['warning_level=3']
|
||||
)
|
||||
|
||||
py_mod = import('python')
|
||||
py3 = py_mod.find_installation()
|
||||
py3_dep = py3.dependency(required : false)
|
||||
if not py3_dep.found()
|
||||
error('MESON_SKIP_TEST: Python library not found.')
|
||||
endif
|
||||
|
||||
subdir('libdir')
|
||||
|
||||
test('cython tester',
|
||||
py3,
|
||||
args : files('cytest.py'),
|
||||
env : ['PYTHONPATH=' + pydir]
|
||||
)
|
Loading…
Reference in New Issue