Skip to content

Commit 080181f

Browse files
Error handling tests (#98)
* Add simple core and integration test for new error handling code * Bump version to 0.4.7
1 parent 7e4bbe4 commit 080181f

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StaticCompiler"
22
uuid = "81625895-6c0f-48fc-b932-11a18313743c"
33
authors = ["Tom Short and contributors"]
4-
version = "0.4.6"
4+
version = "0.4.7"
55

66
[deps]
77
Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100"

test/scripts/throw_errors.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using StaticCompiler
2+
using StaticTools
3+
4+
function maybe_throw(argc::Int, argv::Ptr{Ptr{UInt8}})
5+
printf(c"Argument count is %d:\n", argc)
6+
argc > 1 || return printf(stderrp(), c"Too few command-line arguments\n")
7+
n = argparse(Int64, argv, 2) # First command-line argument
8+
printf((c"Input:\n", n, c"\n"))
9+
printf(c"\nAttempting to represent input as UInt64:\n")
10+
x = UInt64(n)
11+
printf(x)
12+
end
13+
14+
# Attempt to compile
15+
path = compile_executable(maybe_throw, (Int64, Ptr{Ptr{UInt8}}), "./")

test/testcore.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,19 @@ end
291291
r = run(`$filepath Hello, world!`);
292292
@test isa(r, Base.Process)
293293
@test r.exitcode == 0
294+
295+
# Compile a function that definitely fails
296+
@inline foo_err() = UInt64(-1)
297+
filepath = compile_executable(print_args, (Int, Ptr{Ptr{UInt8}}), tempdir())
298+
@test isfile(filepath)
299+
status = -1
300+
try
301+
status = run(`filepath`)
302+
catch
303+
@info "foo_err: Task failed successfully!"
304+
end
305+
@test status === -1
306+
294307
end
295308

296309
@noinline square(n) = n*n

test/testintegration.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,41 @@
242242
@test isa(status, Base.Process) && status.exitcode == 0
243243
end
244244

245+
## --- Test error throwing
246+
247+
let
248+
# Compile...
249+
status = -1
250+
try
251+
isfile("maybe_throw") && rm("maybe_throw")
252+
status = run(`$jlpath --startup=no --compile=min $testpath/scripts/throw_errors.jl`)
253+
catch e
254+
@warn "Could not compile $testpath/scripts/throw_errors.jl"
255+
println(e)
256+
end
257+
@test isa(status, Base.Process)
258+
@test isa(status, Base.Process) && status.exitcode == 0
259+
260+
# Run...
261+
println("Error handling:")
262+
status = -1
263+
try
264+
status = run(`./maybe_throw 10`)
265+
catch e
266+
@warn "Could not run $(scratch)/maybe_throw"
267+
println(e)
268+
end
269+
@test isa(status, Base.Process)
270+
@test isa(status, Base.Process) && status.exitcode == 0
271+
status = -1
272+
try
273+
status = run(`./maybe_throw -10`)
274+
catch e
275+
@info "maybe_throw: task failed sucessfully!"
276+
end
277+
@test status === -1
278+
end
279+
245280
## --- Test interop
246281

247282
@static if Sys.isbsd()

0 commit comments

Comments
 (0)