Skip to content

Commit f1dfdf6

Browse files
authored
Merge pull request #14 from NHDaly/testing
Separate out the build files for each example.
2 parents 7524d08 + e8f262f commit f1dfdf6

File tree

3 files changed

+54
-28
lines changed

3 files changed

+54
-28
lines changed

test/BuildApp.jl

+17-28
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
using Base.Test
22
using ApplicationBuilder; using BuildApp;
33

4-
examples_blink = joinpath(@__DIR__, "..", "examples", "blink.jl")
5-
examples_hello = joinpath(@__DIR__, "..", "examples", "hello.jl")
6-
74
builddir = mktempdir()
85
@assert isdir(builddir)
96

107
@testset "HelloWorld.app" begin
11-
@test 0 == BuildApp.build_app_bundle(examples_hello;
12-
verbose=true, appname="HelloWorld", builddir=builddir)
8+
@test 0 == include("build_examples/hello.jl")
139
@test isdir("$builddir/HelloWorld.app")
1410
@test success(`$builddir/HelloWorld.app/Contents/MacOS/hello`)
1511

@@ -25,33 +21,26 @@ builddir = mktempdir()
2521
end
2622
end
2723

24+
25+
function testRunAndKillProgramSucceeds(cmd)
26+
out, _, p = readandwrite(cmd) # Make sure it runs correctly
27+
sleep(1)
28+
process_exited(p) && (println("Test Failed: failed to launch: \n", readstring(out)); return false)
29+
sleep(10)
30+
process_exited(p) && (println("Test Failed: Process died: \n", readstring(out)); return false)
31+
# Manually kill program after it's been running for a bit.
32+
kill(p); sleep(1)
33+
process_exited(p) || (println("Test Failed: Process failed to exit: \n", readstring(out)); return false)
34+
return true
35+
end
36+
2837
@testset "HelloBlink.app" begin
29-
blinkPkg = Pkg.dir("Blink")
30-
httpParserPkg = Pkg.dir("HttpParser")
31-
mbedTLSPkg = Pkg.dir("MbedTLS")
32-
33-
@test 0 == BuildApp.build_app_bundle(examples_blink;
34-
verbose = true,
35-
resources = [joinpath(blinkPkg, "deps","Julia.app"),
36-
joinpath(blinkPkg, "src","AtomShell","main.js"),
37-
joinpath(blinkPkg, "src","content","main.html"),
38-
joinpath(blinkPkg, "res")],
39-
libraries = [joinpath(httpParserPkg, "deps","usr","lib","libhttp_parser.dylib"),
40-
joinpath(mbedTLSPkg, "deps","usr","lib","libmbedcrypto.2.dylib")],
41-
appname="HelloBlink", builddir=builddir)
38+
@test 0 == include("build_examples/blink.jl")
4239

4340
@test isdir("$builddir/HelloBlink.app")
4441
# Test that it copied the correct files
4542
@test isdir("$builddir/HelloBlink.app/Contents/Libraries")
4643
@test isfile("$builddir/HelloBlink.app/Contents/Resources/main.js")
47-
48-
# Manually kill HelloBlink, since it waits for user input.
49-
@async begin
50-
sleep(15) # wait til blink has started up
51-
run(`pkill blink`)
52-
end
53-
try # expect failure due to pkill, so not really much to test.
54-
run(`$builddir/HelloBlink.app/Contents/MacOS/blink`)
55-
end
56-
44+
# Test that it runs correctly
45+
@test testRunAndKillProgramSucceeds(`$builddir/HelloBlink.app/Contents/MacOS/blink`)
5746
end

test/build_examples/blink.jl

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using ApplicationBuilder; using BuildApp
2+
3+
examples_blink = joinpath(@__DIR__, "..", "..", "examples", "blink.jl")
4+
5+
# Allow this file to be called either as a standalone file to build the above
6+
# example, or from runtests.jl using a provided builddir.
7+
isdefined(:builddir) || (builddir=mktempdir())
8+
9+
blinkPkg = Pkg.dir("Blink")
10+
httpParserPkg = Pkg.dir("HttpParser")
11+
mbedTLSPkg = Pkg.dir("MbedTLS")
12+
13+
@assert blinkPkg != nothing "Blink is not installed!"
14+
15+
using Blink
16+
17+
BuildApp.build_app_bundle(examples_blink;
18+
verbose = true,
19+
resources = [joinpath(blinkPkg, "deps","Julia.app"),
20+
joinpath(blinkPkg, "src","AtomShell","main.js"),
21+
joinpath(blinkPkg, "src","content","main.html"),
22+
joinpath(blinkPkg, "res")],
23+
# Get the current library names directly from the packages that use them,
24+
# which keeps this build script robust against lib version changes.
25+
libraries = [HttpParser.lib,
26+
MbedTLS.libmbedcrypto],
27+
appname="HelloBlink", builddir=builddir)

test/build_examples/hello.jl

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using ApplicationBuilder; using BuildApp
2+
3+
examples_hello = joinpath(@__DIR__, "..", "..", "examples", "hello.jl")
4+
5+
# Allow this file to be called either as a standalone file to build the above
6+
# example, or from runtests.jl using a provided builddir.
7+
isdefined(:builddir) || (builddir=mktempdir())
8+
9+
BuildApp.build_app_bundle(examples_hello;
10+
verbose=true, appname="HelloWorld", builddir=builddir)

0 commit comments

Comments
 (0)