Skip to contentSkip to conversation

tst_test.sh: Reduce false positives in reserved variable warnings

PATCH New Petr Vorel 2 participants 3 messages Aug 9, 2019

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 tst_test.sh: Reduce false positives in reserved variable warnings

"Reserved variable TST_FOO used!" and "Private variable or function _tst_foo used!" reports some false positive.

Filter out commented code and variables and functions not starting with searched prefix (foo_tst_bar() or $foo_tst_bar).

NOTE: There are still some false positives (e.g. echo "echo TST_SHOULD_NOT_BE_FOUND"), but let's not complicate the regexp too much.

---
 testcases/lib/tst_test.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/lib/tst_test.sh +2 -2
index 31b3a3951..f779cc471 100644
@@ -402,7 +402,7 @@ tst_run()
 	local _tst_name
 
 	if [ -n "$TST_TEST_PATH" ]; then
-		for _tst_i in $(grep TST_ "$TST_TEST_PATH" | sed 's/.*TST_//; s/[="} \t\/:`].*//'); do
+		for _tst_i in $(grep '^[^#]*\bTST_' "$TST_TEST_PATH" | sed 's/.*TST_//; s/[="} \t\/:`].*//'); do
 			case "$_tst_i" in
 			DISABLE_APPARMOR|DISABLE_SELINUX);;
 			SETUP|CLEANUP|TESTFUNC|ID|CNT|MIN_KVER);;
@@ -417,7 +417,7 @@ tst_run()
 			esac
 		done
 
-		for _tst_i in $(grep _tst_ "$TST_TEST_PATH" | sed 's/.*_tst_//; s/[="} \t\/:`].*//'); do
+		for _tst_i in $(grep '^[^#]*\b_tst_' "$TST_TEST_PATH" | sed 's/.*_tst_//; s/[="} \t\/:`].*//'); do
 			tst_res TWARN "Private variable or function _tst_$_tst_i used!"
 		done
 	fi
Signature · 1 line
2.22.0
#1 lore raw

PATCH 1/1 tst_test.sh: Reduce false positives in reserved variable warnings

Hi!
Looks good, acked.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH 1/1 tst_test.sh: Reduce false positives in reserved variable warnings

Hi Cyril,

Quoted 2 lines

Hi!
Looks good, acked.

Thanks for review, merged.

Kind regards,
Petr