1 | #!/bin/bash |
---|
2 | #------------------------------------------------------------------------------- |
---|
3 | # (C) British Crown Copyright 2006-17 Met Office. |
---|
4 | # |
---|
5 | # This file is part of FCM, tools for managing and building source code. |
---|
6 | # |
---|
7 | # FCM is free software: you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU General Public License as published by |
---|
9 | # the Free Software Foundation, either version 3 of the License, or |
---|
10 | # (at your option) any later version. |
---|
11 | # |
---|
12 | # FCM is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | #------------------------------------------------------------------------------- |
---|
20 | # Tests "fcm make", inherit, with context name. |
---|
21 | #------------------------------------------------------------------------------- |
---|
22 | . "$(dirname "$0")/test_header" |
---|
23 | |
---|
24 | file_cmp_sorted() { |
---|
25 | sort - >"${1}.expected" |
---|
26 | file_cmp "$1" "${2}" "${1}.expected" |
---|
27 | } |
---|
28 | |
---|
29 | find_fcm_make_files() { |
---|
30 | find . "$@" -type f \ |
---|
31 | '(' -path '*/build/*' -o \ |
---|
32 | -path '*/extract/*' -o \ |
---|
33 | -path '*/.fcm-make*/c*' ')' \ |
---|
34 | | sort |
---|
35 | } |
---|
36 | |
---|
37 | tests 5 |
---|
38 | |
---|
39 | #------------------------------------------------------------------------------- |
---|
40 | mkdir -p 'hello/src' |
---|
41 | cat >'hello/fcm-make-friend.cfg' <<'__CFG__' |
---|
42 | name=-friend |
---|
43 | steps=build |
---|
44 | build.source=$HERE/src |
---|
45 | build.target{task}=link |
---|
46 | __CFG__ |
---|
47 | cat >'hello/src/friend.f90' <<'__FORTRAN__' |
---|
48 | module friend |
---|
49 | character(*), parameter :: name = 'friend' |
---|
50 | end module friend |
---|
51 | __FORTRAN__ |
---|
52 | cat >'hello/src/hello.f90' <<'__FORTRAN__' |
---|
53 | program hello |
---|
54 | use friend, only: name |
---|
55 | write(*, '(a,1x,a)') 'Hello', name |
---|
56 | end program hello |
---|
57 | __FORTRAN__ |
---|
58 | |
---|
59 | run_pass "${TEST_KEY_BASE}-hello" fcm make -C "${PWD}/hello" -n '-friend' |
---|
60 | #------------------------------------------------------------------------------- |
---|
61 | mkdir -p 'greet/src' |
---|
62 | cat >'greet/fcm-make-friend.cfg' <<'__CFG__' |
---|
63 | use=$HERE/../hello |
---|
64 | name=-friend |
---|
65 | steps=build |
---|
66 | build.source=$HERE/src |
---|
67 | build.target{task}=link |
---|
68 | __CFG__ |
---|
69 | cat >'greet/src/greet.f90' <<'__FORTRAN__' |
---|
70 | program greet |
---|
71 | use friend, only: name |
---|
72 | write(*, '(a,1x,a)') 'Greet', name |
---|
73 | end program greet |
---|
74 | __FORTRAN__ |
---|
75 | |
---|
76 | run_pass "${TEST_KEY_BASE}-greet" fcm make -C "${PWD}/greet" -n '-friend' |
---|
77 | (cd 'greet' && find_fcm_make_files) >"${TEST_KEY_BASE}-greet.find" |
---|
78 | file_cmp_sorted \ |
---|
79 | "${TEST_KEY_BASE}-greet.find" "${TEST_KEY_BASE}-greet.find" <<'__FIND__' |
---|
80 | ./.fcm-make-friend/config-as-parsed.cfg |
---|
81 | ./.fcm-make-friend/config-on-success.cfg |
---|
82 | ./.fcm-make-friend/ctx.gz |
---|
83 | ./build/bin/greet.exe |
---|
84 | ./build/bin/hello.exe |
---|
85 | ./build/o/greet.o |
---|
86 | __FIND__ |
---|
87 | #------------------------------------------------------------------------------- |
---|
88 | mkdir -p 'snub/src' |
---|
89 | cat >'snub/fcm-make-no-friend.cfg' <<'__CFG__' |
---|
90 | use=$HERE/../hello |
---|
91 | name=-no-friend |
---|
92 | steps=build |
---|
93 | build.source=$HERE/src |
---|
94 | build.target{task}=link |
---|
95 | __CFG__ |
---|
96 | run_fail "${TEST_KEY_BASE}-snub" fcm make -C "${PWD}/snub" -n '-no-friend' |
---|
97 | sed -i '3q' "${TEST_KEY_BASE}-snub.err" # 3 lines only |
---|
98 | file_cmp "${TEST_KEY_BASE}-snub.err" "${TEST_KEY_BASE}-snub.err" <<__ERR__ |
---|
99 | [FAIL] use = ${PWD}/hello: incorrect value in declaration |
---|
100 | [FAIL] config-file=${PWD}/snub/fcm-make-no-friend.cfg:1 |
---|
101 | [FAIL] ${PWD}/hello/.fcm-make/ctx.gz: cannot retrieve cache |
---|
102 | __ERR__ |
---|
103 | #------------------------------------------------------------------------------- |
---|
104 | exit |
---|