Skip to content

Commit bebe912

Browse files
committed
make savetext test use defined output dir, not in source
1 parent 465fc89 commit bebe912

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
build/
2+
13
# Prerequisites
24
*.d
35

src/tests/loadtxt/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ target_link_libraries(test_loadtxt fortran_stdlib)
66
add_executable(test_savetxt test_savetxt.f90)
77
target_link_libraries(test_savetxt fortran_stdlib)
88

9-
add_test(NAME load_text COMMAND $<TARGET_FILE:test_loadtxt>
9+
add_test(NAME load_text COMMAND $<TARGET_FILE:test_loadtxt> ${CMAKE_CURRENT_BINARY_DIR}
1010
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
11-
add_test(NAME save_text COMMAND $<TARGET_FILE:test_savetxt>
11+
add_test(NAME save_text COMMAND $<TARGET_FILE:test_savetxt> ${CMAKE_CURRENT_BINARY_DIR}
1212
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

src/tests/loadtxt/test_savetxt.f90

+38-18
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,77 @@ program test_loadtxt
44
use stdlib_experimental_error, only: assert
55
implicit none
66

7-
call test_sp()
8-
call test_dp()
9-
call test_qp()
7+
character(:), allocatable :: outpath
8+
9+
outpath = get_outpath() // "/tmp.dat"
10+
11+
call test_sp(outpath)
12+
call test_dp(outpath)
13+
call test_qp(outpath)
1014

1115
contains
1216

13-
subroutine test_sp()
17+
function get_outpath() result(outpath)
18+
integer :: ierr
19+
character(256) :: argv
20+
character(:), allocatable :: outpath
21+
22+
call get_command_argument(1, argv, status=ierr)
23+
if (ierr==0) then
24+
outpath = trim(argv)
25+
else
26+
outpath = '.'
27+
endif
28+
end function get_outpath
29+
30+
subroutine test_sp(outpath)
31+
character(*), intent(in) :: outpath
1432
real(sp) :: d(3, 2), e(2, 3)
1533
real(sp), allocatable :: d2(:, :)
1634
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
17-
call savetxt("tmp.dat", d)
18-
call loadtxt("tmp.dat", d2)
35+
call savetxt(outpath, d)
36+
call loadtxt(outpath, d2)
1937
call assert(all(shape(d2) == [3, 2]))
2038
call assert(all(abs(d-d2) < epsilon(1._sp)))
2139

2240
e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
23-
call savetxt("tmp.dat", e)
24-
call loadtxt("tmp.dat", d2)
41+
call savetxt(outpath, e)
42+
call loadtxt(outpath, d2)
2543
call assert(all(shape(d2) == [2, 3]))
2644
call assert(all(abs(e-d2) < epsilon(1._sp)))
2745
end subroutine
2846

2947

30-
subroutine test_dp()
48+
subroutine test_dp(outpath)
49+
character(*), intent(in) :: outpath
3150
real(dp) :: d(3, 2), e(2, 3)
3251
real(dp), allocatable :: d2(:, :)
3352
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
34-
call savetxt("tmp.dat", d)
35-
call loadtxt("tmp.dat", d2)
53+
call savetxt(outpath, d)
54+
call loadtxt(outpath, d2)
3655
call assert(all(shape(d2) == [3, 2]))
3756
call assert(all(abs(d-d2) < epsilon(1._dp)))
3857

3958
e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
40-
call savetxt("tmp.dat", e)
41-
call loadtxt("tmp.dat", d2)
59+
call savetxt(outpath, e)
60+
call loadtxt(outpath, d2)
4261
call assert(all(shape(d2) == [2, 3]))
4362
call assert(all(abs(e-d2) < epsilon(1._dp)))
4463
end subroutine
4564

46-
subroutine test_qp()
65+
subroutine test_qp(outpath)
66+
character(*), intent(in) :: outpath
4767
real(qp) :: d(3, 2), e(2, 3)
4868
real(qp), allocatable :: d2(:, :)
4969
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
50-
call savetxt("tmp.dat", d)
51-
call loadtxt("tmp.dat", d2)
70+
call savetxt(outpath, d)
71+
call loadtxt(outpath, d2)
5272
call assert(all(shape(d2) == [3, 2]))
5373
call assert(all(abs(d-d2) < epsilon(1._qp)))
5474

5575
e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
56-
call savetxt("tmp.dat", e)
57-
call loadtxt("tmp.dat", d2)
76+
call savetxt(outpath, e)
77+
call loadtxt(outpath, d2)
5878
call assert(all(shape(d2) == [2, 3]))
5979
call assert(all(abs(e-d2) < epsilon(1._qp)))
6080
end subroutine

0 commit comments

Comments
 (0)