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

Make SyntaxTest easier to extend with custom expectations #14505

Merged
merged 5 commits into from
Aug 23, 2023

Conversation

cameel
Copy link
Member

@cameel cameel commented Aug 21, 2023

Prerequisite for #14433.

I originally planned to derive my new Natspec test case from TestCase with AnalysisFramework as a mixin. This allowed me to go 90% of the way, but then it turned out that some useful behaviors of our syntax tests are not a reusable part of the base test case, but available only in SyntaxTest:

  • Formatting errors the same way as in syntax tests (and parsing that format back).
  • Highlighting locations of syntax errors in he source.
  • Multi-file tests.

Some of them are in CommonSyntaxTest, but that in turn does not use AnalysisFramework and I'd have to reimplement some of the functionality that SyntaxTest already has.

This PR modifies CommonSyntaxTest and SyntaxTest to make it easier to use them as a base for test cases that want to include errors and warnings in their expectations, but also have extra output when analysis succeeds. The Natspec test case will use this mechanism to expect either errors (if Natspec is invalid) or JSON content.

matheusaaguiar
matheusaaguiar previously approved these changes Aug 21, 2023
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.

Just a small nit or more of a question, but not really a problem.


protected:
virtual void setupCompiler();
void parseAndAnalyze() override;
virtual void filterObtainedErrors();

bool m_optimiseYul = true;
bool m_parserErrorRecovery = false;
bool m_optimiseYul{};
Copy link
Collaborator

@matheusaaguiar matheusaaguiar Aug 21, 2023

Choose a reason for hiding this comment

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

I see that m_optimiseYul defaults to true in the constructor, so seems harmless, but still shouldn't we keep it initialized with the same value here too?

Copy link
Member Author

@cameel cameel Aug 22, 2023

Choose a reason for hiding this comment

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

It does not really default to true. It defaults to m_reader.boolSetting("optimize-yul", true), which could end up being either. true is just as misleading here as false.

I think that using default initialization here is the least bad option. It does not show the value so it does not draw attention away from the initialization in the constructor. The actual value here is irrelevant, we only really care that it's initialized to some deterministic value.

@ekpyron
Copy link
Member

ekpyron commented Aug 22, 2023

Needs rebase

@cameel
Copy link
Member Author

cameel commented Aug 22, 2023

Rebased.

@cameel cameel force-pushed the syntax-test-more-extension-points branch from 5fa0993 to bf0d51d Compare August 22, 2023 13:45
@cameel cameel force-pushed the syntax-test-more-extension-points branch from bf0d51d to 7768f26 Compare August 22, 2023 19:17
- Also reorder Error::Type to match initial values for some consistency
- These get re-initialized in constructor anyway. The only purpose if initializing here is our convention to always initialize primitive types at declaration time. We don't want to have to repeat the defaults though.
@cameel cameel force-pushed the syntax-test-more-extension-points branch from 7768f26 to e847596 Compare August 23, 2023 16:00
@ekpyron ekpyron enabled auto-merge August 23, 2023 16:06
@ekpyron ekpyron merged commit 37e1861 into develop Aug 23, 2023
1 check passed
@ekpyron ekpyron deleted the syntax-test-more-extension-points branch August 23, 2023 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants