1 # Copyright (c) 2021 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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # This file should be executed from tox, as the assumed 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.
21 # This script checks if the number of tests in a job specification is the same
22 # as declared at the beginning of the file.
23 # It counts the lines not starting with '#' so it can also detect redundant
24 # empty lines, or lines which should not be in the job specification.
26 # "set -eu" handles failures from the following two lines.
27 BASH_CHECKS_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))"
28 BASH_FUNCTION_DIR="$(readlink -e "${BASH_CHECKS_DIR}/../../function")"
29 source "${BASH_FUNCTION_DIR}/common.sh" || {
30 echo "Source failed." >&2
34 job_spec_dir="docs/job_specs/"
35 rm -f "job_spec.log" || die
38 # Disabling -x: Following lines are doing too much garbage output.
41 for f in $(find ${job_spec_dir} -type f | grep -v perf_tests_job_specs); do
42 declared=$(fgrep "### tests" $f | tr -dc '0-9')
43 present=$(fgrep -v '#' $f | wc -l)
44 if [ "${declared}" != "${present}" ]; then
45 echo "Wrong number of tests detected in ${f}: \
46 declared: ${declared} / present: ${present}" | tee -a job_spec.log
47 violations=$((violations+1))
53 if [ "${violations}" != "0" ]; then
55 warn "Number of tests in job spec checker: FAIL"
60 warn "Number of tests in job spec checker: PASS"