golang.org/x/tools/gopls@v0.15.3/integration/govim/run_local.sh (about)

     1  #!/bin/bash -e
     2  
     3  # Copyright 2019 The Go Authors. All rights reserved.
     4  # Use of this source code is governed by a BSD-style
     5  # license that can be found in the LICENSE file.
     6  
     7  # Run govim integration tests against a local gopls.
     8  
     9  usage() {
    10    cat <<EOUSAGE
    11  Usage: $0 [--sudo] [--short] [--version (semver|latest)]
    12  
    13  Args:
    14    --sudo     run docker with sudo
    15    --short    run `go test` with `-short`
    16    --version  run on the specific tagged govim version (or latest) rather
    17               than the default branch
    18  
    19  Run govim tests against HEAD using local docker.
    20  EOUSAGE
    21  }
    22  
    23  SUDO_IF_NEEDED=
    24  TEST_SHORT=
    25  DOCKERFILE=gopls/integration/govim/Dockerfile
    26  GOVIM_REF=main
    27  while [[ $# -gt 0 ]]; do
    28    case "$1" in
    29      "-h" | "--help" | "help")
    30        usage
    31        exit 0
    32        ;;
    33      "--sudo")
    34        SUDO_IF_NEEDED="sudo "
    35        shift
    36        ;;
    37      "--short")
    38        TEST_SHORT="-short"
    39        shift
    40        ;;
    41      "--version")
    42        if [[ -z "$2" ]]; then
    43          usage
    44          exit 1
    45        fi
    46        GOVIM_REF=$2
    47        if [[ "${GOVIM_REF}" == "latest" ]]; then
    48          TMPGOPATH=$(mktemp -d)
    49          trap "GOPATH=${TMPGOPATH} go clean -modcache && rm -r ${TMPGOPATH}" EXIT
    50          GOVIM_REF=$(GOPATH=${TMPGOPATH} go mod download -json \
    51            github.com/govim/govim@latest | jq -r .Version)
    52        fi
    53        shift 2
    54        ;;
    55      *)
    56        usage
    57        exit 1
    58    esac
    59  done
    60  
    61  # Find the tools root, so that this script can be run from any directory.
    62  script_dir=$(dirname "$(readlink -f "$0")")
    63  tools_dir=$(readlink -f "${script_dir}/../../..")
    64  
    65  # Build gopls.
    66  cd "${tools_dir}/gopls"
    67  temp_gopls=$(mktemp -p "$PWD")
    68  trap "rm -f \"${temp_gopls}\"" EXIT
    69  # For consistency across environments, use golang docker to build rather than
    70  # the local go command.
    71  ${SUDO_IF_NEEDED}docker run --rm -t \
    72    -v "${tools_dir}:/src/tools" \
    73    -w "/src/tools/gopls" \
    74    golang:rc \
    75    go build -o $(basename ${temp_gopls})
    76  
    77  # Build the test harness. Here we are careful to pass in a very limited build
    78  # context so as to optimize caching.
    79  echo "Checking out govim@${GOVIM_REF}"
    80  cd "${tools_dir}"
    81  ${SUDO_IF_NEEDED}docker build \
    82    --build-arg GOVIM_REF="${GOVIM_REF}" \
    83    -t gopls-govim-harness:${GOVIM_REF} \
    84    -f gopls/integration/govim/Dockerfile \
    85    gopls/integration/govim
    86  
    87  # Run govim integration tests.
    88  echo "running govim integration tests using ${temp_gopls}"
    89  temp_gopls_name=$(basename "${temp_gopls}")
    90  ${SUDO_IF_NEEDED}docker run --rm -t \
    91    -v "${tools_dir}:/src/tools" \
    92    -w "/src/govim" \
    93    --ulimit memlock=-1:-1 \
    94    gopls-govim-harness:${GOVIM_REF} \
    95    go test ${TEST_SHORT} ./cmd/govim \
    96      -gopls "/src/tools/gopls/${temp_gopls_name}"