I’ve been trying to implement SonarQube for C++ manually since the GithubActions and others are not feasible right now on my workspace. Despite it working for the code, when following the tutorials for gcovr and gcov and manually uploading the values as instructed on the tutorials on GitHub the tests coverage still show up as 0%.
Our system is built using CMake with a separate directory for the build and tests.
There are no errors on uploading the reports with sonnar-scanner and using lcov to assert the results they show relevant information from the coverage. Also reading the coverage generated with the --sonarqube command on gcov, it correctly shows my tests coverages. But when checking the coverage on the website it’s stays shows as 0%.
Are the tests coverages a paid feature? Since i’ve been testing i’m sticking to the free version, could this be the problem?
Code coverage is available in all editions / tiers of SonarQube. What do the logs say about importing code coverage?
They show no errors what so ever. I glad to send them if required
Bring 'em on!
I’m sorry for taking this long to reply, Holidays got in the way… Either way it started working by itself… It must have been related to the targets when building using CMake.
With that being said i’ve stumbled on another problem. When using curl commands to test the Web API from SonarCloud i’m receiving a outdated browser error.
When running the following command:
curl -u my_token: https://sonarcloud.io/web_api/api/projects/search\?deprecated\=false\&organization\=tidewise
I get the following response:
</style>
<div class="terminal">
<div aria-label="Outdated browser">
<pre aria-hidden="true">
██████╗ ██╗ ██╗████████╗██████╗ █████╗ ████████╗███████╗██████╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗███████╗███████╗██████╗
██╔═══██╗██║ ██║╚══██╔══╝██╔══██╗██╔══██╗╚══██╔══╝██╔════╝██╔══██╗ ██╔══██╗██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔════╝██╔══██╗
██║ ██║██║ ██║ ██║ ██║ ██║███████║ ██║ █████╗ ██║ ██║ ██████╔╝██████╔╝██║ ██║██║ █╗ ██║███████╗█████╗ ██████╔╝
██║ ██║██║ ██║ ██║ ██║ ██║██╔══██║ ██║ ██╔══╝ ██║ ██║ ██╔══██╗██╔══██╗██║ ██║██║███╗██║╚════██║██╔══╝ ██╔══██╗
╚██████╔╝╚██████╔╝ ██║ ██████╔╝██║ ██║ ██║ ███████╗██████╔╝ ██████╔╝██║ ██║╚██████╔╝╚███╔███╔╝███████║███████╗██║ ██║
╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚══════╝╚═╝ ╚═╝
</pre>
</div>
<div class="warning-msg">
As if my curl was a outdated browser. Which IMO doesn’t make any sense, i’ve tried to save the response on multiple files but to no avail (e.g. JSON, HTML, TXT)
Also, the command stated on the web api samples doesn’t work as intented despite working when using the RESTED API browser extension:
curl --request GET \
--url 'https://sonarcloud.com/api/web_api/measures/component?metricKeys=ncloc%2Ccode_smells%2Ccomplexity&component=tidewise_drivers-test' \
--header 'Authorization: Bearer my_token'
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>urllo</center>
</body>
</html>
The correct URL is:
https://sonarcloud.io/api/measures/component?metricKeys=ncloc%2Ccode_smells%2Ccomplexity&component=tidewise_drivers-test
While the documentation has web_api
in the URL, the actual APi does not.
Can you point me to this example?
I’ve used curl -u
to send the authentication, but now i’ve realized i may be mistaken. As for the url, it’s here.
I got it by copying the hyperlink on the chains, and modified it to add the organization parameter as it’s required.
Upon further inspection, i’ve realized that when copied the hyperlink returns the following:
https://sonarcloud.io/web_api/api/projects/search?deprecated=false§ion=params
But when pasted on the Konsole it turns into:
https://sonarcloud.io/web_api/api/projects/search\?deprecated\=false\§ion\=params
The backslashes are added and break the url. These occur because of Z Shells url quote magic… that I didn’t notice it beforehand. Upon their removal and also removing the web_api since i now know it’s deprecated and adding the required parameter, it becomes:
https://sonarcloud.io/api/projects/search?deprecated=false§ion=params&organization=tidewise
And by using it alongside:
curl --request GET \
--url 'https://sonarcloud.io/api/projects/search?deprecated=false§ion=params&organization=tidewise' \
--header 'Authorization: Bearer my_token'
Returns the correct response, so now i think everything is in order to continue testing sonarcloud.
On another note, where would i be able to find all the possible options for the sonar-scanner app? I would like to ignore a specific folder from the test coverages analysis.
Hey there.
Ah, that is just a hyperlink to the documentation itself and not intended to point to the “base” URL of the API itself.
You can find that info in the docs. That doc specifically deals with analysis scope, but there are other parameters documented here.