2021-11-17 05:30:32 +00:00
|
|
|
"tests for copy_to_directory"
|
|
|
|
|
2021-12-21 22:18:34 +00:00
|
|
|
load("//lib:diff_test.bzl", "diff_test")
|
2022-04-05 20:38:54 +00:00
|
|
|
load("//lib:copy_directory.bzl", "copy_directory")
|
2021-11-17 05:30:32 +00:00
|
|
|
load("//lib:copy_to_directory.bzl", "copy_to_directory")
|
2022-03-04 00:40:32 +00:00
|
|
|
load("//lib:directory_path.bzl", "make_directory_paths")
|
2021-11-17 05:30:32 +00:00
|
|
|
|
|
|
|
[
|
2022-04-05 20:38:54 +00:00
|
|
|
copy_directory(
|
2021-11-17 05:30:32 +00:00
|
|
|
name = "%s" % d,
|
|
|
|
src = "dir_%s" % d,
|
|
|
|
out = "%s" % d,
|
|
|
|
)
|
|
|
|
for d in [
|
|
|
|
"a",
|
|
|
|
"b",
|
|
|
|
"expected_1",
|
|
|
|
"expected_2",
|
|
|
|
"expected_3",
|
|
|
|
"expected_4",
|
|
|
|
"expected_5",
|
2021-12-16 21:52:29 +00:00
|
|
|
"expected_7",
|
|
|
|
"expected_8",
|
2022-03-04 00:40:32 +00:00
|
|
|
"expected_9",
|
2021-11-17 05:30:32 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
case_srcs = [
|
|
|
|
":a",
|
|
|
|
":b",
|
|
|
|
":c",
|
|
|
|
":d",
|
|
|
|
":e/e",
|
|
|
|
":e/e2",
|
|
|
|
"//lib/tests/copy_to_directory/f/f2:f",
|
|
|
|
"//lib/tests/copy_to_directory/f/f2:f2",
|
|
|
|
"@external_test_repo//:test_a",
|
|
|
|
"@external_test_repo//:test_b",
|
|
|
|
"@external_test_repo//:test_c",
|
|
|
|
"@external_test_repo//:test_d",
|
|
|
|
]
|
|
|
|
|
2021-12-16 21:52:29 +00:00
|
|
|
# Case 1: default settings (with external repo)
|
2021-11-17 05:30:32 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_1",
|
|
|
|
srcs = case_srcs,
|
2021-12-16 21:52:29 +00:00
|
|
|
include_external_repositories = ["external_test_repo"],
|
2021-11-17 05:30:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_1_test",
|
|
|
|
file1 = "case_1",
|
|
|
|
file2 = ":expected_1",
|
|
|
|
)
|
|
|
|
|
2021-12-16 21:52:29 +00:00
|
|
|
# Case 2: replace_prefixes (with external repo)
|
2021-11-17 05:30:32 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_2",
|
|
|
|
srcs = case_srcs,
|
2021-12-16 21:52:29 +00:00
|
|
|
include_external_repositories = ["external_test_repo"],
|
2021-11-17 05:30:32 +00:00
|
|
|
replace_prefixes = {
|
|
|
|
# merge a, b, c, d into a new/abcd dest folder
|
|
|
|
"a": "new/abcd",
|
|
|
|
"b": "//new///abcd////",
|
|
|
|
"c": "new/abcd/c",
|
|
|
|
"d": "////new/////abcd////d",
|
|
|
|
# put e into new/e except for e/e2 which goes into new/e2
|
|
|
|
"e": "new/e",
|
|
|
|
"e/e2": "new/e2/e2",
|
|
|
|
# f/f2/f => new/ff and f/f2/f2 => new/f2/f2
|
|
|
|
"f/f2/": "////new/////f",
|
|
|
|
"f/f2/f2": "////new/////f2///f2",
|
|
|
|
# flatten test_a & test_b to the root
|
|
|
|
"test_a": "",
|
|
|
|
"test_b": "",
|
|
|
|
# some paths that won't match
|
|
|
|
"a/": "wont_match_a_is_terminal_path",
|
|
|
|
"a/a2": "wont_match_since_a2_is_in_a_tree_artifact",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_2_test",
|
|
|
|
file1 = "case_2",
|
|
|
|
file2 = ":expected_2",
|
|
|
|
)
|
|
|
|
|
2021-12-16 21:52:29 +00:00
|
|
|
# Case 3: no root_paths (with external repo)
|
2021-11-17 05:30:32 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_3",
|
|
|
|
srcs = case_srcs,
|
2021-12-16 21:52:29 +00:00
|
|
|
include_external_repositories = ["external_test_repo"],
|
2021-11-17 05:30:32 +00:00
|
|
|
root_paths = [],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_3_test",
|
|
|
|
file1 = "case_3",
|
|
|
|
file2 = ":expected_3",
|
|
|
|
)
|
|
|
|
|
2021-12-16 21:52:29 +00:00
|
|
|
# Case 4: no root_paths + replace_prefixes (with external repo)
|
2021-11-17 05:30:32 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_4",
|
|
|
|
srcs = case_srcs,
|
2021-12-16 21:52:29 +00:00
|
|
|
include_external_repositories = ["external_test_repo"],
|
2021-11-17 05:30:32 +00:00
|
|
|
replace_prefixes = {
|
|
|
|
# strip lib/tests from paths
|
|
|
|
"lib/tests/": "",
|
|
|
|
# except for a few which should match due to longest match wins
|
|
|
|
"lib/tests/copy_to_directory/a": "lib/other/copy_to_directory",
|
|
|
|
"lib/tests/copy_to_directory/c": "lib/other/copy_to_directory/c",
|
|
|
|
},
|
|
|
|
root_paths = [],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_4_test",
|
|
|
|
file1 = "case_4",
|
|
|
|
file2 = ":expected_4",
|
|
|
|
)
|
|
|
|
|
2021-12-16 21:52:29 +00:00
|
|
|
# Case 5: custom root packages (with external repo)
|
2021-11-17 05:30:32 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_5",
|
|
|
|
srcs = case_srcs,
|
2021-12-16 21:52:29 +00:00
|
|
|
include_external_repositories = ["external_test_repo"],
|
2021-11-17 05:30:32 +00:00
|
|
|
root_paths = [
|
|
|
|
package_name(),
|
|
|
|
"%s/e" % package_name(),
|
|
|
|
"%s/f" % package_name(),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_5_test",
|
|
|
|
file1 = "case_5",
|
|
|
|
file2 = ":expected_5",
|
|
|
|
)
|
2021-12-02 01:09:48 +00:00
|
|
|
|
|
|
|
# Case 6: directory used in a test's runfiles
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_6",
|
|
|
|
srcs = case_srcs,
|
2021-12-16 21:52:29 +00:00
|
|
|
include_external_repositories = ["external_test_repo"],
|
2021-12-02 01:09:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
sh_test(
|
|
|
|
name = "case_6_test",
|
|
|
|
srcs = ["case6.sh"],
|
|
|
|
data = ["case_6"],
|
|
|
|
)
|
2021-12-16 21:52:29 +00:00
|
|
|
|
|
|
|
# Case 7: default settings
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_7",
|
|
|
|
srcs = case_srcs,
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_7_test",
|
|
|
|
file1 = "case_7",
|
|
|
|
file2 = ":expected_7",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Case 8: exclude prefixes
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_8",
|
|
|
|
srcs = case_srcs,
|
|
|
|
exclude_prefixes = [
|
|
|
|
# exclude a & b
|
|
|
|
"a",
|
|
|
|
"b",
|
|
|
|
# this partial match should exclude all of e
|
|
|
|
"e/e",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2022-03-04 00:40:32 +00:00
|
|
|
# Case 9: directory_path srcs & replace_prefixes (with external repo)
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_9",
|
|
|
|
srcs = [
|
|
|
|
":c",
|
|
|
|
":d",
|
|
|
|
":e/e",
|
|
|
|
":e/e2",
|
|
|
|
"//lib/tests/copy_to_directory/f/f2",
|
|
|
|
"//lib/tests/copy_to_directory/f/f2:f",
|
|
|
|
"@external_test_repo//:test_c",
|
|
|
|
"@external_test_repo//:test_d",
|
|
|
|
] + make_directory_paths(
|
|
|
|
"case_9_srcs",
|
|
|
|
{
|
|
|
|
":a": "a",
|
|
|
|
":b": [
|
|
|
|
"b",
|
|
|
|
"b2",
|
|
|
|
],
|
|
|
|
"@external_test_repo//:test_a": "test_a",
|
|
|
|
"@external_test_repo//:test_b": "test_b",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
include_external_repositories = ["external_test_repo"],
|
|
|
|
replace_prefixes = {
|
|
|
|
# merge a, b, c, d into a new/abcd dest folder
|
|
|
|
"a/a": "new/abcd/a",
|
|
|
|
"b": "//new///abcd////",
|
|
|
|
"c": "new/abcd/c",
|
|
|
|
"d": "////new/////abcd////d",
|
|
|
|
# put e into new/e except for e/e2 which goes into new/e2
|
|
|
|
"e": "new/e",
|
|
|
|
"e/e2": "new/e2/e2",
|
|
|
|
# f/f2/f => new/ff and f/f2/f2 => new/f2/f2
|
|
|
|
"f/f2/": "////new/////f",
|
|
|
|
"f/f2/f2": "////new/////f2///f2",
|
|
|
|
# flatten test_a & test_b to the root
|
|
|
|
"test_a": "",
|
|
|
|
"test_b": "",
|
|
|
|
# some paths that won't match
|
|
|
|
"a/a2": "wont_match_since_a2_is_not_included_in_the_directory_path_in_srcs",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_9_test",
|
|
|
|
file1 = "case_9",
|
|
|
|
file2 = ":expected_9",
|
|
|
|
)
|
|
|
|
|
2021-12-16 21:52:29 +00:00
|
|
|
diff_test(
|
|
|
|
name = "case_8_test",
|
|
|
|
file1 = "case_8",
|
|
|
|
file2 = ":expected_8",
|
|
|
|
)
|