Skip to content

Commit

Permalink
tests: Move test_build_configured to core
Browse files Browse the repository at this point in the history
Summary: And isolate it at the same time

Reviewed By: IanChilds

Differential Revision: D63972124

fbshipit-source-id: d7a24e28926ad5b9042a2324459e04e81ea8ee6f
  • Loading branch information
JakobDegen authored and facebook-github-bot committed Oct 7, 2024
1 parent 37c2413 commit f459c08
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 110 deletions.
6 changes: 6 additions & 0 deletions tests/core/build/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ buck2_e2e_test(
serialize_test_cases = False,
)

buck2_e2e_test(
name = "test_build_configured",
srcs = ["test_build_configured.py"],
data_dir = "test_build_configured_data",
)

buck2_e2e_test(
name = "test_plugins",
srcs = ["test_plugins.py"],
Expand Down
80 changes: 80 additions & 0 deletions tests/core/build/test_build_configured.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.

# pyre-strict


import json
import re
import typing

from buck2.tests.e2e_util.api.buck import Buck
from buck2.tests.e2e_util.asserts import expect_failure
from buck2.tests.e2e_util.buck_workspace import buck_test


# Obtain hashes of `<astrologer>` and `<vagabond>` configurations.
async def _obtain_cfg_hashes(buck: Buck) -> typing.Tuple[str, str]:
result = await buck.cquery(
"root//:simple",
"--target-universe",
"root//:universe",
)
[astrologer, vagabond] = result.stdout.splitlines()
assert astrologer.startswith("root//:simple (<astrologer>#")
assert vagabond.startswith("root//:simple (<vagabond>#")
astrologer_hash = re.sub(r".*#(.*)\)", r"\1", astrologer)
vagabond_hash = re.sub(r".*#(.*)\)", r"\1", vagabond)
assert re.fullmatch("[0-9a-f]{16}", astrologer_hash), astrologer
assert re.fullmatch("[0-9a-f]{16}", vagabond_hash), vagabond
return (astrologer_hash, vagabond_hash)


@buck_test()
async def test_build_configured_full_configuration(buck: Buck) -> None:
(astrologer_hash, _) = await _obtain_cfg_hashes(buck)

result = await buck.build(
f"root//:simple (<astrologer>#{astrologer_hash})",
"--target-universe",
"root//:universe",
)
out = result.get_build_report().output_for_target("root//:simple").read_text()
assert f"$$$root//:simple (<astrologer>#{astrologer_hash})$$$" == out


@buck_test()
async def test_build_configured_no_hash(buck: Buck) -> None:
(_, vagabond_hash) = await _obtain_cfg_hashes(buck)
result = await buck.build(
"root//:simple (<vagabond>)",
"--target-universe",
"root//:universe",
)
out = result.get_build_report().output_for_target("root//:simple").read_text()
assert f"$$$root//:simple (<vagabond>#{vagabond_hash})$$$" == out


@buck_test()
async def test_build_configured_wrong_hash(buck: Buck) -> None:
result = await buck.build(
"root//:simple (<vagabond>#0123456789abcdef)",
"--target-universe",
"root//:universe",
)
# TODO(nga): this should either fail or emit a warning.
assert "root//:simple" not in json.loads(result.stdout)["results"]


@buck_test()
async def test_build_configured_no_universe(buck: Buck) -> None:
await expect_failure(
buck.build(
"root//:simple (<vagabond>)",
),
stderr_regex="Targets with explicit configuration can only be built when the",
)
12 changes: 12 additions & 0 deletions tests/core/build/test_build_configured_data/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[cells]
root = .
nano_prelude = nano_prelude

[cell_aliases]
prelude = nano_prelude

[external_cells]
nano_prelude = bundled

[buildfile]
name = TARGETS.fixture
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ load(":defs.bzl", "simple", "universe")
# Write the configuration label to the default output.
simple(
name = "simple",
default_target_platform = ":default_plat",
)

# Build nothing, but depend on two `:simple` targets in different configurations.
universe(
name = "universe",
split_dep = ":simple",
default_target_platform = ":default_plat",
)

platform(
name = "default_plat",
)
5 changes: 0 additions & 5 deletions tests/e2e/build/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ buck2_e2e_test(
serialize_test_cases = False,
)

buck2_e2e_test(
name = "test_build_configured",
srcs = ["test_build_configured.py"],
)

buck2_e2e_test(
name = "test_build_inplace",
srcs = ["test_build_inplace.py"],
Expand Down
105 changes: 0 additions & 105 deletions tests/e2e/build/test_build_configured.py

This file was deleted.

0 comments on commit f459c08

Please sign in to comment.