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

format-coverage fails for simplecov 0.21.2 (minitest) with cc-test-reporter 0.10.3 #495

Open
tnir opened this issue Jul 1, 2022 · 4 comments
Assignees

Comments

@tnir
Copy link

tnir commented Jul 1, 2022

What happens

cc-test-reporter format-coverage fails with coverage results from SimpleCov 0.21.2 and minitest 5.16.1 as follows:

$ ./cc-test-reporter format-coverage -t simplecov coverage/.resultset.json -d
DEBU[0000] coverage path coverage/.resultset.json       
DEBU[0000] using formatter simplecov                    
DEBU[0000] checking search path coverage/.resultset.json for simplecov formatter 
DEBU[0000] couldn't load branch from ENV, trying git... 
DEBU[0000] couldn't load commit sha from ENV, trying git... 
DEBU[0000] couldn't load committed at from ENV, trying git... 
DEBU[0000] Analyzing simplecov json output from latest format coverage/.resultset.json 
DEBU[0000] Analyzing simplecov json output from legacy format coverage/.resultset.json 
Error: json: cannot unmarshal object into Go struct field resultSet.coverage of type []formatters.NullInt

Why

The following results should be handled without any error:

{
  "Unit Tests": {
    "coverage": {
      "/workspace/geminabox/lib/geminabox.rb": {
        "lines": [
          null
        ]
      },
      "/workspace/geminabox/lib/geminabox/proxy.rb": {
        "lines": [
          null
        ]
      }
    },
    "timestamp": 1650000000
  },
  "Integration Tests": {
    "coverage": {
      "/workspace/geminabox/lib/geminabox.rb": {
        "lines": [
          null
        ]
      },
      "/workspace/geminabox/lib/geminabox/proxy.rb": {
        "lines": [
          null
        ]
      }
    },
    "timestamp": 1650000000
  }
}

Currently it work well with the following results:

{
  "Unit Tests": {
    "coverage": {
      "/workspace/geminabox/lib/geminabox.rb": [
          null
      ],
      "/workspace/geminabox/lib/geminabox/proxy.rb": [
          null
      ]
    },
    "timestamp": 1650000000
  },
  "Integration Tests": {
    "coverage": {
      "/workspace/geminabox/lib/geminabox.rb": [
          null
      ],
      "/workspace/geminabox/lib/geminabox/proxy.rb": [
          null
      ]
    },
    "timestamp": 1650000000
  }
}

Workaround

jq 'map_values(. | map_values(if type=="object" then map_values(.lines) else . end))' coverage/.resultset.json helped me work well.

Environments

Code Climate Test Reporter 0.10.3 (2cd3a82f34475dd7387da166ddd967fe1d713a65 @ 2022-02-15T15:28:53+0000)
@tnir
Copy link
Author

tnir commented Jul 2, 2022

Looks relevant to #488 to me.

@manicmaniac
Copy link

@tnir

Thank you for the workaround in #495 (comment)

📝 jq 'walk(try .lines // .)' coverage/.resultset.json also works for me.

geezyx added a commit to geezyx/whatmask that referenced this issue Jan 4, 2023
* Add .circleci/config.yml

* remove travisci config

* update dependencies

* update badges

* create basic ruby gem publish

* use newer ruby version

* commit gemfile lock

* add codeclimate test coverage

* add codeclimate test coverage

* json fix for codeclimate test reporter

see codeclimate/test-reporter#495
@manicmaniac
Copy link

Currently simplecov formatter checks .meta.simplecov_version value in .resultset.json and changes its behavior depending whether the version is above 0.18.0.

However, apparently simplecov does not output .meta.simplecov_version to .resultset.json as far as I confirmed.
If .meta.simplecov_version does not exist, the program uses legacy formatter that does not support .lines.

if reportIsOnLegacyFormat(m.Meta.SimpleCovVersion) {

func reportIsOnLegacyFormat(simplecovVersion string) bool {
var major, minor, patch int
fmt.Sscanf(simplecovVersion, "%d.%d.%d", &major, &minor, &patch)
if major < 1 {
if minor < 18 {
return true
}
}
return false
}

@manicmaniac
Copy link

However, apparently simplecov does not output .meta.simplecov_version to .resultset.json as far as I confirmed.

After a further investigation, I found simplecov writes coverage/coverage.json only when CC_TEST_REPORTER_ID environment variable is set (this feature was introduced in simplecov-ruby/simplecov#950).
And cc-test-reporter format-coverage --input-type=simplecov reads coverage/coverage.json at first and fallbacks to coverage/.resultset.json if the former does not exist.

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

So another possible workaround would be setting environment variable before testing.

CC_TEST_REPORTER_ID=xxx bundle exec rake test

manicmaniac added a commit to manicmaniac/test-reporter that referenced this issue Apr 9, 2023
As I mentioned in codeclimate#495 (comment),
`cc-test-reporter format-coverage --input-type=simplecov` needs the test
to have run with `CC_TEST_REPORTER_ID` is set, otherwise it parses
a coverage file in legacy format that crashes `cc-test-reporter`.
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

No branches or pull requests

3 participants