Skip to content

Commit 0ca8bb1

Browse files
committed
Add an initial test working
1 parent 886a63d commit 0ca8bb1

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
cmake_minimum_required(VERSION 2.8)
2+
enable_language(C Fortran)
23
project(symengine.f90)
34

45
set(CMAKE_PREFIX_PATH ${SymEngine_DIR} ${CMAKE_PREFIX_PATH})
@@ -64,4 +65,6 @@ message("HAVE_SYMENGINE_PIRANHA : ${HAVE_SYMENGINE_PIRANHA}")
6465
message("HAVE_SYMENGINE_FLINT : ${HAVE_SYMENGINE_FLINT}")
6566
message("HAVE_SYMENGINE_LLVM : ${HAVE_SYMENGINE_LLVM}")
6667

68+
enable_testing()
69+
6770
add_subdirectory(src)

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set(SRC
33
basic.f90
44
)
55

6-
include_directories(BEFORE ${python_wrapper_BINARY_DIR}/symengine/lib)
7-
86
add_library(symengine_f90 ${SRC})
97
target_link_libraries(symengine_f90 ${SYMENGINE_LIBRARIES})
8+
9+
add_subdirectory(tests)

src/basic.f90

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
module basic
2+
use iso_c_binding, only: c_int
23
implicit none
34

5+
interface
6+
subroutine f_c(i) bind(c, name="f")
7+
import :: c_int
8+
integer(c_int), value, intent(in) :: i
9+
end subroutine
10+
end interface
11+
412
contains
513

14+
subroutine f(i)
15+
integer, intent(in) :: i
16+
call f_c(i)
17+
end subroutine
18+
619
end module

src/tests/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
include_directories(${PROJECT_BINARY_DIR}/src)
2+
3+
macro(ADDTEST name)
4+
add_executable(${name} ${name}.f90)
5+
target_link_libraries(${name} symengine_f90)
6+
add_test(${name} ${PROJECT_BINARY_DIR}/${name})
7+
endmacro(ADDTEST)
8+
9+
project(tests)
10+
11+
ADDTEST(test_basic)

src/tests/test_basic.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
program test_basic
2+
use basic, only: f
3+
implicit none
4+
5+
call f(1)
6+
call f(2)
7+
call f(3)
8+
9+
end program

src/wrapper.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ void f(int i)
1414
basic_mul(e, n, x);
1515
basic_add(e, e, y);
1616
s = basic_str(e);
17-
printf("Result: %s", s);
17+
printf("Result: %s\n", s);
1818
basic_str_free(s);
19+
basic_free_stack(x);
20+
basic_free_stack(y);
21+
basic_free_stack(e);
22+
basic_free_stack(n);
1923
}

0 commit comments

Comments
 (0)