semgrep / semgrep

Lightweight static analysis for many languages. Find bug variants with patterns that look like source code.
https://semgrep.dev
GNU Lesser General Public License v2.1
10.17k stars 586 forks source link

xunit/junit conformance #5930

Open zerkms opened 1 year ago

zerkms commented 1 year ago

Describe the bug Produced junit xml does not comply with the https://github.com/jenkinsci/xunit-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd used in jenkins' xunit.

<?xml version="1.0" ?>
<testsuites errors="0" failures="2" tests="2" time="0.0">
    <testsuite errors="0" failures="2" name="semgrep results" skipped="0" tests="2" time="0">
        <testcase name="go.src.github.com.dgryski.semgrep-go.os-error-is-not-exist" classname="foo.go">
            <failure type="ERROR" message="New code should use errors.Is with the appropriate error type">      if os.IsNotExist(err) {
</failure>
        </testcase>
        <testcase name="go.src.github.com.dgryski.semgrep-go.deprecated-ioutil-writefile" classname="foo.go">
            <failure type="ERROR" message="ioutil.WriteFile is deprecated">     if err := ioutil.WriteFile(out, []byte(result), 0644); err != nil {
</failure>
        </testcase>
    </testsuite>
</testsuites>

Validation results are:

semgrep.xml:2: element testsuites: Schemas validity error : Element 'testsuites', attribute 'disabled': The attribute 'disabled' is not allowed.
semgrep.xml:3: element testsuite: Schemas validity error : Element 'testsuite', attribute 'disabled': The attribute 'disabled' is not allowed.
semgrep.xml:4: element testcase: Schemas validity error : Element 'testcase', attribute 'file': The attribute 'file' is not allowed.
semgrep.xml:4: element testcase: Schemas validity error : Element 'testcase', attribute 'line': The attribute 'line' is not allowed.
semgrep.xml:8: element testcase: Schemas validity error : Element 'testcase', attribute 'file': The attribute 'file' is not allowed.
semgrep.xml:8: element testcase: Schemas validity error : Element 'testcase', attribute 'line': The attribute 'line' is not allowed.
semgrep.xml fails to validate

To Reproduce Generate with --junit-xml and feed to the jenkins' xunit.

Expected behavior I suspect it should produce the complaint xml, unless junit in context of semgrep means something else.

Screenshots If applicable, add screenshots to help explain your problem.

What is the priority of the bug to you?

Environment If not using semgrep.dev: are you running off docker, an official binary, a local build? an official binary

Use case What will fixing this bug enable for you?

Statistics and charts in jenkins.

r2c-demo commented 1 year ago

This issue is synced in Linear at https://linear.app/r2c/issue/PA-1774/xunitjunit-conformance. Note: this link is for r2c use only and is not accessible publicly.

zerkms commented 1 year ago

Or if it's supposed to be used with recordIssues then possibly checkstyle report result should be implemented (then it would be a feature request).

ievans commented 1 year ago

@zerkms thanks for letting us know. Feel free to open a PR if you'd like, or in the meantime: what's the priority of the issue to you (looks like you forgot to mark above)?