Skip to content

fixed #13376 - include --check-level in analyzer information hash#7072

Merged
firewave merged 1 commit intocppcheck-opensource:mainfrom
firewave:level-hash
Dec 10, 2024
Merged

fixed #13376 - include --check-level in analyzer information hash#7072
firewave merged 1 commit intocppcheck-opensource:mainfrom
firewave:level-hash

Conversation

@firewave
Copy link
Copy Markdown
Collaborator

@firewave firewave commented Dec 4, 2024

No description provided.

Comment thread lib/cppcheck.cpp Outdated
toolinfo << (mSettings.severity.isEnabled(Severity::information) ? 'i' : ' ');
toolinfo << mSettings.userDefines;
toolinfo << std::to_string(static_cast<std::uint8_t>(mSettings.checkLevel));
// TODO: do we need to add more options?
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

how about creating a Settings::toolinfo() method and unit testing that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That would be a rather pointless test. It returns exactly what we expect it to return based on the input so it would just be a logic duplication.

There's more refactorings coming so maybe one of those will give us an in for a useful test.

Copy link
Copy Markdown
Collaborator

@danmar danmar Dec 6, 2024

Choose a reason for hiding this comment

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

your test only checks that --check-level=normal / --check-level=exhaustive works as expected. With such unit test we can more quickly test that all the flags we want to test influence the output. I would not think that pytest tests that cover each flag would be nice. 1 pytest that checks that the everything works as expected if toolinfo is different is enough imho.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

But the test is rather pointless as you need to replicate the whole logic of the function. And it would not be the final hash. Also that test would break soon as the suppressions need to be split from the settings and would just complicate things.

And we should actually have not a single test in Python but one for each possible values as each of them might have side effects which would not be visible if you try to test it as whole.

This is only addressing part of this because a user encountered this. This needs a lot more work and a first step which tests this in a more generic will follow soon.

Copy link
Copy Markdown
Collaborator

@danmar danmar Dec 7, 2024

Choose a reason for hiding this comment

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

If you are really against the Settings::toolinfo().. if you expose a calculateHash in analyzerinfo and unit test that then I am also happy. I want to have unit tests that is my motivation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That requires some refactoring first.

I would like to merge this fix before that as it was reported by a user and not discovered internally.

Copy link
Copy Markdown
Collaborator

@danmar danmar Dec 8, 2024

Choose a reason for hiding this comment

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

okay.. feel free to merge and then refactor.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We can still remove/merge it later on - more things need to be tested in future anyways. Too much tests is usually not the issue we are having. 🤪

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Too much tests is usually not the issue we are having.

Yes I do agree however I want to also say I would not like to just throw in lots of random tests in random places. Let's continue to structure it as much as we can and make the tests as clean and simple as possible.

As far as I see there is no existing pytest test for calculateHash yes that is really unfortunate.

@firewave firewave marked this pull request as ready for review December 4, 2024 23:40
Comment thread test/cli/other_test.py
@firewave firewave merged commit 719ee61 into cppcheck-opensource:main Dec 10, 2024
@firewave firewave deleted the level-hash branch December 10, 2024 12:14
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.

2 participants