Skip to content

Commit

Permalink
Error handling tests (#98)
Browse files Browse the repository at this point in the history
* Add simple core and integration test for new error handling code

* Bump version to 0.4.7
  • Loading branch information
brenhinkeller authored Mar 15, 2023
1 parent 7e4bbe4 commit 080181f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StaticCompiler"
uuid = "81625895-6c0f-48fc-b932-11a18313743c"
authors = ["Tom Short and contributors"]
version = "0.4.6"
version = "0.4.7"

[deps]
Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100"
Expand Down
15 changes: 15 additions & 0 deletions test/scripts/throw_errors.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using StaticCompiler
using StaticTools

function maybe_throw(argc::Int, argv::Ptr{Ptr{UInt8}})
printf(c"Argument count is %d:\n", argc)
argc > 1 || return printf(stderrp(), c"Too few command-line arguments\n")
n = argparse(Int64, argv, 2) # First command-line argument
printf((c"Input:\n", n, c"\n"))
printf(c"\nAttempting to represent input as UInt64:\n")
x = UInt64(n)
printf(x)
end

# Attempt to compile
path = compile_executable(maybe_throw, (Int64, Ptr{Ptr{UInt8}}), "./")
13 changes: 13 additions & 0 deletions test/testcore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ end
r = run(`$filepath Hello, world!`);
@test isa(r, Base.Process)
@test r.exitcode == 0

# Compile a function that definitely fails
@inline foo_err() = UInt64(-1)
filepath = compile_executable(print_args, (Int, Ptr{Ptr{UInt8}}), tempdir())
@test isfile(filepath)
status = -1
try
status = run(`filepath`)
catch
@info "foo_err: Task failed successfully!"
end
@test status === -1

end

@noinline square(n) = n*n
Expand Down
35 changes: 35 additions & 0 deletions test/testintegration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,41 @@
@test isa(status, Base.Process) && status.exitcode == 0
end

## --- Test error throwing

let
# Compile...
status = -1
try
isfile("maybe_throw") && rm("maybe_throw")
status = run(`$jlpath --startup=no --compile=min $testpath/scripts/throw_errors.jl`)
catch e
@warn "Could not compile $testpath/scripts/throw_errors.jl"
println(e)
end
@test isa(status, Base.Process)
@test isa(status, Base.Process) && status.exitcode == 0

# Run...
println("Error handling:")
status = -1
try
status = run(`./maybe_throw 10`)
catch e
@warn "Could not run $(scratch)/maybe_throw"
println(e)
end
@test isa(status, Base.Process)
@test isa(status, Base.Process) && status.exitcode == 0
status = -1
try
status = run(`./maybe_throw -10`)
catch e
@info "maybe_throw: task failed sucessfully!"
end
@test status === -1
end

## --- Test interop

@static if Sys.isbsd()
Expand Down

2 comments on commit 080181f

@brenhinkeller
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, it's been a while since we've released!

@JuliaRegistrator register

Release notes:

  • Some errors are now allowed in standalone executables (Thanks, @gbaraldi!!)
  • Updates to pointer patching
  • Bump compat on GPUCompiler to 0.17

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/79595

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.7 -m "<description of version>" 080181f40fa3c99d3efab3309d3e24f5988cb21b
git push origin v0.4.7

Please sign in to comment.