Skip to content

Commit 7f98569

Browse files
committed
Add check prefixes.
1 parent 5a4487e commit 7f98569

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

test/helpers/test.jl

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ end
4141
module FileCheck
4242
import LLVM_jll
4343
import IOCapture
44+
using InteractiveUtils
4445

4546
export filecheck
4647

@@ -63,26 +64,46 @@ module FileCheck
6364
return Cmd(Cmd([filecheck_path]); env)
6465
end
6566

67+
const julia_typed_pointers = let
68+
ir = sprint(io->code_llvm(io, unsafe_load, Tuple{Ptr{Int}}))
69+
if occursin(r"load i64, i64\* .+, align 1", ir)
70+
true
71+
elseif occursin(r"load i64, ptr .+, align 1", ir)
72+
false
73+
else
74+
error("could not determine whether Julia uses typed pointers")
75+
end
76+
end
77+
6678
function filecheck(f, input)
6779
# FileCheck assumes that the input is available as a file
68-
path, io = mktemp()
69-
write(io, input)
70-
close(io)
80+
mktemp() do path, io
81+
write(io, input)
82+
close(io)
7183

72-
# Now execute `f` with IOCapture
73-
# XXX: See if Suppressor is a better fit
74-
value, output, error, backtrace = IOCapture.capture(()->f(input); rethrow=Union{})
84+
# Now execute `f` with IOCapture
85+
# XXX: See if Suppressor is a better fit
86+
value, output, error, backtrace = IOCapture.capture(()->f(input); rethrow=Union{})
7587

76-
io = IOBuffer()
77-
write(io, output)
78-
println(io)
88+
io = IOBuffer()
89+
write(io, output)
90+
println(io)
7991

80-
if error
81-
showerror(io, value, backtrace)
82-
end
92+
if error
93+
showerror(io, value, backtrace)
94+
end
8395

84-
seekstart(io)
85-
cmd = `$(filecheck_exe()) $path`
86-
value, success(pipeline(cmd; stdin=io, stdout, stderr))
96+
# Determine some useful prefixes for FileCheck
97+
prefixes = ["CHECK"]
98+
if julia_typed_pointers
99+
push!(prefixes, "OPAQUE")
100+
else
101+
push!(prefixes, "TYPED")
102+
end
103+
104+
seekstart(io)
105+
cmd = `$(filecheck_exe()) --allow-unused-prefixes --check-prefixes $(join(prefixes, ',')) $path`
106+
value, success(pipeline(cmd; stdin=io, stdout, stderr))
107+
end
87108
end
88-
end
109+
end

0 commit comments

Comments
 (0)