Debian Codegraph @

tests/functional/cylc-clean/02-targeted.t

raw
1 #!/usr/bin/env bash
2 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
3 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # -----------------------------------------------------------------------------
18 # Test the cylc clean command
19
20 . "$(dirname "$0")/test_header"
21 if ! command -v 'tree' >'/dev/null'; then
22 skip_all '"tree" command not available'
23 fi
24 set_test_number 16
25
26 # Generate random name for symlink dirs to avoid any clashes with other tests
27 SYM_NAME="$(mktemp -u)"
28 SYM_NAME="sym-${SYM_NAME##*tmp.}"
29
30 create_test_global_config "" "
31 [install]
32 [[symlink dirs]]
33 [[[localhost]]]
34 run = ${TEST_DIR}/${SYM_NAME}/run
35 log = ${TEST_DIR}/${SYM_NAME}/other
36 share = ${TEST_DIR}/${SYM_NAME}/other
37 work = ${TEST_DIR}/${SYM_NAME}/other
38 # Need to override any symlink dirs set in global.cylc:
39 share/cycle =
40 "
41 install_workflow "${TEST_NAME_BASE}" basic-workflow
42 # Also create some other file
43 touch "${WORKFLOW_RUN_DIR}/darmok.cylc"
44
45 run_ok "${TEST_NAME_BASE}-val" cylc validate "$WORKFLOW_NAME"
46
47 FUNCTIONAL_DIR="${TEST_SOURCE_DIR_BASE%/*}"
48 # -----------------------------------------------------------------------------
49 TEST_NAME="${TEST_NAME_BASE}-run-dir-readlink-pre-clean"
50 readlink "$WORKFLOW_RUN_DIR" > "${TEST_NAME}.stdout"
51 cmp_ok "${TEST_NAME}.stdout" <<< "${TEST_DIR}/${SYM_NAME}/run/cylc-run/${WORKFLOW_NAME}"
52
53 TEST_NAME="${TEST_NAME_BASE}-testdir-tree-pre-clean"
54 run_ok "${TEST_NAME}" tree -L 5 --noreport --charset=ascii "${TEST_DIR}/${SYM_NAME}/"*"/cylc-run/${CYLC_TEST_REG_BASE}"
55 # Note: backticks need to be escaped in the heredoc
56 cmp_ok "${TEST_NAME}.stdout" << __TREE__
57 ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${CYLC_TEST_REG_BASE}
58 \`-- ${FUNCTIONAL_DIR}
59 \`-- cylc-clean
60 \`-- ${TEST_NAME_BASE}
61 |-- log
62 | \`-- install
63 |-- share
64 \`-- work
65 ${TEST_DIR}/${SYM_NAME}/run/cylc-run/${CYLC_TEST_REG_BASE}
66 \`-- ${FUNCTIONAL_DIR}
67 \`-- cylc-clean
68 \`-- ${TEST_NAME_BASE}
69 |-- _cylc-install
70 | \`-- source -> ${TEST_DIR}/${WORKFLOW_NAME}
71 |-- darmok.cylc
72 |-- flow.cylc
73 |-- log -> ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${WORKFLOW_NAME}/log
74 |-- share -> ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${WORKFLOW_NAME}/share
75 \`-- work -> ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${WORKFLOW_NAME}/work
76 __TREE__
77 # -----------------------------------------------------------------------------
78 # Clean the log dir only
79 run_ok "${TEST_NAME_BASE}-targeted-clean-1" cylc clean "$WORKFLOW_NAME" \
80 --rm log
81
82 TEST_NAME="${TEST_NAME_BASE}-testdir-tree-1"
83 run_ok "${TEST_NAME}" tree -L 5 --noreport --charset=ascii "${TEST_DIR}/${SYM_NAME}/"*"/cylc-run/${CYLC_TEST_REG_BASE}"
84 cmp_ok "${TEST_NAME}.stdout" << __TREE__
85 ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${CYLC_TEST_REG_BASE}
86 \`-- ${FUNCTIONAL_DIR}
87 \`-- cylc-clean
88 \`-- ${TEST_NAME_BASE}
89 |-- share
90 \`-- work
91 ${TEST_DIR}/${SYM_NAME}/run/cylc-run/${CYLC_TEST_REG_BASE}
92 \`-- ${FUNCTIONAL_DIR}
93 \`-- cylc-clean
94 \`-- ${TEST_NAME_BASE}
95 |-- _cylc-install
96 | \`-- source -> ${TEST_DIR}/${WORKFLOW_NAME}
97 |-- darmok.cylc
98 |-- flow.cylc
99 |-- share -> ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${WORKFLOW_NAME}/share
100 \`-- work -> ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${WORKFLOW_NAME}/work
101 __TREE__
102 # -----------------------------------------------------------------------------
103 # Clean using a glob
104 run_ok "${TEST_NAME_BASE}-targeted-clean-2" cylc clean "$WORKFLOW_NAME" \
105 --rm 'wo*'
106
107 TEST_NAME="${TEST_NAME_BASE}-testdir-tree-2"
108 run_ok "${TEST_NAME}" tree -L 5 --noreport --charset=ascii "${TEST_DIR}/${SYM_NAME}/"*"/cylc-run/${CYLC_TEST_REG_BASE}"
109 # Note: when using glob, the symlink dir target is not deleted
110 cmp_ok "${TEST_NAME}.stdout" << __TREE__
111 ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${CYLC_TEST_REG_BASE}
112 \`-- ${FUNCTIONAL_DIR}
113 \`-- cylc-clean
114 \`-- ${TEST_NAME_BASE}
115 \`-- share
116 ${TEST_DIR}/${SYM_NAME}/run/cylc-run/${CYLC_TEST_REG_BASE}
117 \`-- ${FUNCTIONAL_DIR}
118 \`-- cylc-clean
119 \`-- ${TEST_NAME_BASE}
120 |-- _cylc-install
121 | \`-- source -> ${TEST_DIR}/${WORKFLOW_NAME}
122 |-- darmok.cylc
123 |-- flow.cylc
124 \`-- share -> ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${WORKFLOW_NAME}/share
125 __TREE__
126 # -----------------------------------------------------------------------------
127 # Clean the last remaining symlink dir
128 run_ok "${TEST_NAME_BASE}-targeted-clean-3" cylc clean "$WORKFLOW_NAME" \
129 --rm 'share'
130
131 TEST_NAME="${TEST_NAME_BASE}-testdir-tree-3"
132 run_ok "${TEST_NAME}" tree -L 5 --noreport --charset=ascii "${TEST_DIR}/${SYM_NAME}/"*"/cylc-run/${CYLC_TEST_REG_BASE}"
133 cmp_ok "${TEST_NAME}.stdout" << __TREE__
134 ${TEST_DIR}/${SYM_NAME}/run/cylc-run/${CYLC_TEST_REG_BASE}
135 \`-- ${FUNCTIONAL_DIR}
136 \`-- cylc-clean
137 \`-- ${TEST_NAME_BASE}
138 |-- _cylc-install
139 | \`-- source -> ${TEST_DIR}/${WORKFLOW_NAME}
140 |-- darmok.cylc
141 \`-- flow.cylc
142 __TREE__
143 # -----------------------------------------------------------------------------
144 # Clean multiple things
145 run_ok "${TEST_NAME_BASE}-targeted-clean-3" cylc clean "$WORKFLOW_NAME" \
146 --rm 'flow.cylc' --rm 'darmok.cylc'
147
148 TEST_NAME="${TEST_NAME_BASE}-testdir-tree-3"
149 run_ok "${TEST_NAME}" tree -L 5 --noreport --charset=ascii "${TEST_DIR}/${SYM_NAME}/"*"/cylc-run/${CYLC_TEST_REG_BASE}"
150 cmp_ok "${TEST_NAME}.stdout" << __TREE__
151 ${TEST_DIR}/${SYM_NAME}/run/cylc-run/${CYLC_TEST_REG_BASE}
152 \`-- ${FUNCTIONAL_DIR}
153 \`-- cylc-clean
154 \`-- ${TEST_NAME_BASE}
155 \`-- _cylc-install
156 \`-- source -> ${TEST_DIR}/${WORKFLOW_NAME}
157 __TREE__
158 # -----------------------------------------------------------------------------
159 purge
160 exit