a7ex / xcresultparser

Parse the binary xcresult bundle from Xcode builds and testruns
MIT License
83 stars 24 forks source link

fullpath is not shown in xml #18

Closed EaseTheWorld closed 1 year ago

EaseTheWorld commented 1 year ago

When I run xcresultparser -o xml Test-logging.xcresult output is like below.

<?xml version="1.0" encoding="UTF-8"?>
<testExecutions version="1">
    <file path="LoggingTests">
        <testCase name="testWhenSuccess()" duration="5"/>
        <testCase name="testWhenFailure()" duration="17"/>
    </file>
</testExecutions>

but when I passed this to sonar-scanner, it wasn't processed. because sonar-scanner expects, <file path="Full/Path/LoggingTests.swift"> https://docs.sonarqube.org/latest/analyzing-source-code/test-coverage/generic-test-data/#generic-test-execution

Is it possible to put the fullpath info here?

a7ex commented 1 year ago

Yes, it should be possible. Unfortunately the paths in the xcresult file are absolut and it is not easy to figure out the relative path names. Sonar however requires the relative paths. In order for the xcresultparser to figure out how to convert to relative paths you need to pass the root directory as parameter. Then the paths can be converted.

a7ex commented 1 year ago

Oh maybe I remember wrong and mixed up requirements.

Read the chapter "About paths for the sonarqube scanner" at the end of the Readme. For me that works with sonarqube.

EaseTheWorld commented 1 year ago

I read the chapter but it is two different things to me.

  1. "The tools to get the data from the xcresult archive yield absolute path names." -> result will look like <file path="Full/Path/LoggingTests.swift">.
  2. "the .xcresult bundle only lists the test by testclass, but not by file." -> result will look like <file path="LoggingTests">

My case is 2. but you're saying 1. For 1, I can use for sonarqube by replacing some path absolute->relative. but For 2, I can't do anything about it because I don't have any info about directory.

Am I missing something? or my xcresult file is wrong?(I'm using XCode 14.3, MacOS 13.2)

a7ex commented 1 year ago

I will look into it, whether xcresult changed lately in this regard. We use the sonar scanner as well with our project and there we can see the tests. I will see, what I can find out.

a7ex commented 1 year ago

The xcresult file only shows the class name of the test class. xcresultparser now uses grep to find the file, where your test class is defined. It searches through all files in your "project root" folder for "class " and very naively uses the first matching file. If the string "class " appears more than once it might be the case, that the wrong file is found.

EaseTheWorld commented 1 year ago

Thank you for check. Then xcresult never provides full path but only classname, and you've grepped to get fullpath and pass to sonarqube?

or it depends on xcode version?

2023년 5월 19일 (금) 오후 9:46, alex da franca @.***>님이 작성:

The xcresult file only shows the class name of the test class. xcresultparser now uses grep to find the file, where your test class is defined. It searches through all files in your "project root" folder for "class " and very naively uses the first matching file. If the string "class " appears more than once it might be the case, that the wrong file is found.

— Reply to this email directly, view it on GitHub https://github.com/a7ex/xcresultparser/issues/18#issuecomment-1554520466, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIEPKY62B6LS4NVFQDFHVLXG5TSHANCNFSM6AAAAAAYGFJ3YM . You are receiving this because you authored the thread.Message ID: @.***>

a7ex commented 1 year ago

Yes, that's exactly what xcresultparser does. The xcresult file provides the name of the test class and xcresultparser greps in the provided project folder for swift files which contain the string 'class name-of-the-testclass' (I just realised, that what I did in my last response got chopped by GitHub, where I used 'opening-bracket' name-of-test-class 'closing-bracket'). That is a rather "naive" approach and it will break easily, but as far as my research goes, it is the only tool, which converts xcresult files to expose the tests to SonarQube due to this "dirty trick".

a7ex commented 1 year ago

If you do not run the SonarQube command line tool in the source folder of your project, but rather only have the xcresult file, there is not much I can do about it. The sonarqube command line tool needs to run in the sources folder where the tests are, which created the xcresult. It needs to scan the test files themselves.

EaseTheWorld commented 1 year ago

I looked into the logic and found ActionTestableSummary includes projectRelativePath, ex. Module1/Domain1/Module1Domain1.xcodeproj. I think this can optimize the grep logic by narrowing down the search scope. especially for multi-module project.

a7ex commented 1 year ago

Thanks for the hint. I will look into that.