Debian Codegraph @

tests/f/cylc-lint/01.lint-toml.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 #------------------------------------------------------------------------------
19 # Test linting with a toml file present.
20 . "$(dirname "$0")/test_header"
21 set_test_number 12
22
23 # Set Up:
24 rm etc/global.cylc
25
26 LINE_LEN_NO=$(python -c "from cylc.flow.scripts.lint import LINE_LEN_NO; print(LINE_LEN_NO)")
27
28 cat > flow.cylc <<__HERE__
29 # This is definitely not an OK flow.cylc file.
30 \t[scheduler]
31
32 [cylc]
33
34 [[dependencies]]
35
36 [runtime]
37 [[foo]]
38 inherit = hello
39 [[[job]]]
40 something\t
41 __HERE__
42
43 mkdir sites
44
45 cat > sites/niwa.cylc <<__HERE__
46 blatantly = not valid
47 __HERE__
48
49
50 # Control tests
51 TEST_NAME="it lints without toml file"
52 run_fail "${TEST_NAME}" cylc lint
53 TESTOUT="${TEST_NAME}.stdout"
54 named_grep_ok "it returns error code" "S004" "${TESTOUT}"
55 named_grep_ok "it returns error from subdirectory" "niwa.cylc" "${TESTOUT}"
56 named_grep_ok "it returns a 728 upgrade code" "^\[U" "${TESTOUT}"
57
58
59 # Add a pyproject.toml file
60 cat > pyproject.toml <<__HERE__
61 [tool.cylc.lint]
62 # Check against these rules
63 rulesets = [
64 "style"
65 ]
66 # do not check for these errors
67 ignore = [
68 "S004"
69 ]
70 # do not lint files matching
71 # these globs:
72 exclude = [
73 "sites/*.cylc",
74 ]
75 __HERE__
76
77 # Test that results are different:
78 TEST_NAME="it_lints_with_toml_file"
79 run_fail "${TEST_NAME}" cylc lint
80 TESTOUT="${TEST_NAME}.stdout"
81 grep_fail "S004" "${TESTOUT}"
82 grep_fail "niwa.cylc" "${TESTOUT}"
83 grep_fail "^\[U" "${TESTOUT}"
84
85
86 # Add a max line length to the pyproject.toml.
87 echo "" >> pyproject.toml
88 echo "max-line-length = 4" >> pyproject.toml
89
90 cat > flow.cylc <<__HERE__
91 script = """
92 How long a line is too long a line
93 """
94 __HERE__
95
96 TEST_NAME="it_fails_if_max-line-length_set"
97 run_fail "${TEST_NAME}" cylc lint
98 named_grep_ok "${TEST_NAME}-line-too-long-message" \
99 "\[${LINE_LEN_NO}\] flow.cylc:2: line > 4 characters." \
100 "${TEST_NAME}.stdout"
101
102 TEST_NAME="it_does_not_fail_if_max-line-length_set_but_ignored"
103 cat > pyproject.toml <<__HERE__
104 [tool.cylc.lint]
105 # Check against these rules
106 rulesets = [
107 "style"
108 ]
109 # do not check for these errors
110 ignore = [
111 "${LINE_LEN_NO}"
112 ]
113 exclude = [
114 "sites/*.cylc",
115 ]
116 max-line-length = 1
117 __HERE__
118 run_ok "${TEST_NAME}" cylc lint
119 grep_ok "rules and found no issues" "${TEST_NAME}.stdout"