github.com/XiaoMi/Gaea@v1.2.5/util/testleak/check-leaktest.sh (about)

     1  #!/bin/sh
     2  #
     3  # Usage: check-leaktest.sh
     4  # It needs to run under the github.com/pingcap/tidb directory.
     5  
     6  set -e
     7  
     8  pkgs=$(git grep 'Suite' |grep -vE "Godeps|tags" |awk -F: '{print $1}' | xargs -n1 dirname | sort |uniq)
     9  echo $pkgs
    10  for pkg in ${pkgs}; do
    11    if [ -z "$(ls ${pkg}/*_test.go 2>/dev/null)" ]; then
    12      continue
    13    fi
    14    awk -F'[(]' '
    15  /func \(s .*Suite\) Test.*C\) {/ {
    16    test = $1"("$2
    17    next
    18  }
    19  
    20  /defer testleak.AfterTest/ {
    21    test = 0
    22    next
    23  }
    24  
    25  {
    26      if (test && (FILENAME != "./tidb_test.go")) {
    27      	printf "%s: %s: missing defer testleak.AfterTest\n", FILENAME, test
    28      	test = 0
    29      	code = 1
    30      }
    31  }
    32  
    33  END {
    34    exit code
    35  }
    36  
    37  ' ${pkg}/*_test.go
    38  done