|
| 1 | +@testset "run_path separates execution and output directories" begin |
| 2 | + |
| 3 | +# Create a document that writes a marker file and reads a file from cwd |
| 4 | +doc_body = """ |
| 5 | +```julia |
| 6 | +pwd() |
| 7 | +``` |
| 8 | +
|
| 9 | +```julia |
| 10 | +read("run_path_input.txt", String) |
| 11 | +``` |
| 12 | +""" |
| 13 | + |
| 14 | +# Set up: doc in one dir, input file in another |
| 15 | +doc_dir = mktempdir() |
| 16 | +run_dir = mktempdir() |
| 17 | +out_dir = mktempdir() |
| 18 | + |
| 19 | +doc_path = joinpath(doc_dir, "test_run_path.jmd") |
| 20 | +write(doc_path, doc_body) |
| 21 | +write(joinpath(run_dir, "run_path_input.txt"), "hello from run_dir") |
| 22 | + |
| 23 | +@testset "run_path controls execution directory" begin |
| 24 | + doc = run_doc(WeaveDoc(doc_path); out_path = out_dir, run_path = run_dir) |
| 25 | + # pwd() during execution should be run_dir |
| 26 | + @test occursin(run_dir, doc.chunks[1].output) |
| 27 | + # reading a file relative to cwd should find run_dir's file |
| 28 | + @test occursin("hello from run_dir", doc.chunks[2].output) |
| 29 | + # output should go to out_dir |
| 30 | + @test doc.out_dir == out_dir |
| 31 | +end |
| 32 | + |
| 33 | +@testset "run_path=:doc runs from document directory" begin |
| 34 | + write(joinpath(doc_dir, "run_path_input.txt"), "hello from doc_dir") |
| 35 | + doc = run_doc(WeaveDoc(doc_path); out_path = out_dir, run_path = :doc) |
| 36 | + @test occursin(doc_dir, doc.chunks[1].output) |
| 37 | + @test occursin("hello from doc_dir", doc.chunks[2].output) |
| 38 | +end |
| 39 | + |
| 40 | +@testset "run_path=nothing preserves default behavior" begin |
| 41 | + write(joinpath(out_dir, "run_path_input.txt"), "hello from out_dir") |
| 42 | + doc = run_doc(WeaveDoc(doc_path); out_path = out_dir, run_path = nothing) |
| 43 | + # default: execution dir == output dir |
| 44 | + @test occursin(out_dir, doc.chunks[1].output) |
| 45 | + @test occursin("hello from out_dir", doc.chunks[2].output) |
| 46 | +end |
| 47 | + |
| 48 | +@testset "run_path via weave()" begin |
| 49 | + write(joinpath(run_dir, "run_path_input.txt"), "hello from run_dir") |
| 50 | + result = weave(doc_path; out_path = out_dir, run_path = run_dir) |
| 51 | + try |
| 52 | + body = read(result, String) |
| 53 | + @test occursin(run_dir, body) |
| 54 | + @test occursin("hello from run_dir", body) |
| 55 | + finally |
| 56 | + rm(result, force=true) |
| 57 | + end |
| 58 | +end |
| 59 | + |
| 60 | +end # @testset |
0 commit comments