SlatherOrg / slather

Generate test coverage reports for Xcode projects & hook it into CI.
MIT License
1.56k stars 238 forks source link

"error: Could not load coverage information" on targets with 0% code coverage #495

Open tovkal opened 3 years ago

tovkal commented 3 years ago

I am getting this error on targets that have no coverage because they have no tests and don't know if this is expected behavior or not.

error: .../DerivedData/Build/Products/Debug-iphonesimulator/SomeModule.framework/SomeModule: Failed to load coverage: No coverage data found
error: Could not load coverage information
/Users/someUser/.gems/gems/json-2.5.1/lib/json/common.rb:216:in `parse': 809: unexpected token at '' (JSON::ParserError)
    from /Users/someUser/.gems/gems/json-2.5.1/lib/json/common.rb:216:in `parse'
    from /Users/someUser/.gems/gems/slather-2.7.0/lib/slather/project.rb:135:in `pathnames_per_binary'
    from /Users/someUser/.gems/gems/slather-2.7.0/lib/slather/project.rb:124:in `block in profdata_coverage_files'
    from /Users/someUser/.gems/gems/slather-2.7.0/lib/slather/project.rb:123:in `each'
    from /Users/someUser/.gems/gems/slather-2.7.0/lib/slather/project.rb:123:in `profdata_coverage_files'
    from /Users/someUser/.gems/gems/slather-2.7.0/lib/slather/project.rb:98:in `coverage_files'
    from /Users/someUser/.gems/gems/slather-2.7.0/lib/slather/coverage_service/sonarqube_xml_output.rb:18:in `post'
    from /Users/someUser/.gems/gems/slather-2.7.0/lib/slather/command/coverage_command.rb:101:in `post'
    from /Users/someUser/.gems/gems/slather-2.7.0/lib/slather/command/coverage_command.rb:61:in `execute'
    from /Users/someUser/.gems/gems/clamp-1.3.2/lib/clamp/command.rb:66:in `run'
    from /Users/someUser/.gems/gems/clamp-1.3.2/lib/clamp/subcommand/execution.rb:18:in `execute'
    from /Users/someUser/.gems/gems/clamp-1.3.2/lib/clamp/command.rb:66:in `run'
    from /Users/someUser/.gems/gems/clamp-1.3.2/lib/clamp/command.rb:140:in `run'
    from /Users/someUser/.gems/gems/slather-2.7.0/bin/slather:17:in `<top (required)>'
    from /Users/someUser/.gems/bin/slather:23:in `load'
    from /Users/someUser/.gems/bin/slather:23:in `<main>'

I am trying to run slather on a multi module project, all living under one workspace. The command I am running (by using the fastlane plugin) is a more complex version of the following, where I pass all targets I want coverage on as --binary-basename parameters.

slather coverage --sonarqube-xml --build-directory DerivedData --output-directory DerivedData/slatherOutput --ignore Pods/\* --ignore Frameworks/\* --scheme MyApp-ALL-TESTS --workspace ./MyApp.xcworkspace --binary-basename MyApp --binary-basename SomeModule ./MyApp.xcodeproj

Is there a way to tell slather to ignore targets with no coverage, to avoid the error?

kerimovscreations commented 2 years ago

Make sure:

  1. All modules are included in the test phase of the main scheme
Screen Shot 2022-03-27 at 09 31 23 Screen Shot 2022-03-27 at 09 34 32
  1. All modules and their test modules are configured as Enable Testability: True
Screen Shot 2022-03-27 at 09 32 21

Example of project building:

xcodebuild \
          -project yourproject.xcodeproj/ \
          -scheme yourproject \
          -derivedDataPath Build/ \
          -enableCodeCoverage YES \
          -destination 'platform=iOS Simulator,name=iPhone 12,OS=15.4' \
          CODE_SIGN_IDENTITY="" \
          CODE_SIGNING_REQUIRED=NO \
          ONLY_ACTIVE_ARCH=YES \
          VALID_ARCHS=x86_64 \
          clean \
          build \
          test

Slather generator:

slather coverage --sonarqube-xml \
          --build-directory Build \
          --output-directory sonar-reports \
          --scheme yourproject yourproject.xcodeproj
taher-mosbah commented 4 months ago

Is there any updates on this one ? we started getting the same error when running on Xcode 16 beta.

Cynthia1991 commented 3 months ago

We have similar issues when build with Xcode 16 beta 4:

error: Failed to load coverage: 'XXXXXX': No coverage data found
error: Could not load coverage information

Any updates from this one?

MadanG222 commented 3 months ago

Even I am facing same issue. This is working on xCode 15.4 and older but xCode 16 beta 5, I am getting same error. let me know if anyone know any solution for this.

jarrodlombardo-EventBase commented 3 months ago

I can't test this issue myself (If I upgrade beyond XCode 15.1 currently, it will break things for me at work), but if anyone running XCode 16 can get any more detailed information about what has changed in XCode between 15.x and 16, that could help. There was a breaking change in the LLDB version XCode was using between XCode 14.2 and 14.3 that broke lots of things, so maybe they did something similar between XCode 15 and 16.