From 1b9efc01cedb3395a13a8eb33bb869aaa40f148a Mon Sep 17 00:00:00 2001 From: Castulo Martinez Date: Sat, 6 Apr 2019 00:42:36 +0000 Subject: [PATCH] Checking for duplicated or missing test IDs Signed-off-by: Castulo Martinez --- .travis.yml | 3 +- Makefile.am | 3 ++ test/functional/check_ids.bash | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100755 test/functional/check_ids.bash diff --git a/.travis.yml b/.travis.yml index 368efb7a..8ab6584a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -72,7 +72,8 @@ before_script: - sudo find test/functional -exec chmod g-w {} \; - make && sudo sh -c 'umask 0022 && make install' && - sudo sh -c 'umask 0022 && make install-check' + sudo sh -c 'umask 0022 && make install-check' && + sh -c 'make check-test-ids' after_failure: - cat test-suite.log diff --git a/Makefile.am b/Makefile.am index 8ba4202c..263b9014 100644 --- a/Makefile.am +++ b/Makefile.am @@ -390,6 +390,9 @@ shellcheck-all: shellcheck -s bash -x -e SC1008 /dev/stdin \ " \; +check-test-ids: + test/functional/check_ids.bash + release: @git rev-parse v$(PACKAGE_VERSION) &> /dev/null; \ if [ "$$?" -eq 0 ]; then \ diff --git a/test/functional/check_ids.bash b/test/functional/check_ids.bash new file mode 100755 index 00000000..6391661a --- /dev/null +++ b/test/functional/check_ids.bash @@ -0,0 +1,50 @@ +#!/bin/bash + +FUNC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# shellcheck source=/dev/null +source "$FUNC_DIR"/testlib.bash + +declare -A groups=( ["bundleadd"]="ADD" ["bundlelist"]="LST" ["bundleremove"]="REM" \ + ["checkupdate"]="CHK" ["hashdump"]="HSD" ["mirror"]="MIR" ["search"]="SRH" \ + ["update"]="UPD" ["usability"]="USA" ["verify"]="VER" ) + +invalid=false + +for group in "${!groups[@]}"; do + + group_code="${groups[$group]}" + num_tests=$(list_tests "$FUNC_DIR/$group" | wc -l) + + for iter in $(seq -f "%03g" 1 "$num_tests"); do + + found=0 + + for id in $(list_tests "$FUNC_DIR/$group" | cut -d ":" -f 1 | sort); do + if [ "$group_code$iter" = "$id" ]; then + found=$((found + 1)) + fi + done + + if [ "$found" -eq 0 ]; then + echo "A test with ID '$group_code$iter' was not found." + invalid=true + elif [ "$found" -gt 1 ]; then + echo "Found $found tests with duplicated IDs in '$group'." + invalid=true + fi + + done + +done + +if [ "$invalid" = true ]; then + + echo -e "\nRun 'list_tests --all' to check the test IDs." + exit 1 + +fi + +echo "All tests have valid IDs." + +exit 0