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

Add support for simplecov's new expected JSON output #441

Merged
merged 11 commits into from
Dec 14, 2020
Merged

Add support for simplecov's new expected JSON output #441

merged 11 commits into from
Dec 14, 2020

Conversation

fede-moya
Copy link
Contributor

@fede-moya fede-moya commented Sep 14, 2020

Following #413, this PR attempts to add support to simplecov 0.20.0 +. As discussed in the issue shared before, the main idea is that simplecov will natively incorporate a JSON formatter, which we will be triggered by default when running simplecov within an environment that has the CC_TEST_REPORTER_ID variable present.

Accordingly, the simplecov formatter will now try to read coverage information from the output of the new simplecov's JSON formatter. This new report will contain more information reporting as "ignored" those lines marked with :nocov:.

The current implementation pretends to maintain support for previous versions, therefore there are two different paths for looking up the json report, the old .resultset.json and the new coverage.json, a priority in order has been given to coverage.json. When a path is given, like when using test-reporter format-coverate -t simplecov -p /some-path the formatter will try to read the indicated information as if was outputted by the new JSON formatter, in case of that not being the case it will fallback to reading as if it has the same format as .resultset.json. The idea is that no one gets affected by this changes.

As a final note, Until simplecov-ruby/simplecov#923 get's merged or a variation of it, It wouldn't make much sense to merge this work, though in theory it wouldn't cause problems to anyone.

Addresses:

Bonus track

  • This pull request includes a minimal change on the circleci configuration, was necessary to get CI passing. It just bumps up the XCODE version of the macos engines.

@CLAassistant
Copy link

CLAassistant commented Sep 14, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@noelia-lencina noelia-lencina left a comment

Choose a reason for hiding this comment

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

Nice work! Tests look great 👏 I left a really small comment, feel free to ignore it if you feel it's not worth it.

if err != nil {
return legacyFormat(r, rep)
} else {
logrus.Debugf("Analyzing simplecov json output from latest format %s", r.Path)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would it be possible to move this logic into its own file similar to legacyFormat to keep the same structure?

Copy link
Contributor Author

@fede-moya fede-moya Dec 6, 2020

Choose a reason for hiding this comment

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

I liked the suggestion thanks, addressed. Just couldn't find a more clever name to the new formatter than jsonFormatter although it makes sense since it has been designed to read output from the SimpleCov's JsonFormatter.

@fede-moya
Copy link
Contributor Author

@filipesperandio can I get your review here please ? I'm posting here since I cannot add you as a reviewer, I think it's due to the repo's permissions settings

@filipesperandio
Copy link
Contributor

@fede-moya: You and @noelia-lencina should have write access to the repo now. 🤦

var searchPaths = []string{"coverage/.resultset.json"}
var simpleCovJsonFormatterPath, legacyPath string = "coverage/coverage.json", "coverage/.resultset.json"

var searchPaths = []string{simpleCovJsonFormatterPath, legacyPath}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be inlined? Doesn't look like we use those vars anywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍🏼

if err != nil {
return rep, errors.WithStack(errors.Errorf("could not open coverage file %s", r.Path))
}
rep, err = jsonFormat(r,rep)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused. Does this override what line 34 does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mind taking a new look ? I don't think I'm following the the question sorry

Copy link
Contributor

Choose a reason for hiding this comment

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

I might have something confused in my head, not seeing a problem here anymore 🤦

Coverage map[string]formatters.Coverage `json:"coverage"`
}

func legacyFormat(r Formatter, rep formatters.Report) (formatters.Report, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we always return rep, can we avoid that and only return error?
And the caller deal with the return it needs to pass? Like return rep, legacyFormat(r, rep)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Might not be a go thing, though... let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I liked your suggestion so I tested it out, but for some unknown reason to me tests just started to fail without a clear explanation. Check dacd033 , then I reverted the commit and tests passed again. So ...

rep, err := f.Format()
r.NoError(err)

r.Len(rep.SourceFiles, 7)
Copy link
Contributor

Choose a reason for hiding this comment

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

The single char vars here are making my eye itchy 🤨
Can we make the names a bit more descriptive? Like, 4 lines down and I don't recall what r is anymore 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hahah, yeah I know sorry, I kinda follow the pattern that was already in place, but I have just update all the tests to use better namings.

@fede-moya
Copy link
Contributor Author

Hey @filipesperandio just addressed your comments, thanks for your, as usual, detailed review. I'm just pinging you again in this comment to make some noise on your notifications so it became the first thing you see on Monday and luckily if you have further comments we can address them tomorrow 💪🏼

@filipesperandio
Copy link
Contributor

Worked. 😂

if err != nil {
return rep, errors.WithStack(errors.Errorf("could not open coverage file %s", r.Path))
}
rep, err = jsonFormat(r,rep)
Copy link
Contributor

Choose a reason for hiding this comment

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

I might have something confused in my head, not seeing a problem here anymore 🤦

@@ -18,21 +18,21 @@ func Test_ParseLegacy(t *testing.T) {
return s, nil
}

r := require.New(t)
assert := require.New(t)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! thanks!

@@ -24,7 +24,7 @@ jobs:

test_macos:
macos:
xcode: "9.0"
xcode: "11.3.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance we can do this in a separate PR? Feel free to tag me.
Just want to isolate infra/tooling changes from other things, makes it easier to revert in case we need to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeap, I think that makes sense. Will do that now

@fede-moya fede-moya merged commit d3d488b into codeclimate:master Dec 14, 2020
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.

None yet

4 participants