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

Fix empty source path generated in cobertura.xml #309

Merged
merged 1 commit into from
Aug 24, 2023

Conversation

mstyura
Copy link
Contributor

@mstyura mstyura commented Aug 24, 2023

Currently cobertura.xml is generated with empty path in <source></source> which lead to full path being used in filename attributes:

`cobertura.xml` as produced but current `llvm-cov report --cobertura`
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "https://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.4838709677419355" lines-covered="15" lines-valid="31" timestamp="1692890446" version="2.0.3">
    <sources>
        <source></source>
    </sources>
    <packages>
        <package line-rate="0.4838709677419355" branch-rate="0" name=".test-ci.src" complexity="0">
            <classes>
                <class branch-rate="0" complexity="0" filename="/test-ci/src/lib.rs" line-rate="0.5769230769230769" name=".test-ci.src.lib.rs">
                    <methods>
                        <method name="test_ci::tests::test_bad_sum::{closure#0}" signature="" complexity="0" line-rate="1" branch-rate="1">
                            <lines>
                                <line hits="1" number="34" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::tests::test_success::{closure#0}" signature="" complexity="0" line-rate="1" branch-rate="1">
                            <lines>
                                <line hits="1" number="24" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::uncovered_sum" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="9" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::covered_bad_sum" signature="" complexity="0" line-rate="1" branch-rate="1">
                            <lines>
                                <line hits="1" number="13" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::run" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="1" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::two" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="5" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::uncovered_sum" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="9" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::covered_bad_sum" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="13" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::run" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="1" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::two" signature="" complexity="0" line-rate="1" branch-rate="1">
                            <lines>
                                <line hits="1" number="5" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::tests::test_failure" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="30" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::tests::test_bad_sum" signature="" complexity="0" line-rate="1" branch-rate="1">
                            <lines>
                                <line hits="1" number="35" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::tests::test_success" signature="" complexity="0" line-rate="1" branch-rate="1">
                            <lines>
                                <line hits="1" number="25" branch="false"/>
                            </lines>
                        </method>
                    </methods>
                    <lines>
                        <line branch="false" hits="0" number="1"/>
                        <line branch="false" hits="0" number="2"/>
                        <line branch="false" hits="0" number="3"/>
                        <line branch="false" hits="1" number="5"/>
                        <line branch="false" hits="1" number="6"/>
                        <line branch="false" hits="1" number="7"/>
                        <line branch="false" hits="0" number="9"/>
                        <line branch="false" hits="0" number="10"/>
                        <line branch="false" hits="0" number="11"/>
                        <line branch="false" hits="1" number="13"/>
                        <line branch="false" hits="1" number="14"/>
                        <line branch="false" hits="1" number="15"/>
                        <line branch="false" hits="0" number="16"/>
                        <line branch="false" hits="0" number="17"/>
                        <line branch="false" hits="1" number="18"/>
                        <line branch="false" hits="1" number="24"/>
                        <line branch="false" hits="1" number="25"/>
                        <line branch="false" hits="1" number="26"/>
                        <line branch="false" hits="1" number="27"/>
                        <line branch="false" hits="0" number="30"/>
                        <line branch="false" hits="0" number="31"/>
                        <line branch="false" hits="0" number="32"/>
                        <line branch="false" hits="1" number="34"/>
                        <line branch="false" hits="1" number="35"/>
                        <line branch="false" hits="1" number="36"/>
                        <line branch="false" hits="1" number="37"/>
                    </lines>
                </class>
                <class branch-rate="0" complexity="0" filename="/test-ci/src/main.rs" line-rate="0" name=".test-ci.src.main.rs">
                    <methods>
                        <method name="test_ci::main" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="3" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::main" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="3" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::main" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="1" branch="false"/>
                            </lines>
                        </method>
                    </methods>
                    <lines>
                        <line branch="false" hits="0" number="1"/>
                        <line branch="false" hits="0" number="2"/>
                        <line branch="false" hits="0" number="3"/>
                        <line branch="false" hits="0" number="4"/>
                        <line branch="false" hits="0" number="5"/>
                    </lines>
                </class>
            </classes>
        </package>
    </packages>
</coverage>

which then can't be properly rendered by GitLab test coverage visualisation.

Proposed PR fixed generation of <source></source> which affects generation of filename attributes:

`cobertura.xml` as produced by modified `llvm-cov report --cobertura`
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "https://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.47058823529411764" lines-covered="8" lines-valid="17" timestamp="1692891839" version="2.0.3">
    <sources>
        <source>/test-ci</source>
    </sources>
    <packages>
        <package line-rate="0.47058823529411764" branch-rate="0" name="src" complexity="0">
            <classes>
                <class branch-rate="0" complexity="0" filename="src/lib.rs" line-rate="0.5714285714285714" name="src.lib.rs">
                    <methods>
                        <method name="test_ci::tests::test_failure::{closure#0}" signature="" complexity="0" line-rate="1" branch-rate="1">
                            <lines>
                                <line hits="1" number="16" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::tests::test_success::{closure#0}" signature="" complexity="0" line-rate="1" branch-rate="1">
                            <lines>
                                <line hits="1" number="11" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::run" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="1" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::two" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="5" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::run" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="1" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::two" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="5" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::tests::test_failure" signature="" complexity="0" line-rate="1" branch-rate="1">
                            <lines>
                                <line hits="1" number="17" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::tests::test_success" signature="" complexity="0" line-rate="1" branch-rate="1">
                            <lines>
                                <line hits="1" number="12" branch="false"/>
                            </lines>
                        </method>
                    </methods>
                    <lines>
                        <line branch="false" hits="0" number="1"/>
                        <line branch="false" hits="0" number="2"/>
                        <line branch="false" hits="0" number="3"/>
                        <line branch="false" hits="0" number="5"/>
                        <line branch="false" hits="0" number="6"/>
                        <line branch="false" hits="0" number="7"/>
                        <line branch="false" hits="1" number="11"/>
                        <line branch="false" hits="1" number="12"/>
                        <line branch="false" hits="1" number="13"/>
                        <line branch="false" hits="1" number="14"/>
                        <line branch="false" hits="1" number="16"/>
                        <line branch="false" hits="1" number="17"/>
                        <line branch="false" hits="1" number="18"/>
                        <line branch="false" hits="1" number="19"/>
                    </lines>
                </class>
                <class branch-rate="0" complexity="0" filename="src/main.rs" line-rate="0" name="src.main.rs">
                    <methods>
                        <method name="test_ci::main" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="3" branch="false"/>
                            </lines>
                        </method>
                        <method name="test_ci::main" signature="" complexity="0" line-rate="0" branch-rate="0">
                            <lines>
                                <line hits="0" number="3" branch="false"/>
                            </lines>
                        </method>
                    </methods>
                    <lines>
                        <line branch="false" hits="0" number="3"/>
                        <line branch="false" hits="0" number="4"/>
                        <line branch="false" hits="0" number="5"/>
                    </lines>
                </class>
            </classes>
        </package>
    </packages>
</coverage>

The corrected report is consumed by GitLab successfully and produce nice visualisation:
GitLab report example

@mstyura mstyura force-pushed the gitlab-integration branch from 241f824 to 7044909 Compare August 24, 2023 17:57
Copy link
Owner

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

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

Thanks!

@taiki-e taiki-e merged commit 005b6c9 into taiki-e:main Aug 24, 2023
@taiki-e
Copy link
Owner

taiki-e commented Aug 24, 2023

Published in 0.5.31.

@mstyura mstyura deleted the gitlab-integration branch August 24, 2023 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants