Giter Club home page Giter Club logo

gocov-xml's Introduction

gocov XML

A tool to generate Go coverage in XML report for using with tools/plugins like Jenkins/Cobertura.

Table of Contents

This is a simple helper tool for generating XML output in Cobertura format for CIs like Jenkins, vsts and others from github.com/axw/gocov output. The generated XML output is in the latest coverage-04.dtd schema

Installation

Just type the following to install the program and its dependencies:

For Go 1.17 and above:

go install github.com/axw/gocov/gocov@latest
go install github.com/AlekSi/gocov-xml@latest

For previous Go versions:

go get github.com/axw/gocov/...
go get github.com/AlekSi/gocov-xml

Usage

NOTE: gocov-xml reads data from the standard input.

gocov [-source <absolute path to source>]

Where,

  • source: Absolute path to source. Defaults to the current working directory.

Examples

Generate coverage by passing gocov output as input to gocov-xml

gocov test github.com/gorilla/mux | gocov-xml > coverage.xml

Specifying optional source

gocov test github.com/gorilla/mux | gocov-xml -source /abs/path/to/source > coverage.xml

Authors

gocov-xml's People

Contributors

abhijithda avatar aleksi avatar nezorflame avatar t-yuki avatar yaoyaozong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gocov-xml's Issues

Cobertura can't find sources

In typical setup Cobertura will be unable to find sources, and correct setup is too complicated. I believe we can simplify it using <sources> element in XML.

gocov-xml is not able find *.go, and is throwing `error: can't find <file>.go` and `panic: EOF`

gocov-xml is not able find *.go, and is throwing error: can't find *.go and panic: EOF.

NOTE: The issue is happening only in build. If I run the same thing in codespaces, it's working fine.

Here is the build yml: https://github.com/VeritasOS/plugin-manager/blob/v1/.github/workflows/go.yml#L72, and below are the logs: https://github.com/VeritasOS/plugin-manager/actions/runs/4389396801/jobs/7686898826

	</testsuite>
	<testsuite name="github.com/VeritasOS/plugin-manager/pluginmanager" tests="0" failures="0" errors="0" id="3" hostname="fv-az221-499" time="0.000" timestamp="2023-03-10T23:51:39Z"></testsuite>
	<testsuite name="github.com/VeritasOS/plugin-manager/utils/log" tests="0" failures="0" errors="0" id="4" hostname="fv-az221-499" time="0.000" timestamp="2023-03-10T23:51:39Z"></testsuite>
	<testsuite name="github.com/VeritasOS/plugin-manager/utils/output" tests="4" failures="0" errors="0" id="5" hostname="fv-az221-499" time="0.000" timestamp="2023-03-10T23:51:39Z">
		<testcase name="TestExecCommand" classname="github.com/VeritasOS/plugin-manager/utils/output" time="0.000"></testcase>
		<testcase name="TestOsMkdirAll" classname="github.com/VeritasOS/plugin-manager/utils/output" time="0.000"></testcase>
		<testcase name="TestOsOpenFile" classname="github.com/VeritasOS/plugin-manager/utils/output" time="0.000"></testcase>
		<testcase name="TestOsRemoveAll" classname="github.com/VeritasOS/plugin-manager/utils/output" time="0.000"></testcase>
		<system-out><![CDATA[coverage: [no statements]
ok  	github.com/VeritasOS/plugin-manager/utils/os	0.002s	coverage: [no statements]]]></system-out>
	</testsuite>
</testsuites>
+ /home/runner/work/plugin-manager/plugin-manager/tools/go/gocov convert /home/runner/work/plugin-manager/plugin-manager/cover/cover.out
+ /home/runner/work/plugin-manager/plugin-manager/tools/go/gocov-xml
error: can't find "pm.go": go/build: go list github.com/VeritasOS/plugin-manager/cmd/pm: fork/exec /usr/local/go/bin/go: no such file or directory


panic: EOF

goroutine 1 [running]:
main.main()
	/go/pkg/mod/github.com/!alek!si/[email protected]/gocov-xml.go:106 +0x1265
Error: Process completed with exit code 2.

Tag a Release, also add modules support?

Hi @AlekSi and other contributors,

First, thanks for making gocov-xml -- it's a very valuable tool for our Jenkins pipelines for Go projects!

Could you please tag a Release of this project? I ask because I've run into an issue with a Go modules proxy that comes up mainly because of the behavior of pseudo-versions, and I think the best long-term fix is to tag a release of this project, since it appears to be fairly stable at this point.

If you wanted to explicitly add Go modules support, that would be great too. ๐Ÿ˜„ It looks like it wouldn't be hard, so I don't think you'd need my help, but if you'd like me to prepare a PR, I can do that.

Thanks!

SXXP0003: Error reported by XML parser: DOCTYPE is disallowed

I'm using gocov-xml to convert go coverage to xml format.

go test -tags static -coverprofile coverage.out
gocov convert coverage.out > coverage.json && \
   cat coverage.json | gocov-xml > coverage.xml

I'm then using Jenkins Pipelines to publish this to Jenkins:

publishCoverage adapters: [coberturaAdapter('coverage.xml')], sourceFileResolver: sourceFiles('NEVER_STORE')

In the jenkins.log on the server, we see :

Error on line 2 column 10 of coverage.xml:
  SXXP0003: Error reported by XML parser: DOCTYPE is disallowed when the feature
  "http://apache.org/xml/features/disallow-doctype-decl" set to true.

Looking at the first 2 lines of the coverage.xml we see

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">

I have a feeling this is a security feature of Jenkins - is there a way to suppress generation of the DOCTYPE element, for use when loading into jenkins? Should I strip the DOCTYPE line prior to attempting to publish into jenkins as a workaround?

Thanks,

Support for full project tree

The tools works fine on a specific folder that has tests, but when running with ./...
it fails with:
#13 0.848 ? github.com/xxx/fff/controller/auth [no test files] #13 1.027 # github.com/xxx/fff/controller/config #13 1.027 controller/config/config.go:84:3: Fatal call has possible formatting directive %v #13 1.035 error: exit status 2 #13 1.037 panic: EOF

There are indeed folders without tests, but I expect them to be ignored...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.