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

Uppercase file paths in Xunit reports are changed to lowercase on case sensitive operating systems #2302

Closed
jnicol31 opened this issue Jan 21, 2022 · 5 comments · Fixed by #2303
Assignees
Labels
Milestone

Comments

@jnicol31
Copy link

jnicol31 commented Jan 21, 2022

Describe the bug
Our tests sources are located in a subdirectory <subcomponent>/TESTS/<test_dir>.
However, the Xunit sensor expects them to be in <subcomponent>/tests/<test_dir>
In the end, tests fail to be mapped with their test sources, leading to poor information on the UI.

Example:

<testcase result="fail" name="test_something" filename="somecomponent/TESTS/sometest/tst_something.cpp">

In the logs:

INFO: Processing xUnit report '/home/jenkins/workspace/.../branch/build/report/test_report_something.xml'
WARN: Cannot find the file '/home/jenkins/workspace/.../branch/somecomponent/tests/sometest/tst_something.cpp' in project 'TestProject' with baseDir '/home/jenkins/workspace/.../branch/', skipping

To Reproduce
Steps to reproduce the behavior:

  1. Move your tests source to an uppercase directory
  2. Set your sonar.tests property accordingly
  3. Update some tests so that they fail or are skipped
  4. Launch the tests and the SQ analysis
  5. Watch the logs to find: WARN: Cannot find the file '<lower cased path>' in projetc <project> with baseDir ...

Expected behavior

  • No errror in logs.
  • The failed tests and their source are shown in the UI

Desktop:

  • OS: Linux
  • SonarQube version: 9.2.1.49989
  • cxx plugin version: 2.0.6 (build 2921)
  • sonar-scanner version: 4.6.2.2472-linux

Additional context
The issue seems to be in cxx-sensors/src/main/java/org/sonar/cxx/sensors/tests/xunit/XunitReportParser.java, line 132: why is the resolved path converted to lower case ? (commit 2c2ecbd)

@guwirth
Copy link
Collaborator

guwirth commented Jan 21, 2022

Hello @jnicol31,

thanks for your feedback!

I'd have to take a closer look at that. Think the reason was Windows and Visual Studio? On Windows paths are normally case insensitiv and Visual Studio convert always all paths to lower case.

Regards,

@guwirth guwirth added bug and removed question labels Jan 21, 2022
@guwirth
Copy link
Collaborator

guwirth commented Jan 22, 2022

Hi @jnicol31,

not sure if we need to make it lowercase, inside of

var inputFile = getInputFileIfInProject(tf.getFilename());

this seems to be already handled
public InputFile getInputFileIfInProject(String path) {

Regards,

@jnicol31
Copy link
Author

jnicol31 commented Jan 23, 2022

Hi @guwirth,

thank you for your feedback. I agree with you. The only use I can see to make it lowercase here is avoiding duplications of test files in Windows in the testFiles map field in

private final Map<String, TestFile> testFiles = new HashMap<>();

if the case of the paths was to be inconsistent, which might throw an exception in

saveMetric(inputFile, CoreMetrics.TESTS, tf.getTests());

or distort statistics if a file was to be saved twice.

I wonder whether java.nio.file.Path would be a decent replacement for the testFiles map key type (not sure whether equals() and hashCode() methods adhere to the right testFiles contract for all implementations...). Otherwise, lower case should be applied only on non-NIX platforms...

@guwirth
Copy link
Collaborator

guwirth commented Jan 23, 2022

Hi @jnicol31,

thanks for your proposal, also think using path is the better choice:
https://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html#equals(java.lang.Object)

Regards,

@jnicol31
Copy link
Author

Great ! I will submit a pull request in the next few days to fix this.

Regards,

guwirth added a commit that referenced this issue Jan 25, 2022
@guwirth guwirth added this to the 2.0.7 milestone Jan 25, 2022
@guwirth guwirth changed the title Uppercase file paths in Xunit reports are changed to lowercase. Uppercase file paths in Xunit reports are changed to lowercase on case sensitive operating systems Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants