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

Filter out functions marked with #[test] attribute #26

Closed
ksew1 opened this issue Aug 26, 2024 · 0 comments · Fixed by #40
Closed

Filter out functions marked with #[test] attribute #26

ksew1 opened this issue Aug 26, 2024 · 0 comments · Fixed by #40
Assignees

Comments

@ksew1
Copy link
Member

ksew1 commented Aug 26, 2024

In Cairo coverage, we use compilator mappings in the form of: Sierra ID -> list of details, where each detail is a triple consisting of:

  • Path to file
  • Line in file
  • Function name

We want to focus on the coverage of functions that belong to the user project. However, the user should also have the option to filter out test functions in their project, as these might disturb the true line coverage statistics.

Sierra JSON Files

The structure of the *.sierra.json files is as follows:

{
  "version": 1,
  "type_declarations": [],
  "libfunc_declarations": [],
  "statements": [],
  "funcs": [],
  "debug_info": {
    "type_names": [],
    "libfunc_names": [],
    "user_func_names": [],
    "annotations": [],
    "executables": {
      "snforge_internal_test_executable": [
        {
          "id": 4,
          "debug_name": "some_debug_name"
        }
      ]
    }
  }
}

In the debug_info.executables.snforge_internal_test_executable section, entries point to functions marked with #[test]. Thanks to this, we know the debug names of the functions marked with #[test].

High-level Algorithm

  • Extract function names marked with #[test] from the *.sierra.json files.
  • Analyze entries of Sierra ID -> list of [(path to file, line in file, function name)].
  • Check if the function_name is not in the list of test functions.
  • Filter out entries that do not meet these criteria.

This will not work on functions in #[cfg(test)] that are not marked #[test] this should be fixed here .

@ksew1 ksew1 changed the title Filter out fille locations that are not in user project and in /tests dir Filter out /tests file locations and file locations not from user project Aug 26, 2024
@ksew1 ksew1 mentioned this issue Aug 26, 2024
@ksew1 ksew1 self-assigned this Aug 26, 2024
@ksew1 ksew1 changed the title Filter out /tests file locations and file locations not from user project Filter out tests found in project Aug 27, 2024
@ksew1 ksew1 changed the title Filter out tests found in project Filter out test functions Aug 28, 2024
@ksew1 ksew1 changed the title Filter out test functions Filter out functions marked with #[test] attribute Aug 28, 2024
@ksew1 ksew1 linked a pull request Sep 2, 2024 that will close this issue
@ksew1 ksew1 closed this as completed in #40 Sep 3, 2024
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 a pull request may close this issue.

1 participant