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

     1  #!/bin/sh
     2  #
     3  # Usage: add-leaktest.sh pkg/*_test.go
     4  
     5  set -eu
     6  
     7  sed -i'~' -e '
     8    /^func (s \*test.*Suite) Test.*(c \*C) {/ {
     9      n
    10      /testleak.AfterTest/! i\
    11  		defer testleak.AfterTest(c)()
    12    }
    13  ' $@
    14  
    15  for i in $@; do
    16    if ! cmp -s $i $i~ ; then
    17      goimports -w $i
    18    fi
    19  echo $i
    20    rm -f $i~
    21  done