Skip to content

C++: Exclude tests in model generation #19498

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

Merged
merged 1 commit into from
May 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cpp/ql/src/utils/modelgenerator/internal/CaptureModels.qll
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ private predicate isUninterestingForModels(Callable api) {
api = any(Cpp::LambdaExpression lambda).getLambdaFunction()
or
api.isFromUninstantiatedTemplate(_)
or
// Exclude functions in test directories (but not the ones in the CodeQL test directory)
exists(Cpp::File f |
f = api.getFile() and
f.getAbsolutePath().matches("%test%") and
Copy link
Preview

Copilot AI May 15, 2025

Choose a reason for hiding this comment

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

The pattern "%test%" may match any substring (e.g., "contest" or user paths containing "test"). Consider anchoring to directory separators (e.g., "%/test/%") or using a path-matching utility to target only "test" directories.

Suggested change
f.getAbsolutePath().matches("%test%") and
f.getAbsolutePath().matches("%/test/%") and

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a bad suggestion! I do like simply using test though so that we also match stuff like tests, though. I could go either way on this 🤷

not f.getAbsolutePath().matches("%test/library-tests/dataflow/modelgenerator/dataflow/%")
Comment on lines +52 to +53
Copy link
Preview

Copilot AI May 15, 2025

Choose a reason for hiding this comment

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

Relying on absolute paths with OS-specific separators can reduce portability. Consider using getRelativePath() or normalizing paths with forward slashes to ensure this exception works across platforms.

Suggested change
f.getAbsolutePath().matches("%test%") and
not f.getAbsolutePath().matches("%test/library-tests/dataflow/modelgenerator/dataflow/%")
f.getRelativePath().matches("%test%") and
not f.getRelativePath().matches("%test/library-tests/dataflow/modelgenerator/dataflow/%")

Copilot uses AI. Check for mistakes.

)
}

private predicate relevant(Callable api) {
Expand Down
Loading