diff --git a/src/Literate.jl b/src/Literate.jl index 0f5b7c8..733bbc0 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -229,10 +229,12 @@ function script(inputfile, outputdir; preprocess = identity, postprocess = ident name = filename(inputfile), documenter = true, credit = true, keep_comments::Bool=false, kwargs...) # normalize paths + isfile(inputfile) || throw(ArgumentError("cannot find inputfile `$(inputfile)`")) inputfile = realpath(abspath(inputfile)) mkpath(outputdir) outputdir = realpath(abspath(outputdir)) - @info "generating plain script file from $(inputfile)" + + @info "generating plain script file from `$(Base.contractuser(inputfile))`" # read content content = read(inputfile, String) @@ -266,7 +268,7 @@ function script(inputfile, outputdir; preprocess = identity, postprocess = ident isdir(outputdir) || error("not a directory: $(outputdir)") outputfile = joinpath(outputdir, name * ".jl") - @info "writing result to $(outputfile)" + @info "writing result to `$(Base.contractuser(outputfile))`" write(outputfile, content) return outputfile @@ -303,10 +305,12 @@ function markdown(inputfile, outputdir; preprocess = identity, postprocess = ide codefence::Pair = documenter ? "```@example $(name)" => "```" : "```julia" => "```", kwargs...) # normalize paths + isfile(inputfile) || throw(ArgumentError("cannot find inputfile `$(inputfile)`")) inputfile = realpath(abspath(inputfile)) mkpath(outputdir) outputdir = realpath(abspath(outputdir)) - @info "generating markdown page from $(inputfile)" + + @info "generating markdown page from `$(Base.contractuser(inputfile))`" # read content content = read(inputfile, String) @@ -372,7 +376,7 @@ function markdown(inputfile, outputdir; preprocess = identity, postprocess = ide isdir(outputdir) || error("not a directory: $(outputdir)") outputfile = joinpath(outputdir, name * ".md") - @info "writing result to $(outputfile)" + @info "writing result to `$(Base.contractuser(outputfile))`" write(outputfile, content) return outputfile @@ -402,11 +406,12 @@ function notebook(inputfile, outputdir; preprocess = identity, postprocess = ide execute::Bool=true, documenter::Bool=true, credit = true, name = filename(inputfile), kwargs...) # normalize paths + isfile(inputfile) || throw(ArgumentError("cannot find inputfile `$(inputfile)`")) inputfile = realpath(abspath(inputfile)) mkpath(outputdir) outputdir = realpath(abspath(outputdir)) - @info "generating notebook from $(inputfile)" + @info "generating notebook from `$(Base.contractuser(inputfile))`" # read content content = read(inputfile, String) @@ -469,13 +474,13 @@ function notebook(inputfile, outputdir; preprocess = identity, postprocess = ide nb = postprocess(nb) if execute - @info "executing notebook $(name * ".ipynb")" + @info "executing notebook `$(name * ".ipynb")`" try cd(outputdir) do nb = execute_notebook(nb) end catch err - @error "error when executing notebook based on input file: $(inputfile)" + @error "error when executing notebook based on input file: `$(Base.contractuser(inputfile))`" rethrow(err) end end @@ -484,7 +489,7 @@ function notebook(inputfile, outputdir; preprocess = identity, postprocess = ide isdir(outputdir) || error("not a directory: $(outputdir)") outputfile = joinpath(outputdir, name * ".ipynb") - @info "writing result to $(outputfile)" + @info "writing result to `$(Base.contractuser(outputfile))`" ionb = IOBuffer() JSON.print(ionb, nb, 1) write(outputfile, seekstart(ionb)) diff --git a/test/runtests.jl b/test/runtests.jl index 6c17a3d..ab2fdbf 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -277,6 +277,9 @@ content = """ @test occursin("# # Example", script) @test occursin("# foo, bar", script) @test occursin("# \\int f(x) dx", script) + + # verify that inputfile exists + @test_throws ArgumentError Literate.script("nonexistent.jl", outdir) end end end @@ -414,6 +417,9 @@ end @test occursin("name: foobar", markdown) @test !occursin("name: inputfile", markdown) @test !occursin("name: @__NAME__", markdown) + + # verify that inputfile exists + @test_throws ArgumentError Literate.markdown("nonexistent.jl", outdir) end end end @@ -631,6 +637,9 @@ end end @test isa(r, ErrorException) @test occursin("when executing the following code block", r.msg) + + # verify that inputfile exists + @test_throws ArgumentError Literate.notebook("nonexistent.jl", outdir) end end end