aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/shell/test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'examples/shell/test.sh')
-rwxr-xr-xexamples/shell/test.sh30
1 files changed, 23 insertions, 7 deletions
diff --git a/examples/shell/test.sh b/examples/shell/test.sh
index 6b7ba90e37..b4c7bf821b 100755
--- a/examples/shell/test.sh
+++ b/examples/shell/test.sh
@@ -14,17 +14,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-set -eu
+set -euo pipefail
+# --- begin runfiles.bash initialization ---
+if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
+ if [[ -f "$0.runfiles_manifest" ]]; then
+ export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
+ elif [[ -f "$0.runfiles/MANIFEST" ]]; then
+ export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
+ elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
+ export RUNFILES_DIR="$0.runfiles"
+ fi
+fi
+if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
+ source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
+elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
+ source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
+ "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
+else
+ echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
+ exit 1
+fi
+# --- end runfiles.bash initialization ---
-# This allows RUNFILES to be declared outside the script it you want.
-# RUNFILES for test is the directory of the script.
-RUNFILES=${RUNFILES:-$($(cd $(dirname ${BASH_SOURCE[0]})); pwd)}
-
-source "${RUNFILES}/examples/shell/lib.sh"
+source "$(rlocation io_bazel/examples/shell/lib.sh)"
function test_output {
OUTPUT=$(showfile)
- EXPECTED_OUTPUT=$(cat "${RUNFILES}/examples/shell/data/test_file.txt")
+ EXPECTED_OUTPUT=$(cat "$(rlocation io_bazel/examples/shell/data/test_file.txt)")
if [ "${OUTPUT}" != "${EXPECTED_OUTPUT}" ]; then
# This would be a failure case.