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

Unify preamble injection in AnalysisFramework #14480

Merged
merged 4 commits into from
Aug 17, 2023
Merged

Conversation

cameel
Copy link
Member

@cameel cameel commented Aug 7, 2023

Another refactor before #14433.

Even though AnalysisFramework can insert preamble automatically, this code is baked into parseAnalyseAndReturnError(), which is not universally used by all test cases. The result is that some test cases reinvent the wheel and implement that bit on their own, always slightly differently. Some of them do not insert license if it's already there, some don't care. Some can handle multi-line comments, some can't.

This is quite frustrating because when you're writing a new test case you have to waste time to figure out why there are so many versions of it, which one you need and how to use it. Then you realize you can't easily reuse it and end up adding yet another copy. This PR unifies all that duplicated code into a reusable withPreamble() method available to all test cases inheriting from AnalysisFramework.

It would be nice to also have the error filtering automatically adjust error locations to account for the preamble (SyntaxTest already has code for doing that), but I'll leave that for another day.

@cameel cameel self-assigned this Aug 7, 2023
@cameel cameel force-pushed the refactor-preamble branch from 06b57bb to 4f70c74 Compare August 7, 2023 18:03
nikola-matic
nikola-matic previously approved these changes Aug 8, 2023
test/libsolidity/AnalysisFramework.cpp Outdated Show resolved Hide resolved
@cameel cameel force-pushed the refactor-preamble branch from 078754a to b29778c Compare August 11, 2023 13:06
@cameel cameel requested a review from r0qs August 11, 2023 13:07
@cameel cameel force-pushed the refactor-preamble branch from b29778c to 49408be Compare August 11, 2023 18:38
};

string output = regex_replace(_stderrContent, preReleaseWarningRegex, "");
return regex_replace(std::move(output), noOutputRegex, "");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would string::erase(string::find(preRealeaseWarning)) not work here (on a copy of course)?

Copy link
Member Author

@cameel cameel Aug 16, 2023

Choose a reason for hiding this comment

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

No, because there are optional bits in the string. I.e. the error code and some whitespace. I'd have to do the replacement with 4 variants of the string for that to work.

Also, this is just a minor test helper, so not much point in avoiding simple regexes here if using them makes the code simpler.

@cameel cameel force-pushed the refactor-preamble branch from 49408be to dbe12ff Compare August 16, 2023 12:30
@cameel cameel requested a review from nikola-matic August 16, 2023 12:31
@cameel cameel force-pushed the refactor-preamble branch 3 times, most recently from 3d3d597 to 02ba1ed Compare August 16, 2023 17:07
Copy link
Collaborator

@matheusaaguiar matheusaaguiar left a comment

Choose a reason for hiding this comment

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

lgtm

@cameel cameel force-pushed the refactor-preamble branch from 02ba1ed to 2baf9d4 Compare August 17, 2023 15:39
@cameel cameel merged commit ef5f131 into develop Aug 17, 2023
@cameel cameel deleted the refactor-preamble branch August 17, 2023 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

4 participants