Skip to content

Commit c851860

Browse files
committed
add tests for building executable
1 parent b88bace commit c851860

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ sysimg
1414
*.dll
1515
hello
1616
hello.exe
17+
packages

src/api.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,19 @@ function build_executable(
6060

6161
snoopfile = nothing, builddir = "build",
6262
verbose = false, quiet = false,
63-
cpu_target = "native", optimize = nothing, debug = nothing,
63+
cpu_target = nothing, optimize = nothing, debug = nothing,
6464
inline = nothing, check_bounds = nothing, math_mode = nothing
6565
)
66+
if snoopfile != nothing
67+
precompfile = joinpath(builddir, "precompiled.jl")
68+
snoop(snoopfile, precompfile, joinpath(builddir, "snoop.csv"))
69+
jlmain = joinpath(builddir, "julia_main.jl")
70+
open(jlmain, "w") do io
71+
println(io, "include(\"$(escape_string(precompfile))\")")
72+
println(io, "include(\"$(escape_string(library))\")")
73+
end
74+
library = jlmain
75+
end
6676
julia_compile(
6777

6878
library, julia_program_basename = library_name,

test/runtests.jl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,42 @@ img_file = PackageCompiler.compile_package("Matcha", "UnicodeFun", force = false
2323
end
2424
end
2525

26+
2627
@testset "juliac" begin
2728
mktempdir() do build
2829
juliac = joinpath(@__DIR__, "..", "juliac.jl")
2930
jlfile = joinpath(@__DIR__, "..", "examples", "hello.jl")
3031
cfile = joinpath(@__DIR__, "..", "examples", "program.c")
31-
build = mktempdir()
3232
julia = Base.julia_cmd()
3333
@test success(`$julia $juliac -vosej $jlfile $cfile $build`)
3434
@test isfile(joinpath(build, "hello.$(Libdl.dlext)"))
3535
@test isfile(joinpath(build, "hello$(executable_ext())"))
3636
cd(build) do
37-
run(`./$("hello$(executable_ext())")`)
37+
@test success(`./$("hello$(executable_ext())")`)
3838
end
3939
end
4040
end
41+
42+
@testset "build_executable" begin
43+
build = mktempdir()
44+
jlfile = joinpath(@__DIR__, "..", "examples", "hello.jl")
45+
snoopfile = open(joinpath(build, "snoop.jl"), "w") do io
46+
write(io, open(read, jlfile))
47+
println(io)
48+
println(io, "using .Hello; Hello.julia_main(String[])")
49+
end
50+
build_executable(
51+
jlfile,
52+
snoopfile = snoopfile, builddir = build,
53+
verbose = false, quiet = false,
54+
)
55+
@test isfile(joinpath(build, "hello.$(Libdl.dlext)"))
56+
@test isfile(joinpath(build, "hello$(executable_ext())"))
57+
cd(build) do
58+
@test success(`./$("hello$(executable_ext())")`)
59+
end
60+
for i = 1:100
61+
try rm(build, recursive = true) end
62+
sleep(1/100)
63+
end
64+
end

0 commit comments

Comments
 (0)