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
2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 |
# File 'lib/kettle/jem.rb', line 2507 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
2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 |
# File 'lib/kettle/jem.rb', line 2524 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
2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 |
# File 'lib/kettle/jem.rb', line 2446 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
2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 |
# File 'lib/kettle/jem.rb', line 2459 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 |