aptos-labs / aptos-core

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.
https://aptosfoundation.org
Other
5.89k stars 3.56k forks source link

[Bug] Aptos coverage tool is unable to run due to missing coverage map file #13569

Open IsaacCisnerosFT opened 3 weeks ago

IsaacCisnerosFT commented 3 weeks ago

🐛 Bug

Aptos coverage tool is unable to run due to missing coverage map file

To reproduce

Code snippet to reproduce

aptos move coverage source --module my_module --dev

Stack trace/error message

{
  "Error": "Unexpected error: Failed to retrieve coverage map No such file or directory (os error 2): Coverage map file '\"/MyHome/myProject/myModule/.coverage_map.mvcov\"' doesn't exist"
}

Expected Behavior

Test coverage information is displayed correctly for the current package.

System information

OS: MacOs Sonoma 14.5

Aptos info output: { "Result": { "build_branch": "", "build_cargo_version": "cargo 1.78.0", "build_clean_checkout": "true", "build_commit_hash": "", "build_is_release_build": "true", "build_os": "macos-aarch64", "build_pkg_version": "3.4.1", "build_profile_name": "cli", "build_rust_channel": "", "build_rust_version": "rustc 1.78.0 (9b00956e5 2024-04-29) (Homebrew)", "build_tag": "", "build_time": "2024-05-31 15:28:32 +00:00", "build_using_tokio_unstable": "true" } }

Additional context

Manually creating the missing folder does not work.

rahxephon89 commented 3 weeks ago

Hi @IsaacCisnerosFT, thanks for reporting this. I am wondering whether you have run aptos move test --coverage before running aptos move coverage source --module my_module --dev and if so, is there any error generated? Note that currently if there are failing tests in your code, the coverage map will not be generated, which may lead to the issue you mentioned.

gregnazario commented 3 weeks ago

Around this case it looks like there's a couple cases where the coverage map won't be created (this has probably existed forever).

Failing cases

1. You have no tests

The below example, won't create a coverage map, and then will fail with that error.

module 0x42::test {

  fun break_me() {
  }
}

2. You have tests that are failing

This seems unideal, but the coverage tool doesn't generate a coverage map in the event of a test that succeeds compilation, but fails on running the tests

module 0x42::test {

  fun break_me() {
  }

  #[test]
  fun test_fun() {
    abort 1; // Fail test on purpose
  }
}

Current workaround

  1. Ensure there is at least 1 #[test] function
  2. Ensure that you comment out failing tests to see the coverage
module 0x42::test {

  fun break_me() {
  }

  /*#[test]
  fun test_fun() {
    abort 1; // Fail test on purpose
  }*/
}