diff options
author | Derek Cormier <derek@aspect.dev> | 2022-06-01 00:58:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-01 09:58:09 +0200 |
commit | 207acb38505b4a4acde45521b8c1fe07c762537a (patch) | |
tree | af55b0ddf072bb01fbe497320d532b40a3c53518 /tests/copy_directory | |
parent | 312bccd83b1364fa736dde97ccba3d2b40cdfabc (diff) | |
download | bazel-skylib-207acb38505b4a4acde45521b8c1fe07c762537a.tar.gz |
Add copy_directory rule (#366)
Diffstat (limited to 'tests/copy_directory')
-rw-r--r-- | tests/copy_directory/BUILD.bazel | 44 | ||||
-rwxr-xr-x | tests/copy_directory/copy_directory_tests.sh | 81 | ||||
-rw-r--r-- | tests/copy_directory/dir_with_subdir/a | 1 | ||||
-rw-r--r-- | tests/copy_directory/dir_with_subdir/b | 1 | ||||
-rw-r--r-- | tests/copy_directory/dir_with_subdir/subdir/c | 1 | ||||
-rw-r--r-- | tests/copy_directory/dir_with_symlink/file | 1 | ||||
l--------- | tests/copy_directory/dir_with_symlink/symlink | 1 |
7 files changed, 130 insertions, 0 deletions
diff --git a/tests/copy_directory/BUILD.bazel b/tests/copy_directory/BUILD.bazel new file mode 100644 index 0000000..2c72ab9 --- /dev/null +++ b/tests/copy_directory/BUILD.bazel @@ -0,0 +1,44 @@ +# This package aids testing the 'copy_directory' rule. + +load("//rules:copy_directory.bzl", "copy_directory") + +licenses(["notice"]) + +package(default_testonly = 1) + +# Copy of directory containing files a and b, and a subdir containing c +copy_directory( + name = "copy_of_dir_with_subdir", + src = "dir_with_subdir", + out = "dir_copy", +) + +genrule( + name = "empty_directory", + outs = ["empty_dir"], + cmd = "mkdir $@", +) + +copy_directory( + name = "copy_of_empty_dir", + src = "empty_dir", + out = "empty_dir_copy", +) + +copy_directory( + name = "copy_of_dir_with_symlink", + src = "dir_with_symlink", + out = "dir_with_symlink_copy", +) + +sh_test( + name = "copy_directory_tests", + srcs = ["copy_directory_tests.sh"], + data = [ + ":copy_of_dir_with_subdir", + ":copy_of_dir_with_symlink", + ":copy_of_empty_dir", + "//tests:unittest.bash", + ], + deps = ["@bazel_tools//tools/bash/runfiles"], +) diff --git a/tests/copy_directory/copy_directory_tests.sh b/tests/copy_directory/copy_directory_tests.sh new file mode 100755 index 0000000..37fbb09 --- /dev/null +++ b/tests/copy_directory/copy_directory_tests.sh @@ -0,0 +1,81 @@ +#!/usr/bin/env bash + +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# --- begin runfiles.bash initialization --- +# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). +set -euo pipefail +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 --- + +source "$(rlocation bazel_skylib/tests/unittest.bash)" \ + || { echo "Could not source bazel_skylib/tests/unittest.bash" >&2; exit 1; } + +function test_copy_dir_with_subdir__copies_a() { + cat "$(rlocation bazel_skylib/tests/copy_directory/dir_copy)/a" >"$TEST_log" + expect_log '^foo$' +} + +function test_copy_dir_with_subdir__copies_b() { + cat "$(rlocation bazel_skylib/tests/copy_directory/dir_copy)/b" >"$TEST_log" + expect_log '^bar$' +} + +function test_copy_dir_with_subdir__copies_c() { + cat "$(rlocation bazel_skylib/tests/copy_directory/dir_copy)/subdir/c" >"$TEST_log" + expect_log '^moocow$' +} + +function test_copy_dir_with_subdir__correct_filecounts() { + local -r dir_filecount=$(ls "$(rlocation bazel_skylib/tests/copy_directory/dir_copy)" | wc -l) + assert_equals $dir_filecount 3 + local -r subdir_filecount=$(ls "$(rlocation bazel_skylib/tests/copy_directory/dir_copy)/subdir" | wc -l) + assert_equals $subdir_filecount 1 +} + +function test_copy_empty_dir() { + local -r filecount=$(ls "$(rlocation bazel_skylib/tests/copy_directory/empty_dir_copy)" | wc -l) + assert_equals $filecount 0 +} + +function test_copy_dir_with_symlink__copies_file() { + cat "$(rlocation bazel_skylib/tests/copy_directory/dir_with_symlink_copy)/file" >"$TEST_log" + expect_log '^foo$' +} + +function test_copy_dir_with_symlink__copies_symlink() { + cat "$(rlocation bazel_skylib/tests/copy_directory/dir_with_symlink_copy)/symlink" >"$TEST_log" + expect_log '^foo$' +} + + +run_suite "copy_directory test suite" diff --git a/tests/copy_directory/dir_with_subdir/a b/tests/copy_directory/dir_with_subdir/a new file mode 100644 index 0000000..1910281 --- /dev/null +++ b/tests/copy_directory/dir_with_subdir/a @@ -0,0 +1 @@ +foo
\ No newline at end of file diff --git a/tests/copy_directory/dir_with_subdir/b b/tests/copy_directory/dir_with_subdir/b new file mode 100644 index 0000000..ba0e162 --- /dev/null +++ b/tests/copy_directory/dir_with_subdir/b @@ -0,0 +1 @@ +bar
\ No newline at end of file diff --git a/tests/copy_directory/dir_with_subdir/subdir/c b/tests/copy_directory/dir_with_subdir/subdir/c new file mode 100644 index 0000000..062f177 --- /dev/null +++ b/tests/copy_directory/dir_with_subdir/subdir/c @@ -0,0 +1 @@ +moocow
\ No newline at end of file diff --git a/tests/copy_directory/dir_with_symlink/file b/tests/copy_directory/dir_with_symlink/file new file mode 100644 index 0000000..1910281 --- /dev/null +++ b/tests/copy_directory/dir_with_symlink/file @@ -0,0 +1 @@ +foo
\ No newline at end of file diff --git a/tests/copy_directory/dir_with_symlink/symlink b/tests/copy_directory/dir_with_symlink/symlink new file mode 120000 index 0000000..7b22242 --- /dev/null +++ b/tests/copy_directory/dir_with_symlink/symlink @@ -0,0 +1 @@ +./file
\ No newline at end of file |