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 $TEST_WORKSPACE/tests/unittest.bash)" \ 41 || { echo "Could not source bazel_skylib/tests/unittest.bash" >&2; exit 1; } 42 43function test_copy_dir_with_subdir__copies_a() { 44 cat "$(rlocation $TEST_WORKSPACE/tests/copy_directory/dir_copy)/a" >"$TEST_log" 45 expect_log '^foo$' 46} 47 48function test_copy_dir_with_subdir__copies_b() { 49 cat "$(rlocation $TEST_WORKSPACE/tests/copy_directory/dir_copy)/b" >"$TEST_log" 50 expect_log '^bar$' 51} 52 53function test_copy_dir_with_subdir__copies_c() { 54 cat "$(rlocation $TEST_WORKSPACE/tests/copy_directory/dir_copy)/subdir/c" >"$TEST_log" 55 expect_log '^moocow$' 56} 57 58function test_copy_dir_with_subdir__correct_filecounts() { 59 local -r dir_filecount=$(ls "$(rlocation $TEST_WORKSPACE/tests/copy_directory/dir_copy)" | wc -l) 60 assert_equals $dir_filecount 3 61 local -r subdir_filecount=$(ls "$(rlocation $TEST_WORKSPACE/tests/copy_directory/dir_copy)/subdir" | wc -l) 62 assert_equals $subdir_filecount 1 63} 64 65function test_copy_empty_dir() { 66 local -r filecount=$(ls "$(rlocation $TEST_WORKSPACE/tests/copy_directory/empty_dir_copy)" | wc -l) 67 assert_equals $filecount 0 68} 69 70function test_copy_dir_with_symlink__copies_file() { 71 cat "$(rlocation $TEST_WORKSPACE/tests/copy_directory/dir_with_symlink_copy)/file" >"$TEST_log" 72 expect_log '^foo$' 73} 74 75function test_copy_dir_with_symlink__copies_symlink() { 76 cat "$(rlocation $TEST_WORKSPACE/tests/copy_directory/dir_with_symlink_copy)/symlink" >"$TEST_log" 77 expect_log '^foo$' 78} 79 80 81run_suite "copy_directory test suite" 82