Skip to content

Commit 7d65003

Browse files
committed
Add: test package for tree-shaking
1 parent 219c98c commit 7d65003

File tree

9 files changed

+71
-0
lines changed

9 files changed

+71
-0
lines changed

ci/run_tests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ test ! -x ./build/gfortran_*/app/unused
6262
test ! -x ./build/gfortran_*/test/unused_test
6363
popd
6464

65+
pushd tree_shake
66+
"$fpm" build
67+
"$fpm" run
68+
"$fpm" test
69+
test ! -e ./build/gfortran_*/tree_shake/src_farewell_m.f90.o
70+
test ! -e ./build/gfortran_*/tree_shake/src_farewell_m.f90.o.log
71+
popd
72+
6573
pushd version_file
6674
"$fpm" build
6775
"$fpm" run

example_packages/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ the features demonstrated in each package and which versions of fpm are supporte
2020
| makefile_complex | External build command (makefile); local path dependency | Y | N |
2121
| program_with_module | App-only; module+program in single source file | Y | Y |
2222
| submodules | Lib-only; submodules (3 levels) | N | Y |
23+
| tree_shake | Test tree-shaking/pruning of unused module dependencies | N | Y |
2324
| link_external | Link external library | N | Y |
2425
| link_executable | Link external library to a single executable | N | Y |
2526
| version_file | Read version number from a file in the project root | N | Y |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/*
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
program say_Hello
2+
use greet_m, only: make_greeting
3+
4+
implicit none
5+
6+
print *, make_greeting("World")
7+
end program say_Hello

example_packages/tree_shake/fpm.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "tree_shake"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module farewell_m
2+
use subdir_constants, only: FAREWELL_STR
3+
implicit none
4+
private
5+
6+
public :: make_farewell
7+
contains
8+
function make_farewell(name) result(greeting)
9+
character(len=*), intent(in) :: name
10+
character(len=:), allocatable :: greeting
11+
12+
greeting = FAREWELL_STR // name // "!"
13+
end function make_farewell
14+
end module farewell_m
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module greet_m
2+
use subdir_constants, only: GREET_STR
3+
implicit none
4+
private
5+
6+
public :: make_greeting
7+
contains
8+
function make_greeting(name) result(greeting)
9+
character(len=*), intent(in) :: name
10+
character(len=:), allocatable :: greeting
11+
12+
greeting = GREET_STR // name // "!"
13+
end function make_greeting
14+
end module greet_m
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module subdir_constants
2+
implicit none
3+
4+
character(*), parameter :: GREET_STR = 'Hello, '
5+
character(*), parameter :: FAREWELL_STR = 'Goodbye, '
6+
7+
end module subdir_constants
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
program greet_test
2+
use greet_m, only: make_greeting
3+
use iso_fortran_env, only: error_unit, output_unit
4+
5+
implicit none
6+
7+
character(len=:), allocatable :: greeting
8+
9+
allocate(character(len=0) :: greeting)
10+
greeting = make_greeting("World")
11+
12+
if (greeting == "Hello, World!") then
13+
write(output_unit, *) "Passed"
14+
else
15+
write(error_unit, *) "Failed"
16+
call exit(1)
17+
end if
18+
end program greet_test

0 commit comments

Comments
 (0)