github.com/bazelbuild/rules_webtesting@v0.2.0/web/internal/web_test.sh.template (about)

     1  #!/bin/bash
     2  # Copyright 2016 Google 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  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  #
    16  ################################################################################
    17  #
    18  
    19  if [[ -z "$TEST_SRCDIR" ]]; then
    20    case "$0" in
    21      /*) self="$0" ;;
    22      *)  self="$PWD/$0" ;;
    23    esac
    24  
    25    if [[ -e "$self.runfiles" ]]; then
    26      export TEST_SRCDIR="$self.runfiles"
    27    else
    28      echo "Unable to determine runfiles location"
    29      exit -1
    30    fi
    31  fi
    32  
    33  if [[ -z "$TEST_TEMPDIR" ]]; then
    34    export TEST_TEMPDIR=$(mktemp -d test_tempdir.XXXXXX)
    35  fi
    36  
    37  %TEMPLATED_env_vars%
    38  
    39  printenv
    40  
    41  # Split arguments into wtl_launcher_args and wtl_test_args. These variables are
    42  # prefixed "wtl_" to reduce the chance of colliding with environment variables
    43  # that the user intends to pass through to the wrapped test. (It's uncommon to
    44  # name environment variables with lowercase letters, and yet, we had a bug
    45  # report where this collision occurred.)
    46  wtl_test_args=()
    47  wtl_launcher_args=()
    48  wtl_arg_at_next=0
    49  
    50  for arg in "$@"; do
    51    if (( "$wtl_arg_at_next" )); then
    52      wtl_launcher_args+=("$arg")
    53      wtl_arg_at_next=0
    54    elif [[ "$arg" == --wtl_arg=* ]]; then
    55      wtl_launcher_args+=("${arg#--wtl_arg=}")
    56    elif [[ "$arg" == "--wtl_arg" ]];  then
    57      wtl_arg_at_next=1
    58    else
    59      wtl_test_args+=("$arg")
    60    fi
    61  done
    62  
    63  "$TEST_SRCDIR/%TEMPLATED_launcher%" \
    64    --metadata="%TEMPLATED_metadata%" \
    65    --test="%TEMPLATED_test%" \
    66    "${wtl_launcher_args[@]}" \
    67    -- "${wtl_test_args[@]}"