Add tox.ini and few checker scripts
[csit.git] / resources / libraries / bash / entry / check / autogen.sh
1 # Copyright (c) 2019 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 set -exuo pipefail
15
16 # This file should be executed from tox, as the assumend working directory
17 # is different from where this file is located.
18 # This file does not have executable flag nor shebang,
19 # to dissuade non-tox callers.
20
21 # This script run every executable *.py script anywhere within tests/ dir,
22 # the working directory temporarily changed to where the *.py file is.
23 # Proper virtualenv is assumed to be active.
24 # If "git diff" sees any change, this script fails.
25 # The diff output stored to autogen.log (overwriting).
26 # The *.py files are assumed to be robot suite generators,
27 # any change means the contribution does not match the generated code.
28
29 # "set -eu" handles failures from the following two lines.
30 BASH_CHECKS_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))"
31 BASH_FUNCTION_DIR="$(readlink -e "${BASH_CHECKS_DIR}/../../function")"
32 source "${BASH_FUNCTION_DIR}/common.sh" || {
33     echo "Source failed." >&2
34     exit 1
35 }
36
37 work_dir="$(pwd)" || die
38 trap "cd '${work_dir}'" EXIT || die
39 file_list="$(find ./tests -type f -executable -name '*.py')" || die
40
41 for gen in ${file_list}; do
42     directory="$(dirname "${gen}")" || die
43     filename="$(basename "${gen}")" || die
44     pushd "${directory}" || die
45     ./"${filename}" || die
46     popd || die
47 done
48
49 lines="$(git diff | tee "autogen.log" | wc -l)" || die
50 if [ "${lines}" != "0" ]; then
51     # TODO: Decide which text goes to stdout and which to stderr.
52     warn "Autogen conflict diff nonzero lines: ${lines}"
53     # TODO: Disable if output size does more harm than good.
54     cat "autogen.log" >&2
55     warn
56     warn "Autogen checker: FAIL"
57     exit 1
58 fi
59
60 warn
61 warn "Autogen checker: PASS"