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

More robust comment parsing #2332

Merged
merged 17 commits into from
Jul 8, 2022
Merged

More robust comment parsing #2332

merged 17 commits into from
Jul 8, 2022

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jul 5, 2022

fixes #2170

I haven't ported the entire test suite yet. Once we've done that, I will remove the old parsing system (or in fact, turn them into errors so that accidental usage of old-style comments will be detected)

@bors
Copy link
Contributor

bors commented Jul 5, 2022

☔ The latest upstream changes (presumably #2335) made this pull request unmergeable. Please resolve the merge conflicts.

miri Outdated Show resolved Hide resolved
ui_test/src/comments.rs Outdated Show resolved Hide resolved
ui_test/src/comments.rs Outdated Show resolved Hide resolved

/// Parse comments in `content`.
/// `path` is only used to emit diagnostics if parsing fails.
pub(crate) fn parse(path: &Path, content: &str) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to keep maintaining all this code.

(or in fact, turn them into errors so that accidental usage of old-style comments will be detected)

If you want to do that, please just use a single regex like // *(compiler?-flag|only-|ignore-) and warn/error when that matches. We don't need the full parser for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but I want to keep it around until we ported all the tests and only remove it then

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the issue with just porting them all now?

I don't like having so many dead code paths here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was assuming it's just a fairly simple global search-and-replace to add all those @.

But if you prefer I can also live with doing this in steps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly because it's very conflict prone and I'd have to rebase too often ^^

ui_test/src/comments.rs Outdated Show resolved Hide resolved
ui_test/src/comments.rs Outdated Show resolved Hide resolved
this

if let Some(s) = command.strip_prefix("only-") {
self.only.push(Condition::parse(s));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that Condition::parse can panic... now that you have error reporting here it'd be nice to also use that for incorrect conditions.

For proper reliable parsing, I think ignore-windows should become ignore-target-windows, otherwise we have the same problem again of having some special commands (ignore-debug, ignore-32bit) and then silently falling back to another way of interpreting the command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. For minimal churn I want to change as little as possible until we rip out the old logic and then improve the parser step by step.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 6, 2022

The new attribute parsing errors now look like

tests/fail/memleak.rs ... ok
Error: 
   0: tests/fail/memleak_rc.rs:3: failed to parse annotation
   1: unknown command normalasdfize-stderr-test

Location:
   ui_test/src/comments.rs:248

(plus some terminal coloring for readability)

@RalfJung
Copy link
Member

RalfJung commented Jul 6, 2022

The new attribute parsing errors now look like

tests/fail/memleak.rs ... ok
Error: 
   0: tests/fail/memleak_rc.rs:3: failed to parse annotation
   1: unknown command normalasdfize-stderr-test

Location:
   ui_test/src/comments.rs:248

(plus some terminal coloring for readability)

I am confused by that error. There are two locations there, which one is it at? And why does error 0 have a filename and line but error 1 not?

ui_test/src/comments.rs Outdated Show resolved Hide resolved
ui_test/src/comments.rs Show resolved Hide resolved
ui_test/src/comments.rs Show resolved Hide resolved
ui_test/src/comments.rs Outdated Show resolved Hide resolved
ui_test/src/comments.rs Outdated Show resolved Hide resolved
ui_test/src/tests.rs Show resolved Hide resolved
@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 7, 2022

I am confused by that error. There are two locations there, which one is it at? And why does error 0 have a filename and line but error 1 not?

the "Location" is the place in ui testing where the error was raised

the list is a sort of backtrace of information. This helps avoid passing down all the information, as each bubbling up can attach information in the failure case instead of pushing information in

@RalfJung
Copy link
Member

RalfJung commented Jul 7, 2022

the "Location" is the place in ui testing where the error was raised

Okay. For user-visible errors I don't think we want to show any of our internal source code locations by default. IMO basically we should either panic ("we don't care, just report the error somehow") or do it properly... going half-way doesn't seem worth the effort?
Also that doesn't explain why only one of the errors points at a test file+line.

@bors
Copy link
Contributor

bors commented Jul 8, 2022

☔ The latest upstream changes (presumably #2345) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 8, 2022

Okay. For user-visible errors I don't think we want to show any of our internal source code locations by default. IMO basically we should either panic ("we don't care, just report the error somehow") or do it properly... going half-way doesn't seem worth the effort?

done, we show a message about RUST_BACKTRACE, but nothing else by default

Also that doesn't explain why only one of the errors points at a test file+line.

it's not multiple errors. this is the "spantrace" for a single error. So whenever we call a function, we can attach some information to the failure-path on that function call. To showcase this, I only added information to the parse_checked_line call (adding the file + line information). if we replace more ? with

.map_err(|err| err.wrap_err(format!("your info goes here")))?

then we get more entries in that list, telling us exactly how we got to the error.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 8, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jul 8, 2022

📌 Commit 6e10661 has been approved by oli-obk

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 8, 2022

⌛ Testing commit 6e10661 with merge 7a6a812...

@bors
Copy link
Contributor

bors commented Jul 8, 2022

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 7a6a812 to master...

@bors bors merged commit 7a6a812 into master Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ui_test: more robust comment parsing
3 participants