Skip to content

Commit a678d0e

Browse files
committed
Collect checks in source order.
1 parent 6c499d0 commit a678d0e

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FileCheck"
22
uuid = "4e644321-382b-4b05-b0b6-5d23c3d944fb"
33
authors = ["Tim Besard <tim.besard@gmail.com>"]
4-
version = "1.1.1"
4+
version = "1.1.2"
55

66
[deps]
77
LLVM_jll = "86de99a1-58d6-5da7-8064-bd56ce2e322c"

src/FileCheck.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,25 @@ for (macro_sym, _) in CHECK_MACROS
159159
end
160160

161161
# Walk the AST recursively, collecting @check* macrocall nodes and removing them from blocks.
162+
# For blocks, we process args left-to-right: collect a @check* or recurse into the child.
163+
# This preserves source order even when checks appear at multiple nesting levels.
162164
function extract_checks!(ex, collected::Vector{Tuple{Any,Bool,String,Any}})
163165
ex isa Expr || return ex
164166

165-
# Recurse into sub-expressions first (depth-first to collect in source order)
166-
for i in eachindex(ex.args)
167-
ex.args[i] = extract_checks!(ex.args[i], collected)
168-
end
169-
170-
# Strip @check* calls from blocks
171167
if Meta.isexpr(ex, :block)
172-
filter!(ex.args) do arg
168+
kept = Any[]
169+
for arg in ex.args
173170
if Meta.isexpr(arg, :macrocall) && haskey(CHECK_MACROS, arg.args[1])
174171
collect_check!(arg, collected)
175-
return false
172+
else
173+
push!(kept, extract_checks!(arg, collected))
176174
end
177-
true
175+
end
176+
empty!(ex.args)
177+
append!(ex.args, kept)
178+
else
179+
for i in eachindex(ex.args)
180+
ex.args[i] = extract_checks!(ex.args[i], collected)
178181
end
179182
end
180183
return ex

test/runtests.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,19 @@ end
396396
end
397397
end
398398

399+
@testset "source order with nested checks" begin
400+
# checks at different nesting levels must be collected in source order,
401+
# not depth-first (which would put the nested "second" before "first")
402+
@test @filecheck begin
403+
@check "first"
404+
println("first")
405+
if true
406+
@check "second"
407+
println("second")
408+
end
409+
@check "third"
410+
println("third")
411+
end
412+
end
413+
399414
end # @testset "FileCheck"

0 commit comments

Comments
 (0)