1#!/usr/bin/env bash 2 3# Copyright 2019 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# --- begin runfiles.bash initialization --- 18# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). 19set -euo pipefail 20if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then 21 if [[ -f "$0.runfiles_manifest" ]]; then 22 export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" 23 elif [[ -f "$0.runfiles/MANIFEST" ]]; then 24 export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" 25 elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then 26 export RUNFILES_DIR="$0.runfiles" 27 fi 28fi 29if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then 30 source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" 31elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then 32 source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ 33 "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" 34else 35 echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" 36 exit 1 37fi 38# --- end runfiles.bash initialization --- 39 40source "$(rlocation bazel_skylib/tests/unittest.bash)" \ 41 || { echo "Could not source bazel_skylib/tests/unittest.bash" >&2; exit 1; } 42 43function test_copy_src() { 44 cat "$(rlocation bazel_skylib/tests/copy_file/out/a-out.txt)" >"$TEST_log" 45 expect_log '^#!/usr/bin/env bash$' 46 expect_log '^echo aaa$' 47} 48 49function test_copy_src_symlink() { 50 cat "$(rlocation bazel_skylib/tests/copy_file/out/a-out-symlink.txt)" >"$TEST_log" 51 expect_log '^#!/usr/bin/env bash$' 52 expect_log '^echo aaa$' 53} 54 55function test_copy_gen() { 56 cat "$(rlocation bazel_skylib/tests/copy_file/out/gen-out.txt)" >"$TEST_log" 57 expect_log '^#!/usr/bin/env bash$' 58 expect_log '^echo potato$' 59} 60 61function test_copy_gen_symlink() { 62 cat "$(rlocation bazel_skylib/tests/copy_file/out/gen-out-symlink.txt)" >"$TEST_log" 63 expect_log '^#!/usr/bin/env bash$' 64 expect_log '^echo potato$' 65} 66 67function test_copy_xsrc() { 68 cat "$(rlocation bazel_skylib/tests/copy_file/xsrc-out.txt)" >"$TEST_log" 69 expect_log '^aaa$' 70} 71 72function test_copy_xsrc_symlink() { 73 cat "$(rlocation bazel_skylib/tests/copy_file/xsrc-out-symlink.txt)" >"$TEST_log" 74 expect_log '^aaa$' 75} 76 77function test_copy_xgen() { 78 cat "$(rlocation bazel_skylib/tests/copy_file/xgen-out.txt)" >"$TEST_log" 79 expect_log '^potato$' 80} 81 82function test_copy_xgen_symlink() { 83 cat "$(rlocation bazel_skylib/tests/copy_file/xgen-out-symlink.txt)" >"$TEST_log" 84 expect_log '^potato$' 85} 86 87run_suite "copy_file_tests test suite" 88