Skip to content

Commit f459c08

Browse files
JakobDegenfacebook-github-bot
authored andcommitted
tests: Move test_build_configured to core
Summary: And isolate it at the same time Reviewed By: IanChilds Differential Revision: D63972124 fbshipit-source-id: d7a24e28926ad5b9042a2324459e04e81ea8ee6f
1 parent 37c2413 commit f459c08

File tree

8 files changed

+104
-110
lines changed

8 files changed

+104
-110
lines changed

tests/core/build/BUCK

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ buck2_e2e_test(
2222
serialize_test_cases = False,
2323
)
2424

25+
buck2_e2e_test(
26+
name = "test_build_configured",
27+
srcs = ["test_build_configured.py"],
28+
data_dir = "test_build_configured_data",
29+
)
30+
2531
buck2_e2e_test(
2632
name = "test_plugins",
2733
srcs = ["test_plugins.py"],
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under both the MIT license found in the
4+
# LICENSE-MIT file in the root directory of this source tree and the Apache
5+
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
6+
# of this source tree.
7+
8+
# pyre-strict
9+
10+
11+
import json
12+
import re
13+
import typing
14+
15+
from buck2.tests.e2e_util.api.buck import Buck
16+
from buck2.tests.e2e_util.asserts import expect_failure
17+
from buck2.tests.e2e_util.buck_workspace import buck_test
18+
19+
20+
# Obtain hashes of `<astrologer>` and `<vagabond>` configurations.
21+
async def _obtain_cfg_hashes(buck: Buck) -> typing.Tuple[str, str]:
22+
result = await buck.cquery(
23+
"root//:simple",
24+
"--target-universe",
25+
"root//:universe",
26+
)
27+
[astrologer, vagabond] = result.stdout.splitlines()
28+
assert astrologer.startswith("root//:simple (<astrologer>#")
29+
assert vagabond.startswith("root//:simple (<vagabond>#")
30+
astrologer_hash = re.sub(r".*#(.*)\)", r"\1", astrologer)
31+
vagabond_hash = re.sub(r".*#(.*)\)", r"\1", vagabond)
32+
assert re.fullmatch("[0-9a-f]{16}", astrologer_hash), astrologer
33+
assert re.fullmatch("[0-9a-f]{16}", vagabond_hash), vagabond
34+
return (astrologer_hash, vagabond_hash)
35+
36+
37+
@buck_test()
38+
async def test_build_configured_full_configuration(buck: Buck) -> None:
39+
(astrologer_hash, _) = await _obtain_cfg_hashes(buck)
40+
41+
result = await buck.build(
42+
f"root//:simple (<astrologer>#{astrologer_hash})",
43+
"--target-universe",
44+
"root//:universe",
45+
)
46+
out = result.get_build_report().output_for_target("root//:simple").read_text()
47+
assert f"$$$root//:simple (<astrologer>#{astrologer_hash})$$$" == out
48+
49+
50+
@buck_test()
51+
async def test_build_configured_no_hash(buck: Buck) -> None:
52+
(_, vagabond_hash) = await _obtain_cfg_hashes(buck)
53+
result = await buck.build(
54+
"root//:simple (<vagabond>)",
55+
"--target-universe",
56+
"root//:universe",
57+
)
58+
out = result.get_build_report().output_for_target("root//:simple").read_text()
59+
assert f"$$$root//:simple (<vagabond>#{vagabond_hash})$$$" == out
60+
61+
62+
@buck_test()
63+
async def test_build_configured_wrong_hash(buck: Buck) -> None:
64+
result = await buck.build(
65+
"root//:simple (<vagabond>#0123456789abcdef)",
66+
"--target-universe",
67+
"root//:universe",
68+
)
69+
# TODO(nga): this should either fail or emit a warning.
70+
assert "root//:simple" not in json.loads(result.stdout)["results"]
71+
72+
73+
@buck_test()
74+
async def test_build_configured_no_universe(buck: Buck) -> None:
75+
await expect_failure(
76+
buck.build(
77+
"root//:simple (<vagabond>)",
78+
),
79+
stderr_regex="Targets with explicit configuration can only be built when the",
80+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[cells]
2+
root = .
3+
nano_prelude = nano_prelude
4+
5+
[cell_aliases]
6+
prelude = nano_prelude
7+
8+
[external_cells]
9+
nano_prelude = bundled
10+
11+
[buildfile]
12+
name = TARGETS.fixture

tests/core/build/test_build_configured_data/.buckroot

Whitespace-only changes.

tests/e2e/build/test_build_configured_data/BUCK.v2 renamed to tests/core/build/test_build_configured_data/TARGETS.fixture

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ load(":defs.bzl", "simple", "universe")
33
# Write the configuration label to the default output.
44
simple(
55
name = "simple",
6+
default_target_platform = ":default_plat",
67
)
78

89
# Build nothing, but depend on two `:simple` targets in different configurations.
910
universe(
1011
name = "universe",
1112
split_dep = ":simple",
13+
default_target_platform = ":default_plat",
14+
)
15+
16+
platform(
17+
name = "default_plat",
1218
)

tests/e2e/build/BUCK

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ buck2_e2e_test(
2525
serialize_test_cases = False,
2626
)
2727

28-
buck2_e2e_test(
29-
name = "test_build_configured",
30-
srcs = ["test_build_configured.py"],
31-
)
32-
3328
buck2_e2e_test(
3429
name = "test_build_inplace",
3530
srcs = ["test_build_inplace.py"],

tests/e2e/build/test_build_configured.py

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)