1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
module test_filesystem
use testsuite, only : new_unittest, unittest_t, error_t, test_failed
use fpm_filesystem, only: canon_path
implicit none
private
public :: collect_filesystem
contains
!> Collect all exported unit tests
subroutine collect_filesystem(testsuite)
!> Collection of tests
type(unittest_t), allocatable, intent(out) :: testsuite(:)
testsuite = [ &
& new_unittest("canon-path", test_canon_path) &
]
end subroutine collect_filesystem
subroutine test_canon_path(error)
!> Error handling
type(error_t), allocatable, intent(out) :: error
call check_string(error, &
& canon_path("git/project/src/origin"), "git/project/src/origin")
if (allocated(error)) return
call check_string(error, &
& canon_path("./project/src/origin"), "project/src/origin")
if (allocated(error)) return
call check_string(error, &
& canon_path("./project/src///origin/"), "project/src/origin")
if (allocated(error)) return
call check_string(error, &
& canon_path("../project/./src/origin/"), "../project/src/origin")
if (allocated(error)) return
call check_string(error, &
& canon_path("/project//src/origin/"), "/project/src/origin")
if (allocated(error)) return
call check_string(error, &
& canon_path("/project/src/../origin/"), "/project/origin")
if (allocated(error)) return
call check_string(error, &
& canon_path("/project/src/../origin/.."), "/project")
if (allocated(error)) return
call check_string(error, &
& canon_path("/project/src//../origin/."), "/project/origin")
if (allocated(error)) return
call check_string(error, &
& canon_path("../project/src/./../origin/."), "../project/origin")
if (allocated(error)) return
call check_string(error, &
& canon_path("../project/src/../../../origin/."), "../../origin")
if (allocated(error)) return
call check_string(error, &
& canon_path("/../.."), "/")
if (allocated(error)) return
call check_string(error, &
& canon_path("././././././/////a/b/.///././////.///c/../../../"), ".")
if (allocated(error)) return
call check_string(error, &
& canon_path("/./././././/////a/b/.///././////.///c/../../../"), "/")
if (allocated(error)) return
end subroutine test_canon_path
!> Check a character variable against a reference value
subroutine check_string(error, actual, expected)
!> Error handling
type(error_t), allocatable, intent(out) :: error
!> Actual string value
character(len=*), intent(in) :: actual
!> Expected string value
character(len=*), intent(in) :: expected
if (actual /= expected) then
call test_failed(error, &
"Character value missmatch "//&
"expected '"//expected//"' but got '"//actual//"'")
end if
end subroutine check_string
end module test_filesystem
|