You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by we...@apache.org on 2020/09/07 01:42:08 UTC

[apisix] branch master updated: test case: optimize output of check-plugins-code (#2173)

This is an automated email from the ASF dual-hosted git repository.

wenming pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 3ece377  test case: optimize output of check-plugins-code (#2173)
3ece377 is described below

commit 3ece377d3ff920a3f46c0fa93312e5d7b276f63f
Author: Shuyang Wu <wo...@gmail.com>
AuthorDate: Mon Sep 7 09:41:59 2020 +0800

    test case: optimize output of check-plugins-code (#2173)
---
 .travis/linux_openresty_runner.sh |  2 +-
 utils/check-plugins-code.sh       | 24 ++++++++++++++++--------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/.travis/linux_openresty_runner.sh b/.travis/linux_openresty_runner.sh
index 42ff254..7281c0d 100755
--- a/.travis/linux_openresty_runner.sh
+++ b/.travis/linux_openresty_runner.sh
@@ -164,7 +164,7 @@ script() {
     ./bin/apisix stop
     sleep 1
 
-    sudo sh ./utils/check-plugins-code.sh
+    sudo bash ./utils/check-plugins-code.sh
 
     make lint && make license-check || exit 1
     APISIX_ENABLE_LUACOV=1 PERL5LIB=.:$PERL5LIB prove -Itest-nginx/lib -r t
diff --git a/utils/check-plugins-code.sh b/utils/check-plugins-code.sh
index 7d85e9b..910962c 100755
--- a/utils/check-plugins-code.sh
+++ b/utils/check-plugins-code.sh
@@ -17,25 +17,29 @@
 # limitations under the License.
 #
 
+RED="\033[1;31m";
+NC="\033[0m"; # No Color
+hit=0
 
 checkfunc () {
     funccontent=$1
-    [[ $funccontent =~ "core.response.exit" ]] && echo "can't exit in rewrite or access phase !" && exit 1
-    [[ $funccontent =~ "ngx.exit" ]] && echo "can't exit in rewrite or access phase !" && exit 1
-    echo "passed."
+    file=$2
+    [[ $funccontent =~ "core.response.exit" ]] && echo -e ${RED}${file}${NC} && echo "    can't exit in rewrite or access phase!" && ((hit++))
+    [[ $funccontent =~ "ngx.exit" ]] && echo -e ${RED}${file}${NC} && echo "    can't exit in rewrite or access phase!" && ((hit++))
 }
 
 
 filtercode () {
     content=$1
+    file=$2
 
     rcontent=${content##*_M.rewrite}
     rewritefunc=${rcontent%%function*}
-    checkfunc "$rewritefunc"
+    checkfunc "$rewritefunc" "$file"
 
     rcontent=${content##*_M.access}
     accessfunc=${rcontent%%function*}
-    checkfunc "$accessfunc"
+    checkfunc "$accessfunc" "$file"
 }
 
 
@@ -43,14 +47,18 @@ for file in apisix/plugins/*.lua
 do
     if test -f $file
     then
-        echo $file
         content=$(cat $file)
-        filtercode "$content"
+        filtercode "$content" "$file"
     fi
 done
 
+if (($hit>0))
+then
+    exit 1
+fi
+
 # test case for check
 content=$(cat t/fake-plugin-exit.lua)
 filtercode "$content" > test.log 2>&1 || (cat test.log && exit 1)
 
-echo "done."
+echo "All passed."