Skip to content

Commit

Permalink
patterns: Add test for attrocious default coercion error
Browse files Browse the repository at this point in the history
Summary:
The things you find when you start looking, incredible

(only a little bit sorry about the diff title)

Reviewed By: IanChilds

Differential Revision: D69713854

fbshipit-source-id: 495afee7364c0ea46bf1e2de40ab629dc19d0ef9
  • Loading branch information
JakobDegen authored and facebook-github-bot committed Feb 23, 2025
1 parent 0780249 commit 7d4cd43
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/core/interpreter/test_attr_default_coercion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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


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
from buck2.tests.e2e_util.helper.golden import golden


@buck_test()
async def test_default_not_a_label(buck: Buck) -> None:
res = await expect_failure(buck.uquery("root//:", "--console=none", "-v0"))
golden(
output=res.stderr,
rel_path="golden/default_not_a_label.golden.stderr",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[cells]
root = .

[buildfile]
name = TARGETS.fixture
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load(":error_rule.bzl", "error_rule")

error_rule(
name = "foo",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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.

def _transition_impl(**_kwargs):
pass

_transition = transition(
impl = _transition_impl,
refs = {},
)

def _impl():
pass

error_rule = rule(
impl = _impl,
attrs = {
"someattr": attrs.transition_dep(default = "notaproperlabel", cfg = _transition),
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is @generated, regenerate by re-running test with `-- --env BUCK2_UPDATE_GOLDEN=1` appended to the test command

Command failed:
Error evaluating expression:
root//:
^-----^


Caused by:
0: From load at TARGETS.fixture:1
1: Error evaluating module: `root//error_rule.bzl`
2: Traceback (most recent call last):
* error_rule.bzl:22, in <module>
"someattr": attrs.transition_dep(default = "notaproperlabel", cfg = _transiti...
error: Type of parameters mismatch
--> error_rule.bzl:22:21
|
22 | "someattr": attrs.transition_dep(default = "notaproperlabel", cfg = _transition),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|

0 comments on commit 7d4cd43

Please sign in to comment.