-
Notifications
You must be signed in to change notification settings - Fork 78
Add support for excoveralls json format #278
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package excoveralls | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"strings" | ||
|
||
"github.com/Sirupsen/logrus" | ||
"github.com/codeclimate/test-reporter/env" | ||
"github.com/codeclimate/test-reporter/formatters" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
var searchPaths = []string{"cover/excoveralls.json"} | ||
|
||
type Formatter struct { | ||
Path string | ||
} | ||
|
||
func (f *Formatter) Search(paths ...string) (string, error) { | ||
paths = append(paths, searchPaths...) | ||
for _, p := range paths { | ||
logrus.Debugf("checking search path %s for excoveralls formatter", p) | ||
if _, err := os.Stat(p); err == nil { | ||
f.Path = p | ||
return p, nil | ||
} | ||
} | ||
|
||
return "", errors.WithStack(errors.Errorf("could not find any files in search paths for excoveralls. search paths were: %s", strings.Join(paths, ", "))) | ||
} | ||
|
||
func (r Formatter) Format() (formatters.Report, error) { | ||
report, err := formatters.NewReport() | ||
if err != nil { | ||
return report, err | ||
} | ||
|
||
inputFile, err := os.Open(r.Path) | ||
if err != nil { | ||
return report, errors.WithStack(errors.Errorf("could not open coverage file %s", r.Path)) | ||
} | ||
|
||
coverageInput := &jsonExcoveralls{} | ||
err = json.NewDecoder(inputFile).Decode(&coverageInput) | ||
if err != nil { | ||
return report, errors.WithStack(err) | ||
} | ||
|
||
gitHead, _ := env.GetHead() | ||
for _, file := range coverageInput.Files { | ||
sourceFile, err := formatters.NewSourceFile(file.Name, gitHead) | ||
if err != nil { | ||
return report, errors.WithStack(err) | ||
} | ||
sourceFile.Coverage = file.Coverage | ||
err = report.AddSourceFile(sourceFile) | ||
if err != nil { | ||
return report, errors.WithStack(err) | ||
} | ||
} | ||
|
||
return report, nil | ||
} | ||
|
||
type jsonSourceFile struct { | ||
Name string `json:"name,attr"` | ||
Coverage []formatters.NullInt `json:"coverage,attr"` | ||
} | ||
|
||
type jsonExcoveralls struct { | ||
Files []jsonSourceFile `json:"source_files"` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"source_files":[ | ||
{ | ||
"name":"demo-app/services/create_user.ex", | ||
"coverage":[null,null,null,1,null,null,null,null,null,1,null,1,null,null,1,null,null,1,null,0,null,null] | ||
}, | ||
{ | ||
"name":"demo-app/services/update_user_info.ex", | ||
"coverage":[null,null,null,1,null,null,1,1,null,1,null,null,1,null,null,1,1,null,null,1,null,1,null,null] | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package excoveralls | ||
|
||
import ( | ||
"testing" | ||
|
||
"gopkg.in/src-d/go-git.v4/plumbing/object" | ||
|
||
"github.com/codeclimate/test-reporter/env" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_Format(t *testing.T) { | ||
gb := env.GitBlob | ||
defer func() { env.GitBlob = gb }() | ||
env.GitBlob = func(s string, c *object.Commit) (string, error) { | ||
return s, nil | ||
} | ||
|
||
r := require.New(t) | ||
|
||
rb := Formatter{ | ||
Path: "./excoveralls_example.json", | ||
} | ||
rep, err := rb.Format() | ||
r.NoError(err) | ||
|
||
r.InDelta(93.3, rep.CoveredPercent, 1) | ||
|
||
sf := rep.SourceFiles["demo-app/services/update_user_info.ex"] | ||
r.InDelta(100, sf.CoveredPercent, 1) | ||
sfLc := sf.LineCounts | ||
r.Equal(sfLc.Covered, 9) | ||
r.Equal(sfLc.Missed, 0) | ||
r.Equal(sfLc.Total, 9) | ||
|
||
lc := rep.LineCounts | ||
r.Equal(lc.Covered, 14) | ||
r.Equal(lc.Missed, 1) | ||
r.Equal(lc.Total, 15) | ||
} | ||
|
||
func Test_Format_MissingFile(t *testing.T) { | ||
gb := env.GitBlob | ||
defer func() { env.GitBlob = gb }() | ||
env.GitBlob = func(s string, c *object.Commit) (string, error) { | ||
return s, nil | ||
} | ||
|
||
r := require.New(t) | ||
|
||
rb := Formatter{ | ||
Path: "./not_real.json", | ||
} | ||
_, err := rb.Format() | ||
r.Error(err) | ||
r.Equal("could not open coverage file ./not_real.json", err.Error()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
FROM elixir:1.4.2 | ||
|
||
RUN curl -O https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz | ||
RUN tar -xvf go1.8.linux-amd64.tar.gz | ||
RUN mv go /usr/local | ||
|
||
ENV PATH $PATH:/usr/local/go/bin | ||
RUN go version | ||
|
||
ENV GOPATH /go | ||
RUN mkdir $GOPATH | ||
ENV PATH $PATH:/go/bin | ||
|
||
ENV CCTR=$GOPATH/src/github.com/codeclimate/test-reporter | ||
RUN mkdir -p $CCTR | ||
WORKDIR $CCTR | ||
COPY . . | ||
RUN go install -v | ||
|
||
# RUN git clone https://github.com/ale7714/excoveralls.git | ||
RUN git clone https://github.com/codeclimate-testing/excoveralls.git | ||
WORKDIR excoveralls | ||
|
||
RUN echo "testing" > ignore.me | ||
RUN git config --global user.email "[email protected]" | ||
RUN git config --global user.name "Your Name" | ||
RUN git add ignore.me | ||
RUN git commit -m "testing" | ||
ENV MIX_ENV=test | ||
RUN mix do local.hex --force, local.rebar --force, deps.get, compile, coveralls.json | ||
|
||
|
||
ENV CC_TEST_REPORTER_ID=f611556edda9a27a3faace9b837185944ada203dfca1ec3242a4d0a35162f9fc | ||
|
||
RUN test-reporter after-build -s 2 -d |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it'd be worth adding coverage for the
could not find any files
,could not open coverage file
states, too?