github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/soliton/testleak/check-leaktest.sh (about) 1 #!/bin/sh 2 # Copyright 2020 WHTCORPS INC, Inc. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 # Usage: check-leaktest.sh 16 # It needs to run under the github.com/whtcorpsinc/milevadb directory. 17 18 set -e 19 20 pkgs=$(git grep 'Suite' |grep -vE "Godeps|tags" |awk -F: '{print $1}' | xargs -n1 dirname | sort |uniq) 21 echo $pkgs 22 for pkg in ${pkgs}; do 23 if [ -z "$(ls ${pkg}/*_test.go 2>/dev/null)" ]; then 24 continue 25 fi 26 awk -F'[(]' ' 27 /func \(s .*Suite\) Test.*C\) {/ { 28 test = $1"("$2 29 next 30 } 31 32 /defer testleak.AfterTest/ { 33 test = 0 34 next 35 } 36 37 { 38 if (test && (FILENAME != "./milevadb_test.go")) { 39 printf "%s: %s: missing defer testleak.AfterTest\n", FILENAME, test 40 test = 0 41 code = 1 42 } 43 } 44 45 END { 46 exit code 47 } 48 49 ' ${pkg}/*_test.go 50 done