Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui_test: provide a way to match against labels #2483

Open
RalfJung opened this issue Aug 13, 2022 · 3 comments
Open

ui_test: provide a way to match against labels #2483

RalfJung opened this issue Aug 13, 2022 · 3 comments
Labels
A-tests Area: affects our test suite or CI C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement

Comments

@RalfJung
Copy link
Member

With a stderr like this

full stderr:
error[E0080]: evaluation of constant value failed
  --> tests/fail/const-ub-checks.rs:6:9
   |
LL |         ptr.read();
   |         ^^^^^^^^^^ accessing memory with alignment 1, but alignment 4 is required

I'd like to be able to match not only against "evaluation of constant value failed", but also against "accessing memory with alignment 1, but alignment 4 is required", to ensure that it actually detected the right kind of problem.

This is a prerequisite for #2200.

@RalfJung RalfJung added C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement A-tests Area: affects our test suite or CI labels Aug 13, 2022
@RalfJung
Copy link
Member Author

The JSON from that message looks like this:

{
  "message": "evaluation of constant value failed",
  "code": {
    "code": "E0080",
    "explanation": "A constant value failed to get evaluated.\n\nErroneous code example:\n\n```compile_fail,E0080\nenum Enum {\n    X = (1 << 500),\n    Y = (1 / 0),\n}\n```\n\nThis error indicates that the compiler was unable to sensibly evaluate a\nconstant expression that had to be evaluated. Attempting to divide by 0\nor causing an integer overflow are two ways to induce this error.\n\nEnsure that the expressions given can be evaluated as the desired integer type.\n\nSee the [Custom Discriminants][custom-discriminants] section of the Reference\nfor more information about setting custom integer types on fieldless enums\nusing the [`repr` attribute][repr-attribute].\n\n[custom-discriminants]: https://doc.rust-lang.org/reference/items/enumerations.html#custom-discriminant-values-for-field-less-enumerations\n[repr-attribute]: https://doc.rust-lang.org/reference/type-layout.html#reprc-enums\n"
  },
  "level": "error",
  "spans": [
    {
      "file_name": "tests/fail/const-ub-checks.rs",
      "byte_start": 145,
      "byte_end": 155,
      "line_start": 6,
      "line_end": 6,
      "column_start": 9,
      "column_end": 19,
      "is_primary": true,
      "text": [
        {
          "text": "        ptr.read(); //~ERROR: evaluation of constant value failed",
          "highlight_start": 9,
          "highlight_end": 19
        }
      ],
      "label": "accessing memory with alignment 1, but alignment 4 is required",
      "suggested_replacement": null,
      "suggestion_applicability": null,
      "expansion": null
    }
  ],
  "children": [],
  "rendered": "error[E0080]: evaluation of constant value failed\n --> tests/fail/const-ub-checks.rs:6:9\n  |\n6 |         ptr.read(); //~ERROR: evaluation of constant value failed\n  |         ^^^^^^^^^^ accessing memory with alignment 1, but alignment 4 is required\n\n"
}

@oli-obk
Copy link
Contributor

oli-obk commented Aug 22, 2022

should we just try the main message first and then the label, or should we explicitly opt into checking the label?

@RalfJung
Copy link
Member Author

I think explicit is better than implicit for a test suite, so I was thinking of something like //~LABEL: ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tests Area: affects our test suite or CI C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement
Projects
None yet
Development

No branches or pull requests

2 participants