I get the execution failure java.lang.IllegalStateException: The Compilation Database JSON file was found but 0 C/C++/Objective-C files were analyzed.. I explicitly specified sonar.inclusions=ignored-file.txt because I’m not interested in a full codebase analysis, but only in the specified test file. How could I achieve that?
Test files are typically excluded from analysis, so what you actually want to do is force it to be recognized as a source file (include it as sonar.sources)
I tried to include them in the analysis (in sonar.sources) and also to specify that they are test files (in sonar.tests). sonar-scanner failed with the message: ERROR: File Test/CMakeLists.txt can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files.
The message is quite explicit.
After reading the Narrowing the focus page, I don’t quite understand the point
Different analysis rules are applied to the two categories.
What are the analysis rules that apply to Tests? How could I explicitly analyse them for errors using the CFamily plugin, but still treat them as Test code (in order to exclude them from Code Coverage metrics)?
sonar.tests property is used to identify the directories containing test source files. Identifying test files helps the analyzers to tune their rules. For example, the analyzers can enable test-specific rules and disable rules that don’t make sense in the context of testing.
The C/C++/Objective-C analyzer currently analyze main and test source files the same way. Consequently, sonar.tests is not yet supported; the analyzer ignores it.
If you wish to analyze test source files, you should include them in the sonar.sources property.
So if you’re still facing an issue when only specifying sonar.sources, it would be a good idea to share your build wrapper output and analysis logs. If it only concerns a single file, you might be able to do it publicly.
It works fine if I include the test files in sonar.sources. What I still can’t figure out how to do: exclude the Tests code from Code Coverage metrics. Is that possible?