Skip to content

Commit a209625

Browse files
committed
Allow the use of FileCheck
1 parent 772a78c commit a209625

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
33
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
44
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
5+
IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
56
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
67
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
8+
LLVM_jll = "86de99a1-58d6-5da7-8064-bd56ce2e322c"
79
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
810
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
911
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

test/helpers/test.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,55 @@ end
3535
ret i64 %value"""
3636
return :(Base.llvmcall($llvmcall_str, T, Tuple{T}, i))
3737
end
38+
39+
# filecheck utils
40+
41+
module FileCheck
42+
import LLVM_jll
43+
import IOCapture
44+
45+
export filecheck
46+
47+
global filecheck_path::String
48+
function __init__()
49+
# TODO: Windows
50+
global filecheck_path = joinpath(LLVM_jll.artifact_dir, "tools", "FileCheck")
51+
end
52+
53+
function filecheck_exe(; adjust_PATH::Bool=true, adjust_LIBPATH::Bool=true)
54+
env = Base.invokelatest(
55+
LLVM_jll.JLLWrappers.adjust_ENV!,
56+
copy(ENV),
57+
LLVM_jll.PATH[],
58+
LLVM_jll.LIBPATH[],
59+
adjust_PATH,
60+
adjust_LIBPATH
61+
)
62+
63+
return Cmd(Cmd([filecheck_path]); env)
64+
end
65+
66+
function filecheck(f, input)
67+
# FileCheck assumes that the input is available as a file
68+
path, io = mktemp()
69+
write(io, input)
70+
close(io)
71+
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{})
75+
76+
@show error
77+
io = IOBuffer()
78+
write(io, output)
79+
println(io)
80+
81+
if error
82+
showerror(io, value, backtrace)
83+
end
84+
85+
seekstart(io)
86+
cmd = `$(filecheck_exe()) $path`
87+
value, success(pipeline(cmd; stdin=io, stdout, stderr))
88+
end
89+
end

test/setup.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ for file in readdir(joinpath(@__DIR__, "helpers"))
99
include(joinpath(@__DIR__, "helpers", file))
1010
end
1111
end
12+
using .FileCheck
1213

1314

1415
## entry point

test/utils.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ end
9292
@test occursin(ansi_color, highlighted) skip = !can_highlight
9393
end
9494
end
95+
96+
# Test FileCheck
97+
_, success = filecheck(_->println("works"), "# CHECK: works")
98+
@test success
99+
100+
_, success = filecheck(_->@assert(false),
101+
"""
102+
; CHECK: AssertionError: false
103+
; CHECK-NEXT: Stacktrace:
104+
""")
105+
@test success

0 commit comments

Comments
 (0)