|
1 |
| -using Base.Test |
2 |
| - |
3 |
| -# Test that change_dir_if_bundle actually changes behavior based on ENV variable |
4 |
| -# set up fake .App |
5 |
| -tmpdir = mktempdir() |
6 |
| -tmpAppResources = joinpath(tmpdir, "Tmp.app/Contents/Resources") |
7 |
| -tmpAppMacOS = joinpath(tmpdir, "Tmp.app/Contents/MacOS") |
8 |
| -tmpAppExe = joinpath(tmpdir, "Tmp.app/Contents/MacOS/tmp") |
9 |
| -mkpath(tmpAppMacOS) |
10 |
| -mkpath(tmpAppResources) |
11 |
| - |
12 |
| -# Set up test script. (Must be run as a separate process to allow the ENV |
13 |
| -# variable to generate different code at compile-time.) |
14 |
| -testScript = joinpath(tmpdir, "test.jl") |
15 |
| -write(testScript, """ |
16 |
| - # ApplicationBuilder expects to be inside an App structure. |
17 |
| - eval(Base, :(PROGRAM_FILE = "$tmpAppExe")) |
18 |
| - # change_dir_if_bundle() will be differently based on the ENV variable. |
19 |
| - using ApplicationBuilder; ApplicationBuilder.App.change_dir_if_bundle(); println(pwd()); |
20 |
| - """) |
21 |
| - |
22 |
| -# Without ENV variable set, it should do nothing. |
23 |
| -@test pwd() == readlines(`julia $testScript`)[end] |
24 |
| -# With the ENV variable false, it should do nothing. |
25 |
| -@test pwd() == withenv(()->(readlines(`julia $testScript`)[end]), |
26 |
| - "COMPILING_APPLE_BUNDLE"=>"false") # Code is not being compiled. |
27 |
| - |
28 |
| -# With COMPILING_APPLE_BUNDLE == true, the dir should change since it thinks the |
29 |
| -# code is being compiled as an app. |
30 |
| -@test pwd() != withenv(()->(readlines(`julia $testScript`)[end]), |
31 |
| - "COMPILING_APPLE_BUNDLE"=>"true") # Code is not being compiled. |
| 1 | +using Compat |
| 2 | + |
| 3 | +using Compat.Test |
| 4 | +using Compat.Pkg |
| 5 | +using ApplicationBuilder |
| 6 | + |
| 7 | +const julia_v07 = VERSION > v"0.7-" |
| 8 | + |
| 9 | +builddir = mktempdir() |
| 10 | +@assert isdir(builddir) |
| 11 | + |
| 12 | +@testset "make_bundle_identifier Utils" begin |
| 13 | +@test occursin(r"""^com.[a-z0-9]+.myappnamedthisapp22$""", |
| 14 | + ApplicationBuilder.make_bundle_identifier("My app named this_app22") |
| 15 | + ) |
| 16 | +end |
| 17 | + |
| 18 | +@testset "HelloWorld.app" begin |
| 19 | +@test 0 == include("build_examples/hello.jl") |
| 20 | +@test isdir("$builddir/HelloWorld.app") |
| 21 | +@test success(`$builddir/HelloWorld.app/Contents/MacOS/hello`) |
| 22 | + |
| 23 | +# There shouldn't be a Libraries dir since none specified. |
| 24 | +@test !isdir("$builddir/HelloWorld.app/Contents/Libraries") |
| 25 | + |
| 26 | +# Ensure all dependencies on Julia libs are internal, so the app is portable. |
| 27 | +@testset "No external Dependencies" begin |
| 28 | +@test !success(pipeline( |
| 29 | + `otool -l "$builddir/HelloWorld.app/Contents/MacOS/hello"`, |
| 30 | + `grep 'julia'`, # Get all julia deps |
| 31 | + `grep -v '@rpath'`)) # make sure all are relative. |
| 32 | +end |
| 33 | +end |
| 34 | + |
| 35 | +@testset "commandline_app" begin |
| 36 | +@test 0 == include("build_examples/commandline_hello.jl") |
| 37 | +@test success(`open $builddir/hello.app`) |
| 38 | +end |
| 39 | + |
| 40 | + |
| 41 | +function testRunAndKillProgramSucceeds(cmd, timeout=10) |
| 42 | + out, _, p = readandwrite(cmd) # Make sure it runs correctly |
| 43 | + sleep(1) |
| 44 | + process_exited(p) && (println("Test Failed: failed to launch: \n", readstring(out)); return false) |
| 45 | + sleep(timeout) |
| 46 | + process_exited(p) && (println("Test Failed: Process died: \n", readstring(out)); return false) |
| 47 | + # Manually kill program after it's been running for a bit. |
| 48 | + kill(p); sleep(1) |
| 49 | + process_exited(p) || (println("Test Failed: Process failed to exit: \n", readstring(out)); return false) |
| 50 | + return true |
| 51 | +end |
| 52 | + |
| 53 | +# Test that it can run without .julia directory (Dangerous!) |
| 54 | +function testBundledSuccessfully_macro(cmd_expr, timeout=10) |
| 55 | + quote |
| 56 | + val = false |
| 57 | + mv(Pkg.dir(), Pkg.dir()*".bak") # NOTE: MUST mv() THIS BACK |
| 58 | + try |
| 59 | + val = testRunAndKillProgramSucceeds($cmd_expr, $timeout) |
| 60 | + catch |
| 61 | + end |
| 62 | + mv(Pkg.dir()*".bak", Pkg.dir()) # NOTE: MUST RUN THIS LINE IF ABOVE IS RUN |
| 63 | + val |
| 64 | + end |
| 65 | +end |
| 66 | +macro testBundledSuccessfully(expr...) |
| 67 | + testBundledSuccessfully_macro(expr...) |
| 68 | +end |
| 69 | + |
| 70 | +if !julia_v07 # Blink and SDL don't yet work on julia v0.7. |
| 71 | + |
| 72 | +# Disabling the SDL tests since Cairo is currently broken in METADATA. |
| 73 | +#@testset "sdl: simple example of binary dependencies" begin |
| 74 | +#@test 0 == include("build_examples/sdl.jl") |
| 75 | +## Test that it runs correctly |
| 76 | +#@test testRunAndKillProgramSucceeds(`$builddir/HelloSDL2.app/Contents/MacOS/sdl`) |
| 77 | +## Test that it can run without .julia directory |
| 78 | +#@test @testBundledSuccessfully(`$builddir/HelloSDL2.app/Contents/MacOS/sdl`, 3) |
| 79 | +#end |
| 80 | + |
| 81 | +@testset "HelloBlink.app" begin |
| 82 | +@test 0 == include("build_examples/blink.jl") |
| 83 | + |
| 84 | +@test isdir("$builddir/HelloBlink.app") |
| 85 | +# Test that it copied the correct files |
| 86 | +@test isdir("$builddir/HelloBlink.app/Contents/Libraries") |
| 87 | +@test isfile("$builddir/HelloBlink.app/Contents/Resources/main.js") |
| 88 | +# Test that it runs correctly |
| 89 | +@test testRunAndKillProgramSucceeds(`$builddir/HelloBlink.app/Contents/MacOS/blink`) |
| 90 | +# Test that it can run without .julia directory |
| 91 | +@test @testBundledSuccessfully(`$builddir/HelloBlink.app/Contents/MacOS/blink`, 10) |
| 92 | +end |
| 93 | +end |
0 commit comments