Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changes/unreleased/spec-Added-20251229-105220.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
project: spec
kind: Added
body: Generate macro code coverage report for `ASPEC::Methods.assert_compiles`
time: 2025-12-29T10:52:20.27522588-05:00
custom:
Author: George Dietrich
PR: "642"
Username: blacksmoke16
20 changes: 16 additions & 4 deletions src/components/spec/src/methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,23 @@ module Athena::Spec::Methods
#
# NOTE: When files are required within the *code*, they are relative to the file calling this method.
def assert_compiles(code : String, *, line : Int32 = __LINE__, file : String = __FILE__) : Nil
buffer = IO::Memory.new
result = execute code, buffer, buffer, file, codegen: false
std_out = IO::Memory.new
std_err = IO::Memory.new

fail buffer.to_s, line: line unless result.success?
buffer.close
result = execute code, std_out, std_err, file, codegen: false, macro_code_coverage: true

fail std_err.to_s, line: line unless result.success?
std_err.close

# Ignore coverage report output if the output dir is not defined, or if there is no report.
# TODO: Maybe default this to something?
if !std_out.empty? && (macro_coverage_output_dir = ENV["ATHENA_SPEC_COVERAGE_OUTPUT_DIR"]?.presence)
File.open ::Path[macro_coverage_output_dir, "macro_coverage.#{Path[file].stem}:#{line}.codecov.json"], "w" do |coverage_report|
IO.copy std_out.rewind, coverage_report
end
end

std_out.close
end

# Similar to `.assert_runtime_error`, but asserts the provided Crystal *code* successfully executes.
Expand Down