Luis Fernando Pino Duque | fa38906 | 2016-10-18 14:28:42 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2016 The Bazel Authors. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
| 18 | function print_message_and_exit() { |
| 19 | echo $1 >&2; exit 1; |
| 20 | } |
| 21 | |
Laszlo Csomor | 2bcf7cd | 2018-06-14 07:32:07 -0700 | [diff] [blame] | 22 | if type rlocation >&/dev/null; then |
| 23 | # If rlocation is defined, use it to look up data-dependencies. |
| 24 | # Load the unit test framework |
| 25 | source "$(rlocation io_bazel/src/test/shell/unittest.bash)" \ |
| 26 | || print_message_and_exit "unittest.bash not found!" |
| 27 | # Load the test environment |
| 28 | source "$(rlocation io_bazel/src/test/shell/testenv.sh)" \ |
| 29 | || print_message_and_exit "testenv.sh not found!" |
| 30 | else |
| 31 | # If rlocation is undefined, we are probably running under Blaze. |
| 32 | # Assume the existence of a runfiles tree. |
Luis Fernando Pino Duque | fa38906 | 2016-10-18 14:28:42 +0000 | [diff] [blame] | 33 | |
Laszlo Csomor | 2bcf7cd | 2018-06-14 07:32:07 -0700 | [diff] [blame] | 34 | CURRENT_SCRIPT=${BASH_SOURCE[0]} |
| 35 | # Go to the directory where the script is running |
| 36 | cd "$(dirname ${CURRENT_SCRIPT})" \ |
| 37 | || print_message_and_exit "Unable to access $(dirname ${CURRENT_SCRIPT})" |
| 38 | |
| 39 | DIR=$(pwd) |
| 40 | # Load the unit test framework |
| 41 | source "$DIR/unittest.bash" || print_message_and_exit "unittest.bash not found!" |
| 42 | # Load the test environment |
| 43 | source "$DIR/testenv.sh" || print_message_and_exit "testenv.sh not found!" |
| 44 | fi |
adonovan | ebb86fc | 2020-03-20 14:57:54 -0700 | [diff] [blame] | 45 | |
| 46 | # inplace-sed: a version of sed -i that actually works on Linux and Darwin. |
| 47 | # https://unix.stackexchange.com/questions/92895 |
| 48 | # https://stackoverflow.com/questions/5694228 |
| 49 | function inplace-sed() { |
| 50 | if [ $(uname) = "Darwin" ]; then |
| 51 | sed -i "" "$@" |
| 52 | else |
| 53 | sed -i "$@" |
| 54 | fi |
| 55 | } |