Skip to content

Commit

Permalink
Verify that Runic's output is parseable
Browse files Browse the repository at this point in the history
This doesn't cost much (5 % perf hit for some large files) and can catch
some errors. Note that it isn't possible/trivial to compare the trees
since the formatter make changes to it.
  • Loading branch information
fredrikekre committed Oct 18, 2024
1 parent 5500f9b commit 6212fdf
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Runic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,13 @@ function format_tree!(ctx::Context)
end
# Truncate the output at the root span
truncate(ctx.fmt_io, span(root′))
# Check that the output is parseable
try
fmt_str = String(read(seekstart(ctx.fmt_io)))
JuliaSyntax.parseall(JuliaSyntax.GreenNode, fmt_str; ignore_warnings = true, version = v"2-")
catch
throw(AssertionError("re-parsing the formatted output failed"))
end
# Set the final tree
ctx.fmt_tree = root′
return nothing
Expand Down

0 comments on commit 6212fdf

Please sign in to comment.