### Install Bashcov with Bundler Source: https://github.com/infertux/bashcov/blob/master/INSTALL.md Installs Bashcov using Bundler, a Ruby environment manager. This involves adding 'gem "bashcov"' to a Gemfile, running 'bundle install', and then executing Bashcov with 'bundle exec'. ```ruby source 'https://rubygems.org' gem 'bashcov' ``` ```shell $ bundle install $ bundle exec bashcov -- ``` -------------------------------- ### Full Bashcov Integration Example in Ruby Source: https://context7.com/infertux/bashcov/llms.txt A comprehensive example demonstrating the integration of Bashcov into a Ruby application or test framework. It configures Bashcov options and sets up the environment for coverage analysis. ```ruby #!/usr/bin/env ruby require "bashcov" require "bashcov/runner" require "simplecov" Bashcov.set_default_options! Bashcov.skip_uncovered = true Bashcov.mute = false Bashcov.root_directory = File.expand_path("../", __FILE__) ``` -------------------------------- ### Install Bashcov with Ruby Gem Source: https://github.com/infertux/bashcov/blob/master/INSTALL.md Installs Bashcov as a Ruby gem using the 'gem install' command. This method requires Ruby and development tools. After installation, Bashcov can be run directly from the command line. ```shell $ gem install bashcov $ bashcov -- ``` -------------------------------- ### Install Bashcov with Bundler Source: https://context7.com/infertux/bashcov/llms.txt Manages Bashcov as a project-specific dependency using Bundler. Add the gem to your Gemfile, install dependencies, and then execute Bashcov via Bundler. ```ruby source 'https://rubygems.org' gem 'bashcov' ``` ```bash bundle install bundle exec bashcov -- ./your_script.sh ``` -------------------------------- ### Install Bashcov using RubyGems Source: https://context7.com/infertux/bashcov/llms.txt Installs Bashcov globally using the RubyGems package manager. This command also installs SimpleCov as a dependency. It's followed by a verification step. ```bash gem install bashcov bashcov --version ``` -------------------------------- ### Run Bashcov with Nix Source: https://github.com/infertux/bashcov/blob/master/INSTALL.md Executes Bashcov directly using the Nix package manager without prior installation. This command uses 'nix run' to fetch and execute Bashcov from its GitHub repository. ```shell $ nix run 'github:infertux/bashcov' -- ``` -------------------------------- ### Add Bashcov to Nix Shell Environment Source: https://github.com/infertux/bashcov/blob/master/INSTALL.md Starts a new shell environment with Bashcov available using the 'nix shell' command. This command fetches Bashcov from its GitHub repository and makes it accessible within the new shell session. ```shell $ nix shell 'github:infertux/bashcov' ``` -------------------------------- ### Run Bashcov with Nix Package Manager Source: https://context7.com/infertux/bashcov/llms.txt Executes Bashcov without explicit installation using Nix, or integrates it into a Nix flake for reproducible development environments. Demonstrates direct execution and shell activation. ```bash # Run Bashcov directly without installation nix run 'github:infertux/bashcov' -- ./your_script.sh # Start a shell with Bashcov available nix shell 'github:infertux/bashcov' bashcov --version ``` ```nix # flake.nix - Incorporate Bashcov into your Nix flake { inputs = { bashcov.url = "github:infertux/bashcov"; bashcov.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = inputs @ { nixpkgs, bashcov, ... }: let system = "x86_64-linux"; in { devShells.${system}.default = nixpkgs.legacyPackages.${system}.mkShell { packages = [inputs.bashcov.packages.${system}.bashcov]; }; }; } ``` -------------------------------- ### Incorporate Bashcov into Nix Flake Source: https://github.com/infertux/bashcov/blob/master/INSTALL.md Integrates Bashcov into a Nix flake project by declaring it as an input. This example shows how to add Bashcov to a 'nix develop' environment, making the 'bashcov' command available when 'nix develop' is run. ```nix # flake.nix { inputs = { bashcov.url = "github:infertux/bashcov"; bashcov.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = inputs @ { nixpkgs, bashcov, ... }: let system = "x86_64-linux"; in { devShells.${system}.default = nixpkgs.legacyPackages.${system}.mkShell { packages = [inputs.bashcov.packages.${system}.bashcov]; }; }; } ``` -------------------------------- ### Bashcov Custom Bash Path Option Source: https://context7.com/infertux/bashcov/llms.txt Specifies an alternative Bash interpreter path for testing against specific Bash versions or custom installations. ```bash # Use a specific Bash version bashcov --bash-path /usr/local/bin/bash-5.2 ./test_suite.sh # Test with Homebrew-installed Bash on macOS bashcov --bash-path /opt/homebrew/bin/bash ./test_suite.sh ``` -------------------------------- ### Execute Bash Script and Generate Coverage Report Source: https://context7.com/infertux/bashcov/llms.txt This snippet demonstrates how to initialize a Bashcov runner, execute a shell script, and configure SimpleCov to generate a formatted HTML coverage report. ```ruby command = [Bashcov.bash_path, "./test_suite.sh", "--verbose"] runner = Bashcov::Runner.new(command) status = runner.run coverage = runner.result SimpleCov.start do add_filter "/vendor/" add_group "Scripts", /\.sh$/ end SimpleCov.command_name "ruby-integration" SimpleCov.root Bashcov.root_directory result = SimpleCov::Result.new(coverage) if SimpleCov.use_merging SimpleCov::ResultMerger.store_result(result) result = SimpleCov::ResultMerger.merged_result end result.format! puts "Coverage report generated at coverage/index.html" ``` -------------------------------- ### Basic SimpleCov Configuration Source: https://context7.com/infertux/bashcov/llms.txt Configures basic SimpleCov settings like minimum coverage threshold and refusing coverage drops. It also sets up custom filters to exclude specific directories from coverage reports. ```ruby SimpleCov.start do minimum_coverage 80 refuse_coverage_drop add_filter '/vendor/' add_filter '/spec/' add_filter '/test/' end ``` -------------------------------- ### SimpleCov File Grouping Configuration Source: https://context7.com/infertux/bashcov/llms.txt Demonstrates how to use SimpleCov groups to organize coverage results by file type, directory, or custom patterns. This helps in categorizing coverage for different parts of the project. ```ruby SimpleCov.add_group "Bash Scripts", /\.sh$/ SimpleCov.add_group "Nested scripts", "/nested" SimpleCov.add_group "Utilities", "/utils/" SimpleCov.add_group "Core", "/lib/" ``` -------------------------------- ### Basic Bashcov Usage for Coverage Reports Source: https://context7.com/infertux/bashcov/llms.txt Executes a Bash script and generates HTML coverage reports in the `coverage/` directory. Includes a command to open the generated report in a web browser. ```bash # Basic execution - runs script and generates coverage report bashcov ./test_suite.sh # View the generated report open ./coverage/index.html ``` -------------------------------- ### Bashcov Command-Line for Merging Results Source: https://context7.com/infertux/bashcov/llms.txt Shows how to run multiple test suites using bashcov with distinct command names. The results from these runs are automatically merged into a single coverage report. ```bash bashcov --command-name "unit-tests" -- ./tests/unit/run.sh bashcov --command-name "integration-tests" -- ./tests/integration/run.sh bashcov --command-name "e2e-tests" -- ./tests/e2e/run.sh ``` -------------------------------- ### Calculate Coverage Percentage Programmatically Source: https://context7.com/infertux/bashcov/llms.txt This snippet shows how to access the raw coverage data returned by the runner and calculate the percentage of covered lines for a specific script. ```ruby coverage = runner.result script_coverage = coverage["/path/to/example.sh"] relevant_lines = script_coverage.compact covered_lines = relevant_lines.count { |hits| hits > 0 } coverage_percent = (covered_lines.to_f / relevant_lines.count * 100).round(2) puts "Coverage: #{coverage_percent}%" ``` -------------------------------- ### Bashcov Module Configuration Source: https://context7.com/infertux/bashcov/llms.txt Configures global Bashcov settings programmatically to control coverage behavior and environment paths. ```APIDOC ## Bashcov Module Configuration ### Description Configures global settings for the Bashcov module, including root directories, bash paths, and coverage reporting flags. ### Method N/A (Module Configuration) ### Parameters - **Bashcov.skip_uncovered** (boolean) - Optional - If true, skips reporting on files with zero coverage. - **Bashcov.mute** (boolean) - Optional - If true, suppresses output from the bash process. - **Bashcov.root_directory** (string) - Optional - Sets the base directory for the project. ### Request Example ```ruby require "bashcov" Bashcov.skip_uncovered = true Bashcov.root_directory = "/path/to/project" ``` ``` -------------------------------- ### Bashcov Module Configuration in Ruby Source: https://context7.com/infertux/bashcov/llms.txt Provides programmatic access to Bashcov configuration options within a Ruby environment. It allows setting options like skipping uncovered lines, muting output, and specifying root directory and bash path. ```ruby require "bashcov" Bashcov.skip_uncovered = true Bashcov.mute = false Bashcov.root_directory = "/path/to/project" Bashcov.bash_path = "/bin/bash" puts Bashcov.fullname puts Bashcov.bash_version ``` -------------------------------- ### Bashcov Custom Root Directory Option Source: https://context7.com/infertux/bashcov/llms.txt Sets a custom project root directory to control which files are included in the coverage analysis. Useful for non-standard project structures. ```bash # Set custom project root bashcov --root /path/to/project ./tests/run_all.sh # Combined with other options bashcov --root ~/myproject --skip-uncovered -- ./tests/test_suite.sh ``` -------------------------------- ### Bashcov::Runner Class Source: https://context7.com/infertux/bashcov/llms.txt Executes Bash scripts with xtrace enabled to collect and process coverage data. ```APIDOC ## Bashcov::Runner Class ### Description The Runner class is responsible for executing shell scripts and collecting line-by-line coverage data. ### Method POST (Logical execution) ### Parameters - **command** (array) - Required - The command and arguments to execute. ### Response - **result** (hash) - A hash mapping file paths to arrays of hit counts (nil for non-executable lines, 0 for uncovered, 1+ for hits). ### Response Example ```ruby { "/path/to/script.sh" => [nil, 1, 1, nil, 0, 1] } ``` ``` -------------------------------- ### Bashcov::Runner Class for Script Execution Source: https://context7.com/infertux/bashcov/llms.txt The Bashcov::Runner class executes Bash scripts with xtrace enabled and collects coverage data. It allows creating a runner instance, executing a script, retrieving coverage results, and checking the exit status. ```ruby require "bashcov" require "bashcov/runner" Bashcov.root_directory = Dir.pwd runner = Bashcov::Runner.new(["/bin/bash", "./test_suite.sh"]) status = runner.run coverage = runner.result puts "Exit code: #{status.exitstatus}" coverage.each do |file, lines| covered = lines.compact.count { |hits| hits > 0 } total = lines.compact.count puts "#{File.basename(file)}: #{covered}/#{total} lines covered" end ``` -------------------------------- ### SimpleCov Tracking Specific Files Source: https://context7.com/infertux/bashcov/llms.txt Configures SimpleCov to ensure specific files or patterns are always included in coverage analysis, even if they are not directly executed. This is combined with filters to exclude certain files. ```ruby SimpleCov.configure do track_files "lib/**/*.sh" track_files "bin/*" add_filter "/test/" end ``` -------------------------------- ### Bashcov::Lexer Class for Coverage Analysis Source: https://context7.com/infertux/bashcov/llms.txt The Bashcov::Lexer class analyzes Bash source files to determine which lines are relevant for coverage reporting. It processes initial coverage data and marks comments, function declarations, and control structures as irrelevant. ```ruby require "bashcov/lexer" coverage = [nil, nil, 1, 1, nil, 0, 1] lexer = Bashcov::Lexer.new("/path/to/script.sh", coverage) lexer.complete_coverage ``` -------------------------------- ### Bashcov Skip Uncovered Files Option Source: https://context7.com/infertux/bashcov/llms.txt Excludes files that were never executed from the coverage report, focusing only on files that were actually run. Useful for large projects to streamline reports. ```bash # Only report coverage for files that were executed bashcov --skip-uncovered ./test_suite.sh # Useful for large projects where many scripts exist but only some are tested bashcov --skip-uncovered -- ./run_tests.sh --verbose ``` -------------------------------- ### Bashcov::Detective Class Source: https://context7.com/infertux/bashcov/llms.txt Identifies shell scripts based on shebang lines, file extensions, and syntax validation. ```APIDOC ## Bashcov::Detective Class ### Description Utility class to determine if a file is a valid shell script for coverage analysis. ### Methods - **shellscript?**(path) - Returns boolean if file is a shell script. - **shellscript_shebang?**(path) - Validates the shebang line. - **shellscript_extension?**(filename) - Checks for standard shell extensions (.sh). ### Response Example ```ruby detective = Bashcov::Detective.new("/bin/bash") detective.shellscript?("/path/to/script.sh") # => true ``` ``` -------------------------------- ### Bashcov Passing Flags to Scripts Source: https://context7.com/infertux/bashcov/llms.txt Uses `--` to separate Bashcov options from script arguments, enabling the passing of flags directly to the executed test script. ```bash # Pass arguments to your script bashcov -- ./test_suite.sh --verbose --filter unit # Complex example with all options bashcov --skip-uncovered --mute -- ./test_runner.sh --parallel 4 --format json ``` -------------------------------- ### SimpleCov Result Merging Configuration Source: https://context7.com/infertux/bashcov/llms.txt Enables result merging in SimpleCov to combine coverage data from multiple test suites or CI runs into a single report. It includes an option to set a merge timeout. ```ruby require "simplecov" SimpleCov.configure do use_merging true merge_timeout 3600 end ``` -------------------------------- ### Bashcov Custom Command Name Option Source: https://context7.com/infertux/bashcov/llms.txt Sets a custom name for SimpleCov result merging using the `--command-name` option or the `BASHCOV_COMMAND_NAME` environment variable for better result identification. ```bash # Set command name for result identification bashcov --command-name "unit-tests" -- ./unit_tests.sh bashcov --command-name "integration-tests" -- ./integration_tests.sh # Using environment variable BASHCOV_COMMAND_NAME="smoke-tests" bashcov ./smoke_tests.sh ``` -------------------------------- ### Bashcov::Detective Class for Script Identification Source: https://context7.com/infertux/bashcov/llms.txt The Bashcov::Detective class is used to identify whether files are shell scripts. It checks for shebang lines, file extensions, and performs syntax validation to determine script type. ```ruby require "bashcov/detective" detective = Bashcov::Detective.new("/bin/bash") detective.shellscript?("/path/to/script.sh") detective.shellscript_shebang?("/path/to/script.sh") detective.shellscript_extension?("deploy.sh") detective.shellscript_shebang_line?("#!/bin/bash") ``` -------------------------------- ### Bashcov Mute Script Output Option Source: https://context7.com/infertux/bashcov/llms.txt Suppresses all output from the executed script, displaying only Bashcov's final summary. Can be combined with other options for cleaner reporting. ```bash # Run silently without script output bashcov --mute ./noisy_test_suite.sh # Combine with skip-uncovered for clean output bashcov --mute --skip-uncovered ./test_suite.sh ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.