github.com/tumi8/quic-go@v0.37.4-tum/mockgen_private.sh (about)

     1  #!/bin/bash
     2  
     3  DEST=$2
     4  PACKAGE=$3
     5  TMPFILE="mockgen_tmp.go"
     6  # uppercase the name of the interface
     7  ORIG_INTERFACE_NAME=$4
     8  INTERFACE_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${ORIG_INTERFACE_NAME:0:1})${ORIG_INTERFACE_NAME:1}"
     9  
    10  # Gather all files that contain interface definitions.
    11  # These interfaces might be used as embedded interfaces,
    12  # so we need to pass them to mockgen as aux_files.
    13  AUX=()
    14  for f in *.go; do
    15    if [[ -z ${f##*_test.go} ]]; then
    16      # skip test files
    17      continue;
    18    fi
    19    if $(egrep -qe "type (.*) interface" $f); then
    20      AUX+=(" github.com/tumi8/quic-go=$f")
    21    fi
    22  done
    23  
    24  # Find the file that defines the interface we're mocking.
    25  for f in *.go; do
    26    if [[ -z ${f##*_test.go} ]]; then
    27      # skip test files
    28      continue;
    29    fi
    30    INTERFACE=$(sed -n "/^type $ORIG_INTERFACE_NAME interface/,/^}/p" $f)
    31    if [[ -n "$INTERFACE" ]]; then
    32      SRC=$f
    33      break
    34    fi
    35  done
    36  
    37  if [[ -z "$INTERFACE" ]]; then
    38    echo "Interface $ORIG_INTERFACE_NAME not found."
    39    exit 1
    40  fi
    41  
    42  AUX_FILES=$(IFS=, ; echo "${AUX[*]}")
    43  
    44  ## create a public alias for the interface, so that mockgen can process it
    45  echo -e "package $1\n" > $TMPFILE
    46  echo "$INTERFACE" | sed "s/$ORIG_INTERFACE_NAME/$INTERFACE_NAME/" >> $TMPFILE
    47  mockgen -package $1 -self_package $3 -destination $DEST -source=$TMPFILE -aux_files $AUX_FILES
    48  sed "s/$TMPFILE/$SRC/" "$DEST" > "$DEST.new" && mv "$DEST.new" "$DEST"
    49  rm "$TMPFILE"