Module: Kettle::Jem::SelfTest::Reporter
- Defined in:
- lib/kettle/jem.rb
Class Method Summary collapse
- .append_self_test_table(lines, title, paths, status = nil) ⇒ Object
- .append_skipped_files(lines, skipped) ⇒ Object
- .diff(file_a, file_b) ⇒ Object
- .summary(comparison, output_dir:, templating_environment: nil, diff_count: nil, now: Time.now) ⇒ Object
Class Method Details
.append_self_test_table(lines, title, paths, status = nil) ⇒ Object
2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 |
# File 'lib/kettle/jem.rb', line 2556 def append_self_test_table(lines, title, paths, status = nil) return if paths.empty? lines << "## #{title} (#{paths.size})" lines << "" if status lines << "| File | Status |" lines << "|------|--------|" paths.each { |path| lines << "| #{path} | #{status} |" } else lines << "| File |" lines << "|------|" paths.each { |path| lines << "| #{path} |" } end lines << "" end |
.append_skipped_files(lines, skipped) ⇒ Object
2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 |
# File 'lib/kettle/jem.rb', line 2573 def append_skipped_files(lines, skipped) return if skipped.empty? lines << "" lines << '<details markdown="1">' lines << "<summary>Not Templated (#{skipped.size} files) - source-only files not produced by the template task</summary>" lines << "" lines << "These files are part of the gem source and are not expected to appear in the template output." lines << "" lines << "| File |" lines << "|------|" skipped.each { |path| lines << "| #{path} |" } lines << "" lines << "</details>" end |
.diff(file_a, file_b) ⇒ Object
2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 |
# File 'lib/kettle/jem.rb', line 2495 def diff(file_a, file_b) a = File.exist?(file_a.to_s) ? file_a.to_s : File::NULL b = File.exist?(file_b.to_s) ? file_b.to_s : File::NULL out, = Open3.capture2("diff", "-u", a, b) out rescue Errno::ENOENT a_lines = File.exist?(file_a.to_s) ? File.readlines(file_a) : [] b_lines = File.exist?(file_b.to_s) ? File.readlines(file_b) : [] return "" if a_lines == b_lines ["--- #{file_a}", "+++ #{file_b}", *a_lines.map { |line| "-#{line.chomp}" }, *b_lines.map { |line| "+#{line.chomp}" }].join("\n") + "\n" end |
.summary(comparison, output_dir:, templating_environment: nil, diff_count: nil, now: Time.now) ⇒ Object
2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 |
# File 'lib/kettle/jem.rb', line 2508 def summary(comparison, output_dir:, templating_environment: nil, diff_count: nil, now: Time.now) matched = comparison.fetch(:matched, []) changed = comparison.fetch(:changed, []) added = comparison.fetch(:added, []) removed = comparison.fetch(:removed, []) skipped = comparison.fetch(:skipped, []) diff_count = changed.size if diff_count.nil? total = matched.size + changed.size + added.size + removed.size score = total.zero? ? 0.0 : (matched.size.to_f / total * 100).round(1) divergence = (100.0 - score).round(1) lines = ["# Template Self-Test Report", ""] lines << "**Date**: #{now.iso8601}" lines << "**Output**: `#{output_dir}`" lines << "**Score**: #{score}% (#{matched.size}/#{total} files unchanged)" lines << "**Divergence**: #{divergence}% (#{changed.size + added.size + removed.size}/#{total} files changed, added, or missing)" lines << "" environment_section = Kettle::Jem::TemplatingReport.markdown_section(snapshot: templating_environment) if templating_environment lines << environment_section if environment_section && !environment_section.empty? append_self_test_table(lines, "Changed Files", changed, "modified") append_self_test_table(lines, "New Files", added) if removed.any? lines << "## Not Templated - Unexpected (#{removed.size})" lines << "" lines << "These files exist in the source gem and appear to be within the template's" lines << "scope, but were not produced by the template task." lines << "" lines << "| File |" lines << "|------|" removed.each { |path| lines << "| #{path} |" } lines << "" end if changed.empty? && added.empty? && removed.empty? lines << "## All files match! :tada:" else lines << "## Detailed Diffs" lines << "" lines << if diff_count.to_i.positive? "See `report/diffs/` directory (#{diff_count} file#{"s" unless diff_count == 1})." else "No per-file diffs were generated for this run; `report/diffs/` is empty." end end append_skipped_files(lines, skipped) lines << "" lines.join("\n") end |