diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-04-06 11:40:19 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-04-06 12:02:37 +0200 |
commit | 6f47c5657f827a6202ad9f1937358893d2722132 (patch) | |
tree | a4348e1fa870bc5915bd5d43ca04a17f63485807 /build/check-controllers.sh | |
parent | 08a2b27df5e282a6b5221fbe72f700523c7b0913 (diff) |
build: add check-controller.sh, a utility to test controller files
The main purpose of the script is to check if the module declaration
matches and if associated cbi resources are properly referenced.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'build/check-controllers.sh')
-rwxr-xr-x | build/check-controllers.sh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/build/check-controllers.sh b/build/check-controllers.sh new file mode 100755 index 000000000..573e6f864 --- /dev/null +++ b/build/check-controllers.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +[ -d build ] || { + echo "Execute as ./build/check-controllers.sh" >&2 + exit 1 +} + +find . -type f -name '*.lua' -path '*/controller/*' | while read controller; do + controller="${controller#./}" + base="${controller%%/controller/*}" + + sed -rne 's#^.*\b(cbi|form)\([[:space:]]*("([^"]*)"|\047([^\047]*)\047)[[:space:]]*[,)].*$#\1 \3\4#gp' "$controller" | while read type map; do + model="$base/model/cbi/$map.lua" + package="${controller##*/controller/}"; package="${package%.lua}"; package="luci.controller.${package//\//.}" + + if ! grep -sqE '\bmodule[[:space:]]*\(?[[:space:]]*("|\047|\[=*\[)'"$package" "$controller"; then + echo "'$controller' does not containt the expected\n\t'module(\"$package\", ...)' line.\n" + fi + + grep -sqE '\b(Form|SimpleForm)[[:space:]]*\(' "$model" && ! grep -sqE '\bMap[[:space:]]*\(' "$model" && is_form=1 || is_form=0 + + if [ ! -f "$model" ]; then + echo -e "'$controller' references $type('$map')\n\tbut expected file '$model' does not exist.\n" + elif [ $type = "cbi" -a $is_form = 1 ]; then + echo -e "'$controller' references $type('$map')\n\tbut '$model' looks like a Form or SimpleForm.\n" + elif [ $type = "form" -a $is_form = 0 ]; then + echo -e "'$controller' references $type('$map')\n\tbut '$model' does not look like a Form or SimpleForm.\n" + fi + done +done |