Skip to content

129tyc/coverage-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Language Test Coverage Project

This project demonstrates test coverage collection across multiple programming languages (TypeScript, Python, and C++), with support for both standardized LCOV format and native coverage reports.

Project Structure

.
├── ts/                 # TypeScript implementation
├── python/            # Python implementation
├── cpp/              # C++ implementation
├── lcov-reports/     # Standardized LCOV format reports
├── coverage-reports/ # Native format coverage reports
└── mock-diffs/      # Mock diff files for testing

Prerequisites

  • Node.js and npm (for TypeScript)
  • Python 3.x and pip (for Python)
  • CMake and a C++ compiler (for C++)
  • LCOV (for C++ coverage reports)

Coverage Report Generation

This project provides two different ways to generate coverage reports, each serving a different purpose:

1. Standardized LCOV Reports

Use generate_lcov_reports.sh to generate standardized LCOV format reports for parsing and analysis:

./generate_lcov_reports.sh

This script:

  • Runs tests for each language
  • Generates coverage data in LCOV format
  • Collects all reports in the lcov-reports/ directory:
    • lcov-reports/typescript.lcov
    • lcov-reports/python.lcov
    • lcov-reports/cpp.lcov

These reports are standardized for:

  • Automated parsing and analysis
  • Cross-language coverage comparison
  • Integration with CI/CD systems
  • Use with LCOV-compatible tools

2. Detailed Native Reports

Use generate_coverage_reports.sh to generate detailed coverage reports in each language's native format:

./generate_coverage_reports.sh

This script:

  • Runs tests for each language
  • Generates comprehensive coverage reports in native formats
  • Creates HTML reports and summaries
  • Saves all reports in coverage-reports/<language>/:
    • TypeScript: Jest coverage reports
    • Python: pytest-cov reports
    • C++: gcov/lcov detailed reports

These reports are useful for:

  • Detailed code coverage analysis
  • Interactive HTML report viewing
  • Language-specific coverage features
  • Development and debugging

Language-Specific Reports

Each language can also generate reports independently:

TypeScript

cd ts
npm install
npm run test:report  # Generates detailed Jest coverage reports

Python

cd python
./test_coverage.sh  # Generates pytest-cov reports

C++

cd cpp
./test_coverage.sh  # Generates detailed gcov/lcov reports

Current Coverage Results

  • TypeScript: 100% (16/16 lines)
  • Python: 100% coverage
  • C++: 96.4% (27/28 lines)

Development

Adding New Tests

  1. Add your test files in the respective language directories
  2. Update the corresponding test scripts if needed
  3. Run both coverage scripts to verify:
    • ./generate_lcov_reports.sh for standardized LCOV reports
    • ./generate_coverage_reports.sh for detailed native reports

Mock Diffs

The mock-diffs/ directory contains sample diff files for testing LCOV parsing:

  • typescript.diff
  • python.diff
  • cpp.diff

Notes

  • The project maintains two types of coverage reports:
    1. Standardized LCOV format (lcov-reports/) for automated processing
    2. Native format reports (coverage-reports/) for detailed analysis
  • Each language uses its standard testing framework:
    • TypeScript: Jest
    • Python: pytest with pytest-cov
    • C++: Google Test with gcov/lcov
  • All LCOV format reports are normalized for consistent parsing
  • Native reports provide additional language-specific insights

Test Coverage

Each project contains identical test cases to verify the following coverage types:

  1. Function Coverage

    • Basic addition function
  2. Branch Coverage

    • Division function (including division by zero error handling)
  3. Anonymous Function/Lambda Coverage

    • Number processing function (with custom processor support)
  4. Line and Complex Branch Coverage

    • Grade calculation function (multiple conditional branches)

Running Individual Projects

If you want to run tests for a specific project, follow these steps:

TypeScript Project

cd ts
npm install
npm test

Python Project

cd python
python3 -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate
pip install -r requirements.txt
pytest --cov=. --cov-report=lcov
deactivate

C++ Project

cd cpp
mkdir -p build
cd build
cmake ..
make
./calculator_test
lcov --capture --directory . --output-file coverage.lcov

Important Notes

  1. Ensure you have the necessary permissions to run run_tests.sh (you may need to run chmod +x run_tests.sh)
  2. Some systems may require additional development tools and compilers
  3. System-level dependencies might require sudo privileges to install

Project Features

Each project implements a Calculator class with the following features:

  1. Basic arithmetic operations

    • Addition (function coverage example)
    • Division (branch coverage example)
  2. Advanced functionality

    • Number processing with custom lambda functions
    • Grade calculation with multiple branches
  3. Comprehensive test coverage

    • Unit tests for all functions
    • Edge case handling
    • Error condition testing

Troubleshooting

If you encounter any issues:

  1. Verify all required dependencies are installed
  2. Check system permissions
  3. Ensure all build tools are properly configured
  4. For Python virtual environment issues, try recreating the venv

Contributing

Feel free to contribute to this project by:

  • Adding support for more programming languages
  • Enhancing test coverage
  • Improving build scripts
  • Updating documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors