Skip to content

Commit 6e1ce8d

Browse files
committed
Add regression tests for canon_path and update CLI help text
1 parent fa9a499 commit 6e1ce8d

File tree

3 files changed

+158
-17
lines changed

3 files changed

+158
-17
lines changed

fpm/src/fpm_command_line.f90

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,16 @@ subroutine set_help()
673673
' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] [options]', &
674674
' ', &
675675
'SUBCOMMAND OPTIONS ', &
676-
' --profile PROF Builds or runs with the given profile (either release or debug).', &
677-
' fpm(1) defaults to using common compiler debug flags with debug', &
678-
' profile, common compiler optimization flags are used with the', &
679-
' release profile', &
680-
' --flag FFLAGS Use compile arguments provided in FFLAGS rather than', &
681-
' defaults, if a profile (debug or release) is present the', &
682-
' FFLAGS are appended rather than replaced, module flags are', &
683-
' provided by fpm(1) and must not be present in FFLAGS', &
676+
' --profile PROF selects the compilation profile for the build.',&
677+
' Currently available profiles are "release" for',&
678+
' high optimization and "debug" for full debug options.',&
679+
' If --flag is not specified the "debug" flags are the',&
680+
' default. ',&
681+
' --flag FFLAGS selects compile arguments for the build. These are',&
682+
' added to the profile options if --profile is specified,',&
683+
' else these options override the defaults.',&
684+
' Note object and .mod directory locations are always',&
685+
' built in.',&
684686
' --list List candidates instead of building or running them. On ', &
685687
' the fpm(1) command this shows a brief list of subcommands.', &
686688
' --runner CMD Provides a command to prefix program execution paths. ', &
@@ -765,8 +767,16 @@ subroutine set_help()
765767
' the special characters from shell expansion. ', &
766768
' --all Run all examples or applications. An alias for --target ''*''. ', &
767769
' --example Run example programs instead of applications. ', &
768-
' --profile PROF Selects the compilation profile for the build. ', &
769-
' --flags FFLAGS selects compile arguments for the build', &
770+
' --profile PROF selects the compilation profile for the build.',&
771+
' Currently available profiles are "release" for',&
772+
' high optimization and "debug" for full debug options.',&
773+
' If --flag is not specified the "debug" flags are the',&
774+
' default. ',&
775+
' --flag FFLAGS selects compile arguments for the build. These are',&
776+
' added to the profile options if --profile is specified,',&
777+
' else these options override the defaults.',&
778+
' Note object and .mod directory locations are always',&
779+
' built in.',&
770780
' --compiler COMPILER_NAME Specify a compiler name. The default is ', &
771781
' "gfortran" unless set by the environment ', &
772782
' variable FPM_COMPILER. ', &
@@ -829,9 +839,16 @@ subroutine set_help()
829839
' specified in the "fpm.toml" file. ', &
830840
' ', &
831841
'OPTIONS ', &
832-
' --profile PROF selects the compilation profile for the build ', &
833-
' high optimization instead of full debug options. ', &
834-
' --flags FFLAGS selects compile arguments for the build', &
842+
' --profile PROF selects the compilation profile for the build.',&
843+
' Currently available profiles are "release" for',&
844+
' high optimization and "debug" for full debug options.',&
845+
' If --flag is not specified the "debug" flags are the',&
846+
' default. ',&
847+
' --flag FFLAGS selects compile arguments for the build. These are',&
848+
' added to the profile options if --profile is specified,',&
849+
' else these options override the defaults.',&
850+
' Note object and .mod directory locations are always',&
851+
' built in.',&
835852
' --compiler COMPILER_NAME Specify a compiler name. The default is ', &
836853
' "gfortran" unless set by the environment ', &
837854
' variable FPM_COMPILER. ', &
@@ -1005,8 +1022,16 @@ subroutine set_help()
10051022
' any single character and "*" represents any string. ', &
10061023
' Note The glob string normally needs quoted to ', &
10071024
' protect the special characters from shell expansion.', &
1008-
' --profile PROF selects the compilation profile for the build.', &
1009-
' --flags FFLAGS selects compile arguments for the build', &
1025+
' --profile PROF selects the compilation profile for the build.',&
1026+
' Currently available profiles are "release" for',&
1027+
' high optimization and "debug" for full debug options.',&
1028+
' If --flag is not specified the "debug" flags are the',&
1029+
' default. ',&
1030+
' --flag FFLAGS selects compile arguments for the build. These are',&
1031+
' added to the profile options if --profile is specified,',&
1032+
' else these options override the defaults.',&
1033+
' Note object and .mod directory locations are always',&
1034+
' built in.',&
10101035
' --compiler COMPILER_NAME Specify a compiler name. The default is ', &
10111036
' "gfortran" unless set by the environment ', &
10121037
' variable FPM_COMPILER. ', &
@@ -1069,8 +1094,16 @@ subroutine set_help()
10691094
'OPTIONS', &
10701095
' --list list all installable targets for this project,', &
10711096
' but do not install any of them', &
1072-
' --profile selects the compilation profile for installation', &
1073-
' --flags FFLAGS selects compile arguments for the build', &
1097+
' --profile PROF selects the compilation profile for the build.',&
1098+
' Currently available profiles are "release" for',&
1099+
' high optimization and "debug" for full debug options.',&
1100+
' If --flag is not specified the "debug" flags are the',&
1101+
' default. ',&
1102+
' --flag FFLAGS selects compile arguments for the build. These are',&
1103+
' added to the profile options if --profile is specified,',&
1104+
' else these options override the defaults.',&
1105+
' Note object and .mod directory locations are always',&
1106+
' built in.',&
10741107
' --no-rebuild do not rebuild project before installation', &
10751108
' --prefix DIR path to installation directory (requires write access),', &
10761109
' the default prefix on Unix systems is $HOME/.local', &

fpm/test/fpm_test/main.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ program fpm_testing
55
& select_suite, run_selected
66
use test_toml, only : collect_toml
77
use test_manifest, only : collect_manifest
8+
use test_filesystem, only : collect_filesystem
89
use test_source_parsing, only : collect_source_parsing
910
use test_module_dependencies, only : collect_module_dependencies
1011
use test_package_dependencies, only : collect_package_dependencies
@@ -22,6 +23,7 @@ program fpm_testing
2223
suite = [ &
2324
& new_testsuite("fpm_toml", collect_toml), &
2425
& new_testsuite("fpm_manifest", collect_manifest), &
26+
& new_testsuite("fpm_filesystem", collect_filesystem), &
2527
& new_testsuite("fpm_source_parsing", collect_source_parsing), &
2628
& new_testsuite("fpm_module_dependencies", collect_module_dependencies), &
2729
& new_testsuite("fpm_package_dependencies", collect_package_dependencies), &

fpm/test/fpm_test/test_filesystem.f90

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

0 commit comments

Comments
 (0)