### Install via cargo-binstall Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Install cargo-llvm-cov using the cargo-binstall tool. ```sh cargo binstall cargo-llvm-cov ``` -------------------------------- ### Install via Scoop (Windows) Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Use Scoop to add the repository and install cargo-llvm-cov on Windows. ```sh scoop bucket add taiki-e https://github.com/taiki-e/scoop-bucket scoop install cargo-llvm-cov ``` -------------------------------- ### Install cargo-llvm-cov from Release Page with Verification Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md This script downloads a prebuilt binary from the GitHub releases page, verifies its integrity using release attestations and artifact attestations, and installs it. It requires `gh` CLI to be installed. ```sh # Get host target. host=$(rustc -vV | grep '^host:' | cut -d' ' -f2) # Download binary. curl --proto '=https' --tlsv1.2 -fsSL -o cargo-llvm-cov.tar.gz "https://github.com/taiki-e/cargo-llvm-cov/releases/latest/download/cargo-llvm-cov-${host}.tar.gz" # Verify release attestations. gh release -R https://github.com/taiki-e/cargo-llvm-cov verify-asset cargo-llvm-cov.tar.gz # Verify artifact attestations. gh attestation verify --repo taiki-e/cargo-llvm-cov --signer-workflow taiki-e/github-actions/.github/workflows/rust-release.yml cargo-llvm-cov.tar.gz # Install to $CARGO_HOME/bin (or $HOME/.cargo/bin if CARGO_HOME is unset). tar xf cargo-llvm-cov.tar.gz -C "${CARGO_HOME:-"$HOME/.cargo"}"/bin # Remove archive. rm cargo-llvm-cov.tar.gz ``` ```text Calculated digest for cargo-llvm-cov.tar.gz: sha256: Resolved tag v to sha1: Loaded attestation from GitHub API ✓ Verification succeeded! cargo-llvm-cov.tar.gz is present in release v ``` ```text Loaded digest sha256: for file://cargo-llvm-cov.tar.gz Loaded 1 attestation from GitHub API The following policy criteria will be enforced: - Predicate type must match:................ https://slsa.dev/provenance/v1 - Source Repository Owner URI must match:... https://github.com/taiki-e - Subject Alternative Name must match regex: (?i)^https://github.com/taiki-e/ - OIDC Issuer must match:................... https://token.actions.githubusercontent.com ✓ Verification succeeded! The following 1 attestation matched the policy criteria - Attestation #1 - Build repo:..... taiki-e/cargo-llvm-cov - Build workflow:. .github/workflows/release.yml@refs/heads/main - Signer repo:.... taiki-e/github-actions - Signer workflow: .github/workflows/rust-release.yml@refs/heads/main ``` -------------------------------- ### Install via ports (FreeBSD) Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Install cargo-llvm-cov from the official ports collection on FreeBSD. ```sh pkg install cargo-llvm-cov ``` -------------------------------- ### Install cargo-llvm-cov via Homebrew Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Install cargo-llvm-cov using Homebrew. This command installs the package from the official `homebrew-core` tap. ```sh brew install cargo-llvm-cov ``` -------------------------------- ### Install cargo-llvm-cov from Source Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Use this command to install cargo-llvm-cov directly from its source code using Cargo. Ensure you have Rust toolchain 1.87+ installed. ```sh cargo +stable install cargo-llvm-cov --locked ``` -------------------------------- ### Install via pacman (Arch Linux) Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Install cargo-llvm-cov from the Arch Linux extra repository using pacman. ```sh pacman -S cargo-llvm-cov ``` -------------------------------- ### Install cargo-llvm-cov on GitHub Actions Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Use the `taiki-e/install-action` to automatically install prebuilt binaries of cargo-llvm-cov on GitHub Actions workflows. This is recommended for CI/CD environments. ```yaml - uses: taiki-e/install-action@cargo-llvm-cov ``` ```yaml - uses: taiki-e/install-action@cargo-llvm-cov - uses: taiki-e/install-action@nextest ``` -------------------------------- ### Run Binary/Example and Generate Coverage Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Executes a binary or example using `cargo run` and generates a code coverage report. This is useful for profiling executable code. ```sh cargo llvm-cov run ``` -------------------------------- ### Install cargo-llvm-cov from Release Page without Verification Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md This script downloads a prebuilt binary from the GitHub releases page and installs it directly without verification. This is a faster but less secure method. ```sh # Get host target. host=$(rustc -vV | grep '^host:' | cut -d' ' -f2) # Download binary and install to $CARGO_HOME/bin (or $HOME/.cargo/bin if CARGO_HOME is unset). curl --proto '=https' --tlsv1.2 -fsSL "https://github.com/taiki-e/cargo-llvm-cov/releases/latest/download/cargo-llvm-cov-$host.tar.gz" \ | tar xzf - -C "${CARGO_HOME:-"$HOME/.cargo"}"/bin ``` -------------------------------- ### Install cargo-llvm-cov via Homebrew Tap Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Install cargo-llvm-cov using Homebrew from the custom tap maintained by the project. This might provide newer versions or specific builds. ```sh brew install taiki-e/tap/cargo-llvm-cov ``` -------------------------------- ### Setup Environment Variables for External Tests Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Source environment variables for coverage and clean previous artifacts before building. This setup is required before building your Rust binaries. ```sh # Set the environment variables needed to get coverage. source <(cargo llvm-cov show-env --sh) # Remove artifacts that may affect the coverage results. # This command should be called after show-env. cargo llvm-cov clean --workspace ``` -------------------------------- ### Setup Environment Variables and Clean for AFL Fuzzers Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Prepare the environment for AFL fuzzer coverage by sourcing environment variables and cleaning the workspace. Use `--dep-coverage` if your fuzzer is in a separate workspace. ```sh # Set environment variables and clean workspace. # If your fuzzer directory is in a separated workspace, you have to pass # `--dep-coverage ` to `cargo llvm-cov show-env` and then run # `cargo llvm-cov clean -p `. source <(cargo llvm-cov show-env --sh) cargo llvm-cov clean --workspace ``` -------------------------------- ### GitLab CI Configuration for Coverage (YAML) Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md This GitLab CI configuration example demonstrates how to run tests with `cargo-llvm-cov`, generate a Cobertura coverage report, and configure GitLab to display the coverage summary. ```yaml unit_tests: artifacts: reports: junit: target/nextest/default/junit.xml coverage_report: coverage_format: cobertura path: target/llvm-cov-target/cobertura.xml # this uses region for coverage summary coverage: '/TOTAL\s+(\d+\s+)+(\d+\.\d+\%)/' script: - cargo llvm-cov nextest - cargo llvm-cov report --cobertura --output-path target/llvm-cov-target/cobertura.xml ``` -------------------------------- ### Rust Function with Coverage Data Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/real1/package1.txt Example of a Rust function annotated with coverage data. Lines marked with '0' indicate execution, while lines without a leading number are not covered. ```rust 0| 0|pub fn func(x: u32) { 0| 0| match x { 0| 0| 0 => {} 0| 0| 1 => {} 0| 0| 2 => {} 0| 0| _ => {} | } 0|} ``` -------------------------------- ### Rust Main Function with Match Statement Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/bin_crate/bin_crate.hide-instantiations.txt This Rust code defines a main function that parses command-line arguments and uses a match statement to execute different branches based on the parsed value. It's a basic example of input handling and control flow in Rust. ```rust fn main() { match std::env::args().skip(1).next().unwrap().parse::().unwrap() { 0 => {} 1 => {} 2 => {} _ => {} } } ``` -------------------------------- ### Rust Function with Match Statement Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/no_test/no_test.txt A Rust function that uses a match statement. This example shows a function with multiple branches. ```rust pub fn func(x: u32) { match x { 0 => {} 1 => {} 2 => {} _ => {} } } ``` -------------------------------- ### PowerShell Environment Variable Setup for Coverage Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Alternative method for setting environment variables for coverage in PowerShell 6+. This is used similarly to the shell script method for external tests. ```powershell Invoke-Expression (cargo llvm-cov show-env --pwsh | Out-String) ``` -------------------------------- ### Rust Generic Function with Coverage Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/instantiations/instantiations.hide-instantiations.txt Illustrates a generic Rust function `func` that takes a type `T` implementing `Default` and `PartialOrd`. Coverage is tracked for the conditional logic within the function. This example is relevant for understanding how coverage is reported for generic code. ```rust fn func(t: T) -> bool { if t < T::default() { true } else { false } } ``` -------------------------------- ### Default Excluded Patterns for Coverage Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md These are the default patterns and crates that are excluded from coverage reports. They include vendored sources, tests, examples, benches, and toolchain files. ```text {SEPARATOR}rustc{SEPARATOR}([0-9a-f]+|[0-9]+\.[0-9]+\.[0-9]+){SEPARATOR} ^{WORKSPACE_ROOT}({SEPARATOR}.*)?{SEPARATOR}(tests|examples|benches){SEPARATOR} ^{WORKSPACE_ROOT}({SEPARATOR}.*)?{SEPARATOR}(tests.rs|[0-9a-zA-Z_-]+[_-]tests.rs)$ ^{TARGET_DIR}($|{SEPARATOR}) ^{CARGO_HOME}{SEPARATOR}(registry|git){SEPARATOR} ^{RUSTUP_HOME}{SEPARATOR}toolchains($|{SEPARATOR}) ``` -------------------------------- ### Cargo LLVM-cov Help Output Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Displays the complete list of options and arguments for the cargo-llvm-cov command. This is useful for understanding all available functionalities and configurations. ```console $ cargo llvm-cov --help cargo-llvm-cov Cargo subcommand to easily use LLVM source-based code coverage (-C instrument-coverage). USAGE: cargo llvm-cov [SUBCOMMAND] [OPTIONS] [-- ...] ARGS: ... Arguments for the test binary OPTIONS: --json Export coverage data in "json" format If --output-path is not specified, the report will be printed to stdout. This internally calls `llvm-cov export -format=text`. See for more. --lcov Export coverage data in "lcov" format If --output-path is not specified, the report will be printed to stdout. This internally calls `llvm-cov export -format=lcov`. See for more. --cobertura Export coverage data in "cobertura" XML format If --output-path is not specified, the report will be printed to stdout. This internally calls `llvm-cov export -format=lcov` and then converts to cobertura.xml. See for more. --codecov Export coverage data in "Codecov Custom Coverage" format If --output-path is not specified, the report will be printed to stdout. This internally calls `llvm-cov export -format=json` and then converts to codecov.json. See for more. --text Generate coverage report in "text" format If --output-path or --output-dir is not specified, the report will be printed to stdout. This internally calls `llvm-cov show -format=text`. See for more. --html Generate coverage report in "html" format If --output-dir is not specified, the report will be generated in `target/llvm-cov/html` directory. This internally calls `llvm-cov show -format=html`. See for more. --open Generate coverage reports in "html" format and open them in a browser after the operation. See --html for more. --summary-only Export only summary information for each file in the coverage data This flag can only be used together with --json, --lcov, or --cobertura. --output-path Specify a file to write coverage data into. This flag can only be used together with --json, --lcov, --cobertura, or --text. See --output-dir for --html and --open. --output-dir Specify a directory to write coverage report into (default to `target/llvm-cov`). This flag can only be used together with --text, --html, or --open. See also --output-path. --failure-mode Fail if `any` or `all` profiles cannot be merged (default to `any`) --ignore-filename-regex Skip source code files with file paths that match the given regular expression --show-instantiations Show instantiations in report --no-cfg-coverage Unset cfg(coverage), which is enabled when code is built using cargo-llvm-cov --no-cfg-coverage-nightly Unset cfg(coverage_nightly), which is enabled when code is built using cargo-llvm-cov and nightly compiler --no-report Run tests, but don't generate coverage report --no-clean Build without cleaning any old build artifacts --no-rustc-wrapper Build without setting RUSTC_WRAPPER By default, cargo-llvm-cov sets RUSTC_WRAPPER. This is usually optimal for compilation time, execution time, and disk usage. When both this flag and --target option are used, coverage for proc-macro and build script will not be displayed because cargo does not pass RUSTFLAGS to them. --fail-under-functions Exit with a status of 1 if the total function coverage is less than MIN percent --fail-under-lines Exit with a status of 1 if the total line coverage is less than MIN percent --fail-under-file-lines Exit with a status of 1 if the files line coverage is less than MIN percent ``` -------------------------------- ### Run Tests and Generate Coverage Summary Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Executes tests and prints a summary of code coverage to standard output. This is the default behavior when no subcommand is specified. ```sh cargo llvm-cov ``` -------------------------------- ### Rust Function with Test Coverage Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/exclude-from-test2.txt Demonstrates a Rust function `func` and a test function `test` that calls it multiple times with different arguments. Coverage is shown for each line. ```rust pub fn func(x: u32) { match x { 0 => {} 1 => {} 2 => {} _ => {} } } ``` ```rust #[test] fn test() { func(1); func(3); member2::func(0); member3::func(0); member4::func(0); } ``` -------------------------------- ### Build and Report Coverage for External Tests Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Build Rust binaries with instrumentation and generate an LCOV report. Ensure environment variables are set and artifacts are cleaned prior to this step. ```sh cargo build # Build rust binaries with instrumentation. # Commands using binaries in target/debug/*, including `cargo test` and other cargo subcommands. # ... cargo llvm-cov report --lcov # Generate report without tests. ``` -------------------------------- ### Rust Function with Match Statement Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package1.txt Illustrates a Rust function `func` that takes a u32 and uses a match statement to handle different input values. Coverage data shows execution counts for each branch. ```rust pub fn func(x: u32) { match x { 0 => {} 1 => {} 2 => {} _ => {} } } ``` -------------------------------- ### Function-level Coverage Control in Rust Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.txt Use `#[cfg_attr(coverage, coverage(off))]` on a function to exclude it from coverage reports. This example shows a function `func` and a test `fn_level` where `func(0)` is covered, but `func(1)` is not due to the attribute. ```rust #![cfg_attr(coverage, feature(coverage_attribute))] fn func(x: i32) { match x { 0 => {} 1 => {} 2 => {} 3 => {} _ => {} } } #[cfg_attr(coverage, coverage(off))] #[test] fn fn_level() { func(0); if false { func(1); } } ``` -------------------------------- ### Build and Run AFL Fuzzer for Coverage Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Build the fuzz target and run the fuzzer with the necessary loop count to ensure profraw files are emitted. This is a prerequisite for generating coverage reports for fuzzers. ```sh # Build the fuzz target. cargo afl build # Run the fuzzer, the AFL_FUZZER_LOOPCOUNT is needed, because otherwise .profraw files aren't emitted. # To get coverage of current corpus, minimize it and set it as input, then run the fuzzer until it processes the corpus. AFL_FUZZER_LOOPCOUNT=20 cargo afl fuzz -c - -i in -o out target/debug/fuzz-target ``` -------------------------------- ### Function Definitions Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/exclude1.txt This snippet details the 'func' and 'func2' functions found in various modules, along with their signatures and basic implementations. ```APIDOC ## Function: func ### Description A function named 'func' is defined in multiple locations. It takes a single argument 'x' of type u32 and contains a match statement. ### Signature `pub fn func(x: u32)` ### Implementation Details The function's implementation includes a match statement that handles specific values of 'x' (0, 1, 2) and a default case. ## Function: func2 ### Description A function named 'func2' is defined in `member2/src/lib.rs`. It takes a single argument 'x' of type u32 and contains a match statement. ### Signature `pub fn func2(x: u32)` ### Implementation Details The function's implementation includes a match statement that handles specific values of 'x' (0, 1, 2) and a default case. This function is also used in a test case. ## Test: test ### Description A test function named 'test' is defined in `member2/src/lib.rs`. It calls `func2` with specific arguments. ### Signature `fn test()` ### Usage Calls `func2(0)` and `func2(2)`. ``` -------------------------------- ### Run Build Without Cleaning Artifacts Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Runs the coverage process without cleaning previous build artifacts. Use with caution, and consider running `cargo llvm-cov clean --workspace` first. ```sh cargo llvm-cov --no-clean ``` -------------------------------- ### say_hello_goodby Function Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/issue361/issue361.hide-instantiations.txt This function, say_hello_goodby, is designed to print a greeting and a farewell message. It also calls another function, crate_a::say_hello(). ```APIDOC ## say_hello_goodby() ### Description This function prints "Goodby!" and calls `crate_a::say_hello()`. ### Signature `pub fn say_hello_goodby()` ### Usage This function can be called directly to execute its defined behavior. ### Example ```rust say_hello_goodby(); ``` ``` -------------------------------- ### Open HTML Coverage Report Automatically Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Generates an HTML coverage report and automatically opens it in the default web browser. ```sh cargo llvm-cov --open ``` -------------------------------- ### Nextest Configuration for JUnit Reports (TOML) Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md This `.config/nextest.toml` configuration specifies the output path for JUnit test reports, which can be used by CI systems. ```toml [profile.default.junit] path = "junit.xml" ``` -------------------------------- ### Generate Plain Text Coverage Report Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Generates a plain text coverage report. If `--output-path` is not specified, the report is printed to standard output and can be piped to a pager like `less`. ```sh cargo llvm-cov --text | less -R ``` -------------------------------- ### Rust Test Case for Function Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/merge/merge.txt Illustrates a Rust test function that verifies the behavior of the `func` function under different feature flags. It asserts expected outcomes for positive and negative inputs. ```rust fn test() { #[cfg(feature = "a")] assert!(!func(1)); #[cfg(feature = "b")] assert!(func(-1)); } ``` -------------------------------- ### Rust Function and Test Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/issue361/issue361.txt This snippet shows a basic Rust function and its corresponding test case. It's useful for understanding how to structure code for coverage analysis. ```rust pub fn say_hello_goodby() { crate_a::say_hello(); println!("Goodby!"); } #[cfg(test)] mod test { #[test] fn test_say_hello_goodby() { super::say_hello_goodby(); } } ``` -------------------------------- ### func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/exclude-from-report1.hide-instantiations.txt A function that takes a u32 input and performs a match operation. ```APIDOC ## pub fn func(x: u32) ### Description This function takes an unsigned 32-bit integer `x` and performs a match operation on its value. ### Parameters * **x** (u32) - The input value for the match operation. ``` -------------------------------- ### func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package3.hide-instantiations.txt A function named func that takes a u32 argument. ```APIDOC ## func ### Description This function takes a single unsigned 32-bit integer argument `x` and performs a match operation on it. ### Signature `pub fn func(x: u32)` ``` -------------------------------- ### module::func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/no_test/link_dead_code.txt This function takes an unsigned 32-bit integer and performs a match operation. ```APIDOC ## module::func(x: u32) ### Description This function takes an unsigned 32-bit integer `x` and executes different code blocks based on its value using a match statement. ### Signature `pub fn func(x: u32)` ### Parameters * **x** (u32) - The input value to be matched. ``` -------------------------------- ### func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package4.hide-instantiations.txt A function that takes a u32 and performs a match operation. ```APIDOC ## func(x: u32) ### Description This function takes an unsigned 32-bit integer `x` and executes a match statement based on its value. ### Signature `pub fn func(x: u32)` ### Parameters - **x** (u32) - The input value for the match operation. ``` -------------------------------- ### Rust Function Definition and Test Case Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/exclude-from-report2.txt Defines a Rust function `func` and a test function `test` that calls it and functions from other members. This snippet shows basic Rust syntax and how tests are structured. ```rust pub fn func(x: u32) { match x { 0 => {} 1 => {} 2 => {} _ => {} } } #[test] fn test() { func(1); func(3); member2::func(0); member3::func(0); member4::func(0); } ``` -------------------------------- ### Include Coverage for FFI Code Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Generates coverage reports that include C/C++ code linked to Rust libraries or binaries. Requires setting specific LLVM environment variables and using the `--include-ffi` flag. ```sh CC= \ CXX= \ LLVM_COV= \ LLVM_PROFDATA= \ cargo llvm-cov --lcov --include-ffi ``` -------------------------------- ### Rust Library Source with Test Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/no_test/link_dead_code.txt This Rust source file defines a library module and includes a test function. Coverage is reported for executed lines. ```rust mod module; pub use module::*; #[test] fn f() {} ``` -------------------------------- ### func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package4.txt A function that takes a u32 integer and performs a match operation. ```APIDOC ## func(x: u32) ### Description This function accepts an unsigned 32-bit integer `x` and executes a match statement based on its value. It handles specific cases for 0, 1, and 2, and a default case for any other value. ### Signature `pub fn func(x: u32)` ### Parameters #### Path Parameters - **x** (u32) - Required - The input unsigned 32-bit integer. ### Response This function does not return a value. ``` -------------------------------- ### func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package5.txt A function that takes a u32 integer and performs a match operation. ```APIDOC ## func(x: u32) ### Description This function accepts an unsigned 32-bit integer `x` and executes a match statement based on its value. It includes specific cases for 0, 1, and 2, with a wildcard case for any other value. ### Signature `pub fn func(x: u32)` ### Parameters * **x** (u32) - The input unsigned 32-bit integer. ### Usage Example ```rust package5::func(0); package5::func(5); ``` ``` -------------------------------- ### GitHub Actions Workflow for Codecov (YAML) Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md This GitHub Actions workflow demonstrates how to generate and upload line coverage reports to Codecov using `cargo-llvm-cov` with the `--lcov` flag. ```yaml name: Coverage on: [pull_request, push] jobs: coverage: runs-on: ubuntu-latest env: CARGO_TERM_COLOR: always steps: - uses: actions/checkout@v6 - name: Install Rust run: rustup update stable - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov - name: Generate code coverage run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} # required for private repos or protected branches files: lcov.info fail_ci_if_error: true ``` -------------------------------- ### Generate HTML Coverage Report Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Generates an interactive HTML report of code coverage. The report is typically saved to `target/llvm-cov/html`. ```sh cargo llvm-cov --html open target/llvm-cov/html/index.html ``` -------------------------------- ### Rust Main Function for Bin Crate Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/bin_crate/bin_crate.txt This Rust code defines the main function for a binary crate. It parses command-line arguments to control execution flow within a match statement. Ensure arguments are provided and parsable as u8. ```rust fn main() { match std::env::args().skip(1).next().unwrap().parse::().unwrap() { 0 => {} 1 => {} 2 => {} _ => {} } } ``` -------------------------------- ### func2 Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/exclude-from-report1.hide-instantiations.txt A function that takes a u32 input and performs a match operation, with associated tests. ```APIDOC ## pub fn func2(x: u32) ### Description This function takes an unsigned 32-bit integer `x` and performs a match operation on its value. It is also used in tests. ### Parameters * **x** (u32) - The input value for the match operation. ### Tests This function is tested with calls to `func2(0)` and `func2(2)`. ``` -------------------------------- ### func2 Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package3.hide-instantiations.txt A function named func2 that takes a u32 argument. ```APIDOC ## func2 ### Description This function takes a single unsigned 32-bit integer argument `x` and performs a match operation on it. ### Signature `pub fn func2(x: u32)` ``` -------------------------------- ### func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package3.txt A function that takes a u32 argument and performs a match operation. ```APIDOC ## func(x: u32) ### Description This function accepts an unsigned 32-bit integer and executes a match statement based on its value. ### Signature `pub fn func(x: u32)` ``` -------------------------------- ### func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/real1/package1.txt A public function named 'func' that accepts a u32 argument and performs a match operation. ```APIDOC ## func(x: u32) ### Description This function takes an unsigned 32-bit integer as input and executes different code blocks based on its value using a match statement. ### Signature `pub fn func(x: u32)` ### Parameters #### Path Parameters - **x** (u32) - Required - The input value for the match operation. ``` -------------------------------- ### func2 Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package3.txt A function that takes a u32 argument and performs a match operation. ```APIDOC ## func2(x: u32) ### Description This function accepts an unsigned 32-bit integer and executes a match statement based on its value. ### Signature `pub fn func2(x: u32)` ``` -------------------------------- ### Module: module Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/no_test/link_dead_code.hide-instantiations.txt This module contains the public function `func`. ```APIDOC ## pub fn func(x: u32) ### Description This function takes an unsigned 32-bit integer and performs a match operation. ### Signature `pub fn func(x: u32)` ### Parameters * **x** (u32) - The input value for the match operation. ``` -------------------------------- ### Module Functions Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/no_test/no_test.txt Exposes public functions from the module. ```APIDOC ## func(x: u32) ### Description A function that takes a u32 argument and performs a match operation. ### Signature `pub fn func(x: u32)` ### Parameters * **x** (u32) - The input unsigned 32-bit integer. ``` -------------------------------- ### GitHub Actions Workflow for Codecov Region Coverage (YAML) Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md This GitHub Actions workflow shows how to generate and upload region coverage reports to Codecov using `cargo-llvm-cov` with the `--codecov` flag. ```yaml - name: Generate code coverage run: cargo llvm-cov --all-features --workspace --codecov --output-path codecov.json - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} # required for private repos or protected branches files: codecov.json fail_ci_if_error: true ``` -------------------------------- ### Generate JSON Coverage Report Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md Generates a JSON formatted coverage report. The report is saved to the specified `--output-path` or printed to standard output if not specified. ```sh cargo llvm-cov --json --output-path cov.json ``` -------------------------------- ### func (member2/src/member4/src/lib.rs) Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package6.txt A function that takes an unsigned 32-bit integer and performs a match operation. ```APIDOC ## func (member2/src/member4/src/lib.rs) ### Description This function accepts a `u32` argument and uses a `match` statement to handle different values. ### Signature `pub fn func(x: u32)` ### Parameters - **x** (u32) - The input value for the match operation. ``` -------------------------------- ### member2/src/lib.rs - func2 Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package2.hide-instantiations.txt A function that takes a u32 and performs a match operation. ```APIDOC ## func2(x: u32) ### Description This function takes an unsigned 32-bit integer `x` and performs a `match` operation on its value. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **x** (u32) - Description of the parameter `x`. ``` -------------------------------- ### member2/member3/src/lib.rs: func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/exclude-from-report2.hide-instantiations.txt This function takes an unsigned 32-bit integer and performs a match operation. ```APIDOC ## member2/member3/src/lib.rs: func ### Description This function takes an unsigned 32-bit integer and performs a match operation. ### Signature `pub fn func(x: u32)` ### Example ```rust member2::member3::func(0); ``` ``` -------------------------------- ### member1/src/lib.rs: func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/exclude-from-report2.hide-instantiations.txt This function takes an unsigned 32-bit integer and performs a match operation. ```APIDOC ## member1/src/lib.rs: func ### Description This function takes an unsigned 32-bit integer and performs a match operation. ### Signature `pub fn func(x: u32)` ### Example ```rust member1::func(0); member1::func(1); member1::func(3); ``` ``` -------------------------------- ### member2/src/member4/src/lib.rs: func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/exclude-from-report2.hide-instantiations.txt This function takes an unsigned 32-bit integer and performs a match operation. ```APIDOC ## member2/src/member4/src/lib.rs: func ### Description This function takes an unsigned 32-bit integer and performs a match operation. ### Signature `pub fn func(x: u32)` ### Example ```rust member2::member4::func(0); ``` ``` -------------------------------- ### Pipe JSON Output to Another Program Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md This command demonstrates how to pipe the JSON output of cargo-llvm-cov directly to another program for processing. ```sh cargo-llvm-cov --json | some-program ``` -------------------------------- ### Rust Function with Match Statement Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/real1/manifest_path.txt This Rust function `func` takes a u32 argument and uses a match statement to handle different values. It is instrumented for coverage reporting, indicated by the line execution counts. ```rust 1| 0|pub fn func(x: u32) { 2| 0| match x { 3| 0| 0 => {} 4| 0| 1 => {} 5| 0| 2 => {} 6| 0| _ => {} 7| | } 8| 0|} ``` -------------------------------- ### func (member2/member3/src/lib.rs) Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package6.txt A function that takes an unsigned 32-bit integer and performs a match operation. ```APIDOC ## func (member2/member3/src/lib.rs) ### Description This function accepts a `u32` argument and uses a `match` statement to handle different values. ### Signature `pub fn func(x: u32)` ### Parameters - **x** (u32) - The input value for the match operation. ``` -------------------------------- ### Rust Function with Match Statement (func2) Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/exclude-from-report1.txt Defines a Rust function `func2` with a match statement, similar to `func` but with different coverage for specific cases. This demonstrates variations in function logic and their impact on coverage. ```rust pub fn func2(x: u32) { match x { 0 => {} 1 => {} 2 => {} _ => {} } } ``` -------------------------------- ### member1/src/lib.rs - func Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/virtual1/package2.hide-instantiations.txt A function that takes a u32 and performs a match operation. ```APIDOC ## func(x: u32) ### Description This function takes an unsigned 32-bit integer `x` and performs a `match` operation on its value. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **x** (u32) - Description of the parameter `x`. ``` -------------------------------- ### Rust Test Function with Feature Flags Source: https://github.com/taiki-e/cargo-llvm-cov/blob/main/tests/fixtures/coverage-reports/merge/clean_ws.txt Illustrates how to write unit tests in Rust that are conditionally compiled based on feature flags. This allows testing different code paths or behaviors. ```rust #[test] fn test() { #[cfg(feature = "a")] assert!(!func(1)); #[cfg(feature = "b")] assert!(func(-1)); } ```