Repository navigation
Conversation
|
Some changes occurred in src/tools/compiletest cc @jieyouxu |
There was a problem hiding this comment.
I'm sure about all changes except for the last commit ("auto-trim directive payload") because I don't know if we intentionally don't trim the payload of {cdb,lldb,gdb}-{command,check,repr}.
Please let me know if trimming there would be incorrect. I don't have access to a Windows machine to test CDB; I saw that some cdb-check directives had "intentionally indented" payloads...
I've g2g that's why I can't spend time anymore researching the exact format of debugger commands. Might do so some other time.
There was a problem hiding this comment.
Huh, interesting. I will double-check.
There was a problem hiding this comment.
Okay I checked again, this does not matter for any of the debuggers.
The cdb ones specically have indent whitespace because that's literally what cdb outputs. So the expected output is actually copied verbatim. This is convenient to help you diff if a newer cdb changed output since you don't have to account for the whitespaces 😓
|
These refactorings aren't the most exciting, I wanted to do more but ran out of time last Sunday as I had to dip. One "large" thing I want to do eventually is to avoid reparsing directives. AFAICT for the UI test suite, we always parse directives twice, first when "constructing" the test ( For that I could be mistaken but for the rustdoc-html test suite it seemed like we parse directives 4 times. Needs investigation. Once we only parse directives once, it should be easier to make errors in |
There was a problem hiding this comment.
I think now
aux-build,aux-binparse_aux_crate,parse_proc_macroserror-pattern/regex-error-pattern(inruntestnot here)
also no longer need the trims.
| /// Invariant: `self.raw_directive.starts_with(self.name)` | ||
| pub(crate) name: &'a str, | ||
|
|
||
| /// The (whitespace-trimmed) playload of the directive. |
|
|
||
| let extra_directives = match config.mode { | ||
| // Inject certain directives depending on the test mode, so test writers don't need to specify | ||
| // then manually in every test file. |
There was a problem hiding this comment.
Nit: I think you meant "them" here
| impl<'ln> DirectiveLine<'ln> { | ||
| pub(crate) fn applies_to_test_revision(&self, test_revision: Option<&str>) -> bool { | ||
| self.revision.is_none() || self.revision == test_revision | ||
| pub(crate) fn synthetic(name: &'static str, file_path: &'ln Utf8Path) -> Self { |
There was a problem hiding this comment.
NB: I need to think about this later, it feels quite strange using synthetic directives 🤔
There was a problem hiding this comment.
Ideally we wouldn't have them. My change is just a stop-gap and removes only a single layer of the onion by no longer passing them to line_directive. This change is part of my aforementioned goal to call line_directive only once per test file -- replacing line_directive with synthetic in iter_directive is one tiny step towards it.
The real fix would be to look at what the respective directive handlers are doing and to call the handler directly in the relevant places (or rather not the "handler" itself but its body / the underlying logic, extracted into separate function that doesn't need to know anything about directives).
| let mut kind: fn(_) -> _ = DirectivePayload::Value; | ||
| let (name, payload) = directive | ||
| .split_once(|char| { | ||
| match char { | ||
| ' ' => kind = DirectivePayload::Remark, | ||
| ':' => {} | ||
| _ => return false, | ||
| }; | ||
| true | ||
| }) | ||
| .map(|(name, payload)| (name, Some(kind(payload.trim())))) | ||
| .unwrap_or((directive, None)); |
There was a problem hiding this comment.
Nit (non-blocking): this reads a little bit clever, maybe .find([' ', ':'])? But also doesn't really matter.
There was a problem hiding this comment.
No, you're right, it's a bit obfuscated.
| /// The playload of the directive. | ||
| /// | ||
| /// If the payload was separated using a colon (`:`) it will get represented as a | ||
| /// [`DirectivePayload::Value`]. If the payload was separated using a space, it will be | ||
| /// represented as a [`DirectivePayload::Remark`]. If the directive doesn't contain either colon | ||
| /// or space, the payload will be `None`. | ||
| pub(crate) payload: Option<DirectivePayload<'a>>, |
There was a problem hiding this comment.
I was looking at this and it occurred to me that:
//@ foo=>Remark("")//@ foo:=>Value("")
I wonder if we should change //@ foo to be no payload and reject //@ foo: with no non-whitespace value 🤔 But also doesn't matter and doesn't need to be this PR.
There was a problem hiding this comment.
No, that's a great observation and suggestion!
| } | ||
|
|
||
| #[test] | ||
| fn test_unknown_directive_check() { |
There was a problem hiding this comment.
Could you also add a test case too for the whitespace trimming around value? I thought we had a test for it but I'm not finding it. For sth like
//@ directive-name: val
=> Value("val").
See individual commits for details. Follow-up to #165576 and #165483.
r? jieyouxu
(No LLM was or will be used by me during the entire creation process of this PR)