Files
cherrypick/cherrypick_generator/coverage_analysis.py
Sergey Penkovsky 5220ebc4b9 feat(generator): complete code generation testing framework with 100% test coverage
BREAKING CHANGE: Updated file extensions and dependencies for better compatibility

## 🎯 Major Features Added:
-  Complete test suite for ModuleGenerator (66 integration tests)
-  Complete test suite for InjectGenerator (66 integration tests)
-  Comprehensive unit tests for BindSpec, MetadataUtils
-  195 total tests across all packages (100% passing)

## 🔧 Technical Improvements:
- feat(generator): add comprehensive integration tests for code generation
- feat(generator): implement BindSpec unit tests with full coverage
- feat(generator): add MetadataUtils unit tests for annotation processing
- fix(generator): update file extensions to avoid conflicts (.module.cherrypick.g.dart)
- fix(generator): correct part directive generation in templates
- fix(generator): resolve dart_style 3.x formatting compatibility

## 📦 Dependencies & Configuration:
- build(deps): upgrade analyzer to ^7.0.0 for Dart 3.5+ compatibility
- build(deps): upgrade dart_style to ^3.0.0 for modern formatting
- build(deps): upgrade source_gen to ^2.0.0 for latest features
- config(build): update build.yaml with new file extensions
- config(melos): optimize test commands for better performance

## 🐛 Bug Fixes:
- fix(examples): correct local package paths in client_app and postly
- fix(analysis): exclude generated files from static analysis
- fix(generator): remove unused imports and variables
- fix(tests): add missing part directives in test input files
- fix(tests): update expected outputs to match dart_style 3.x format

## 🚀 Performance & Quality:
- perf(tests): optimize test execution time (132 tests in ~1 second)
- quality: achieve 100% test coverage for code generation
- quality: eliminate all analyzer warnings and errors
- quality: ensure production-ready stability

## 📋 Test Coverage Summary:
- cherrypick: 61 tests 
- cherrypick_annotations: 1 test 
- cherrypick_generator: 132 tests 
- cherrypick_flutter: 1 test 
- Total: 195 tests (100% passing)

## 🔄 Compatibility:
-  Dart SDK 3.5.2+
-  Flutter 3.24+
-  melos + fvm workflow
-  build_runner integration
-  Modern analyzer and formatter

This commit establishes CherryPick as a production-ready dependency injection
framework with enterprise-grade testing and code generation capabilities.
2025-06-11 18:34:19 +03:00

138 lines
5.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Анализ покрытия тестами для CherryPick Generator
"""
import re
import os
def analyze_lcov_file(lcov_path):
"""Анализирует LCOV файл и возвращает статистику покрытия"""
if not os.path.exists(lcov_path):
print(f"❌ LCOV файл не найден: {lcov_path}")
return
with open(lcov_path, 'r') as f:
content = f.read()
# Разбиваем на секции по файлам
file_sections = content.split('SF:')[1:] # Убираем первую пустую секцию
total_lines = 0
total_hit = 0
files_coverage = {}
for section in file_sections:
lines = section.strip().split('\n')
if not lines:
continue
file_path = lines[0]
file_name = os.path.basename(file_path)
# Подсчитываем строки
da_lines = [line for line in lines if line.startswith('DA:')]
file_total = len(da_lines)
file_hit = 0
for da_line in da_lines:
# DA:line_number,hit_count
parts = da_line.split(',')
if len(parts) >= 2:
hit_count = int(parts[1])
if hit_count > 0:
file_hit += 1
if file_total > 0:
coverage_percent = (file_hit / file_total) * 100
files_coverage[file_name] = {
'total': file_total,
'hit': file_hit,
'percent': coverage_percent
}
total_lines += file_total
total_hit += file_hit
# Общая статистика
overall_percent = (total_hit / total_lines) * 100 if total_lines > 0 else 0
print("📊 АНАЛИЗ ПОКРЫТИЯ ТЕСТАМИ CHERRYPICK GENERATOR")
print("=" * 60)
print(f"\n🎯 ОБЩАЯ СТАТИСТИКА:")
print(f" Всего строк кода: {total_lines}")
print(f" Покрыто тестами: {total_hit}")
print(f" Общее покрытие: {overall_percent:.1f}%")
print(f"\n📁 ПОКРЫТИЕ ПО ФАЙЛАМ:")
# Сортируем по проценту покрытия
sorted_files = sorted(files_coverage.items(), key=lambda x: x[1]['percent'], reverse=True)
for file_name, stats in sorted_files:
percent = stats['percent']
hit = stats['hit']
total = stats['total']
# Эмодзи в зависимости от покрытия
if percent >= 80:
emoji = ""
elif percent >= 50:
emoji = "🟡"
else:
emoji = ""
print(f" {emoji} {file_name:<25} {hit:>3}/{total:<3} ({percent:>5.1f}%)")
print(f"\n🏆 РЕЙТИНГ КОМПОНЕНТОВ:")
# Группируем по типам компонентов
core_files = ['bind_spec.dart', 'bind_parameters_spec.dart', 'generated_class.dart']
utils_files = ['metadata_utils.dart']
generator_files = ['module_generator.dart', 'inject_generator.dart']
def calculate_group_coverage(file_list):
group_total = sum(files_coverage.get(f, {}).get('total', 0) for f in file_list)
group_hit = sum(files_coverage.get(f, {}).get('hit', 0) for f in file_list)
return (group_hit / group_total * 100) if group_total > 0 else 0
core_coverage = calculate_group_coverage(core_files)
utils_coverage = calculate_group_coverage(utils_files)
generators_coverage = calculate_group_coverage(generator_files)
print(f" 🔧 Core Components: {core_coverage:>5.1f}%")
print(f" 🛠️ Utils: {utils_coverage:>5.1f}%")
print(f" ⚙️ Generators: {generators_coverage:>5.1f}%")
print(f"\n📈 РЕКОМЕНДАЦИИ:")
# Файлы с низким покрытием
low_coverage = [(f, s) for f, s in files_coverage.items() if s['percent'] < 50]
if low_coverage:
print(" 🎯 Приоритет для улучшения:")
for file_name, stats in sorted(low_coverage, key=lambda x: x[1]['percent']):
print(f"{file_name} ({stats['percent']:.1f}%)")
# Файлы без покрытия
zero_coverage = [(f, s) for f, s in files_coverage.items() if s['percent'] == 0]
if zero_coverage:
print(" ❗ Требуют срочного внимания:")
for file_name, stats in zero_coverage:
print(f"{file_name} (0% покрытия)")
print(f"\n✨ ДОСТИЖЕНИЯ:")
high_coverage = [(f, s) for f, s in files_coverage.items() if s['percent'] >= 80]
if high_coverage:
print(" 🏅 Отлично протестированы:")
for file_name, stats in sorted(high_coverage, key=lambda x: x[1]['percent'], reverse=True):
print(f"{file_name} ({stats['percent']:.1f}%)")
return files_coverage, overall_percent
if __name__ == "__main__":
lcov_path = "coverage/lcov.info"
analyze_lcov_file(lcov_path)