Merge branch 'master' into pr-362/JonasIsensee/texpipeline

texpipeline
Shuhei Kadowaki 2020-06-13 23:45:43 +09:00
commit 972869da47
27 changed files with 291 additions and 757 deletions

View File

@ -59,9 +59,9 @@ function tangle(
doc = WeaveDoc(source, informat)
doc.cwd = get_cwd(doc, out_path)
outname = get_outname(out_path, doc, ext = "jl")
out_path = get_out_path(doc, out_path, "jl")
open(outname, "w") do io
open(out_path, "w") do io
for chunk in doc.chunks
if typeof(chunk) == CodeChunk
options = merge(doc.chunk_defaults, chunk.options)
@ -69,8 +69,8 @@ function tangle(
end
end
end
doc.cwd == pwd() && (outname = basename(outname))
@info("Writing to file $outname")
@info "Tangled to $(out_path)"
end
"""
@ -198,8 +198,8 @@ function weave(
set_rendering_options!(doc; template = template, highlight_theme = highlight_theme, css = css, keep_unicode = keep_unicode)
rendered = render_doc(doc)
outname = get_outname(out_path, doc)
open(io->write(io,rendered), outname, "w")
out_path = get_out_path(doc, out_path)
write(out_path, rendered)
# document generation via external programs
# -----------------------------------------
@ -210,23 +210,22 @@ function weave(
doctype = doc.doctype
if doctype == "pandoc2html"
mdname = outname
outname = get_outname(out_path, doc, ext = "html")
pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options)
rm(mdname)
intermediate = out_path
out_path = get_out_path(doc, out_path, "html")
pandoc2html(rendered, doc, highlight_theme, out_path, pandoc_options)
rm(intermediate)
elseif doctype == "pandoc2pdf"
mdname = outname
outname = get_outname(out_path, doc, ext = "pdf")
pandoc2pdf(rendered, doc, outname, pandoc_options)
rm(mdname)
intermediate = out_path
out_path = get_out_path(doc, out_path, "pdf")
pandoc2pdf(rendered, doc, out_path, pandoc_options)
rm(intermediate)
elseif doctype == "md2pdf"
run_latex(doc, outname, latex_cmd)
outname = get_outname(out_path, doc, ext = "pdf")
run_latex(doc, out_path, latex_cmd)
out_path = get_out_path(doc, out_path, ext = "pdf")
end
doc.cwd == pwd() && (outname = basename(outname))
@info "Report weaved to $outname"
return abspath(outname)
@info "Weaved to $(out_path)"
return out_path
end
weave(doc::AbstractString, doctype::Union{Symbol,AbstractString}; kwargs...) =
@ -242,6 +241,9 @@ function specific_options!(weave_options, doctype)
end
end
get_out_path(doc, out_path, ext::Nothing = nothing) = get_out_path(doc, out_path, doc.format.extension)
get_out_path(doc, out_path, ext) = abspath(get_cwd(doc, out_path), string(doc.basename , '.', ext))
"""
notebook(source::AbstractString; kwargs...)
@ -277,15 +279,13 @@ function notebook(
doc = WeaveDoc(source)
converted = convert_to_notebook(doc)
doc.cwd = get_cwd(doc, out_path)
outfile = get_outname(out_path, doc, ext = "ipynb")
out_path = get_out_path(doc, out_path, "ipynb")
open(outfile, "w") do f
write(f, converted)
end
write(out_path, converted)
@info "Running nbconvert"
@info "Running nbconvert ..."
return read(
`$jupyter_path nbconvert --ExecutePreprocessor.timeout=$timeout --to notebook --execute $outfile $nbconvert_options --output $outfile`,
`$jupyter_path nbconvert --ExecutePreprocessor.timeout=$timeout --to notebook --execute $(out_path) $nbconvert_options --output $(out_path)`,
String,
)
end
@ -304,7 +304,7 @@ function include_weave(
)
old_path = pwd()
doc = WeaveDoc(source, informat)
cd(doc.path)
cd(dirname(doc.path))
try
code = join(
[x.content for x in filter(x -> isa(x, Weave.CodeChunk), doc.chunks)],

View File

@ -1,64 +1,58 @@
# Default options
const defaultParams = Dict{Symbol,Any}(
:storeresults => false,
:chunk_defaults => Dict{Symbol,Any}(
:echo => true,
:results => "markup",
:hold => false,
:fig => true,
:include => true,
:eval => true,
:tangle => true,
:cache => false,
:fig_cap => nothing,
# Size in inches
:fig_width => 6,
:fig_height => 4,
:fig_path => DEFAULT_FIG_PATH,
:dpi => 96,
:term => false,
:display => false,
:prompt => "\njulia> ",
:label => nothing,
:wrap => true,
:line_width => 75,
:engine => "julia",
# :option_AbstractString=> "",
# Defined in formats
:fig_ext => nothing,
:fig_pos => nothing,
:fig_env => nothing,
:out_width => nothing,
:out_height => nothing,
:skip => false,
),
const _DEFAULT_PARAMS = Dict{Symbol,Any}(
:echo => true,
:results => "markup",
:hold => false,
:fig => true,
:include => true,
:eval => true,
:tangle => true,
:cache => false,
:fig_cap => nothing,
# NOTE: size in inches
:fig_width => 6,
:fig_height => 4,
:fig_path => DEFAULT_FIG_PATH,
:dpi => 96,
:term => false,
:prompt => "\njulia> ",
:label => nothing,
:wrap => true,
:line_width => 75,
:engine => "julia",
:fig_ext => nothing,
:fig_pos => nothing,
:fig_env => nothing,
:out_width => nothing,
:out_height => nothing,
)
# This one can be changed at runtime, initially a copy of defaults
const rcParams = deepcopy(defaultParams)
const DEFAULT_PARAMS = deepcopy(_DEFAULT_PARAMS) # might be changed at runtime
"""
set_chunk_defaults!(opts::Dict{Symbol, Any})
set_chunk_defaults!(k::Symbol, v::Any) = DEFAULT_PARAMS[k]= v
set_chunk_defaults!(kv::Pair{Symbol,Any}...) = for (k,v) in kv; set_chunk_defaults!(k, v); end
set_chunk_defaults!(opts::AbstractDict{Symbol,Any}) = merge!(DEFAULT_PARAMS, opts)
Set default options for code chunks, use [`get_chunk_defaults`](@ref) to see the current values.
E.g.: set default `dpi` to `200` and `fig_width` to `8`
```julia
julia> set_chunk_defaults!(Dict(:dpi => 200, :fig_width => 8))
```
E.g.: all the three examples below will set default `dpi` to `200` and `fig_width` to `8`:
- `set_chunk_defaults!(:dpi, 200); set_chunk_defaults!(:fig_width, 8)`
- `set_chunk_defaults!(:dpi => 200, :fig_width => 8)`
- `set_chunk_defaults!(Dict(:dpi => 200, :fig_width => 8))`
"""
set_chunk_defaults!(opts::Dict{Symbol,Any}) = merge!(rcParams[:chunk_defaults], opts)
set_chunk_defaults!(k::Symbol, v::Any) = DEFAULT_PARAMS[k]= v
set_chunk_defaults!(kv::Pair{Symbol,Any}...) = for (k,v) in kv; set_chunk_defaults!(k, v); end
set_chunk_defaults!(opts::AbstractDict{Symbol,Any}) = merge!(DEFAULT_PARAMS, opts)
"""
get_chunk_defaults()
Get default options used for code chunks.
"""
get_chunk_defaults() = rcParams[:chunk_defaults]
get_chunk_defaults() = DEFAULT_PARAMS
"""
restore_chunk_defaults!()
Restore Weave.jl default chunk options.
"""
restore_chunk_defaults!() = rcParams[:chunk_defaults] = defaultParams[:chunk_defaults]
restore_chunk_defaults!() = for (k,v) in _DEFAULT_PARAMS; DEFAULT_PARAMS[k] = v; end

View File

@ -102,8 +102,6 @@ function convert_to_notebook(doc)
"source" => [strip(join([repr(c) for c in chunk.content], ""))],
),
)
elseif haskey(chunk.options, :skip) && chunk.options[:skip] == "notebook"
continue
else
push!(
cells,

View File

@ -5,12 +5,9 @@ mutable struct Report <: AbstractDisplay
cwd::AbstractString
basename::AbstractString
format::WeaveFormat
pending_code::AbstractString
cur_result::AbstractString
rich_output::AbstractString
fignum::Int
figures::Array{AbstractString}
term_state::Symbol
figures::Vector{String}
cur_chunk::Any
mimetypes::Array{AbstractString}
first_plot::Bool
@ -24,11 +21,8 @@ function Report(cwd, basename, format, mimetypes, throw_errors)
basename,
format,
"",
"",
"",
1,
AbstractString[],
:text,
String[],
nothing,
mimetypes,
true,

View File

@ -1,4 +1,4 @@
function pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options)
function pandoc2html(rendered, doc, highlight_theme, out_path, pandoc_options)
template_path = normpath(TEMPLATE_DIR, "pandoc2html.html")
stylesheet_path = normpath(STYLESHEET_DIR, "pandoc2html_skeleton.css")
highlight_stylesheet = get_highlight_stylesheet(MIME("text/html"), highlight_theme)
@ -21,7 +21,7 @@ function pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options)
# Change path for pandoc
cd_back = let d = pwd(); () -> cd(d); end
cd(doc.cwd)
outname = basename(outname)
out_path = basename(out_path)
try
cmd = `pandoc -f markdown+raw_html -s --mathjax=""
@ -34,7 +34,7 @@ function pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options)
-V weave_date=$weave_date
-V weave_source=$weave_source
-V headerscript=$header_script
-o $outname`
-o $out_path`
proc = open(cmd, "r+")
println(proc.in, rendered)
close(proc.in)
@ -47,10 +47,10 @@ function pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options)
end
end
function pandoc2pdf(rendered, doc, outname, pandoc_options)
function pandoc2pdf(rendered, doc, out_path, pandoc_options)
header_template = normpath(TEMPLATE_DIR, "pandoc2pdf_header.txt")
outname = basename(outname)
out_path = basename(out_path)
# Change path for pandoc
cd_back = let d = pwd(); () -> cd(d); end
@ -69,7 +69,7 @@ function pandoc2pdf(rendered, doc, outname, pandoc_options)
cmd = `pandoc -f markdown+raw_tex -s --pdf-engine=xelatex --highlight-style=tango
$filt $citeproc $pandoc_options
--include-in-header=$header_template
-V fontsize=12pt -o $outname`
-V fontsize=12pt -o $out_path`
proc = open(cmd, "r+")
println(proc.in, rendered)
close(proc.in)
@ -82,12 +82,12 @@ function pandoc2pdf(rendered, doc, outname, pandoc_options)
end
end
function run_latex(doc::WeaveDoc, outname, latex_cmd = "xelatex")
function run_latex(doc::WeaveDoc, out_path, latex_cmd = "xelatex")
cd_back = let d = pwd(); () -> cd(d); end
cd(doc.cwd)
xname = basename(outname)
@info "Weaved code to $outname . Running $latex_cmd" # space before '.' added for link to be clickable in Juno terminal
xname = basename(out_path)
@info "Weaved code to $out_path . Running $latex_cmd" # space before '.' added for link to be clickable in Juno terminal
textmp = mktempdir(".")
try
cmd = `$latex_cmd -shell-escape $xname -aux-directory $textmp -include-directory $(doc.cwd)`

View File

@ -2,7 +2,8 @@ using YAML
function WeaveDoc(source, informat = nothing)
path, fname = splitdir(abspath(source))
path = abspath(source)
_, fname = splitdir(path)
basename = splitext(fname)[1]
isnothing(informat) && (informat = detect_informat(source))

View File

@ -6,7 +6,7 @@
set_rendering_options!(docformat::WeaveFormat; kwargs...) = return
function restore_header!(doc)
(hasproperty(doc.format, :restore_header) && doc.format.restore_header) || return
(hasproperty(doc.format, :preserve_header) && doc.format.preserve_header) || return
# only strips Weave headers
delete!(doc.header, WEAVE_OPTION_NAME)

View File

@ -21,11 +21,11 @@ function run_doc(
doc.format = deepcopy(FORMATS[doctype])
cwd = doc.cwd = get_cwd(doc, out_path)
isdir(cwd) || mkpath(cwd)
isdir(cwd) || mkdir(cwd)
if isnothing(fig_path)
fig_path = if (endswith(doctype, "2pdf") && cache === :off) || endswith(doctype, "2html")
basename(mktempdir(abspath(doc.cwd)))
basename(mktempdir(abspath(cwd)))
else
DEFAULT_FIG_PATH
end
@ -43,7 +43,9 @@ function run_doc(
mimetypes = doc.format.mimetypes
report = Report(doc.cwd, doc.basename, doc.format, mimetypes, throw_errors)
report = Report(cwd, doc.basename, doc.format, mimetypes, throw_errors)
cd_back = let d = pwd(); () -> cd(d); end
cd(cwd)
pushdisplay(report)
try
if cache !== :off && cache !== :refresh
@ -86,6 +88,7 @@ function run_doc(
rethrow(err)
finally
@info "Weaved all chunks" progress=1 _id=PROGRESS_ID
cd_back()
popdisplay(report) # ensure display pops out even if internal error occurs
end
@ -111,8 +114,23 @@ function detect_doctype(path)
return "pandoc"
end
function get_cwd(doc, out_path)
return if out_path === :doc
dirname(doc.path)
elseif out_path === :pwd
pwd()
else
path, ext = splitext(out_path)
if isempty(ext) # directory given
path
else # file given
dirname(path)
end
end |> abspath
end
function run_chunk(chunk::CodeChunk, doc, report, mod)
result = eval_chunk(chunk, report, mod)
result = eval_chunk(doc, chunk, report, mod)
occursin("2html", doc.doctype) && (embed_figures!(result, report.cwd))
return result
end
@ -150,7 +168,7 @@ function run_chunk(chunk::DocChunk, doc, report, mod)
return chunk
end
run_inline(inline::InlineText, doc::WeaveDoc, report::Report, SandBox::Module) = inline
run_inline(inline::InlineText, ::WeaveDoc, ::Report, ::Module) = inline
const INLINE_OPTIONS = Dict(
:term => false,
@ -158,13 +176,13 @@ const INLINE_OPTIONS = Dict(
:wrap => false
)
function run_inline(inline::InlineCode, doc::WeaveDoc, report::Report, SandBox::Module)
function run_inline(inline::InlineCode, doc::WeaveDoc, report::Report, mod::Module)
# Make a temporary CodeChunk for running code. Collect results and don't wrap
chunk = CodeChunk(inline.content, 0, 0, "", INLINE_OPTIONS)
options = merge(doc.chunk_defaults, chunk.options)
merge!(chunk.options, options)
chunks = eval_chunk(chunk, report, SandBox)
chunks = eval_chunk(doc, chunk, report, mod)
occursin("2html", doc.doctype) && (embed_figures!(chunks, report.cwd))
output = chunks[1].output
@ -175,72 +193,76 @@ function run_inline(inline::InlineCode, doc::WeaveDoc, report::Report, SandBox::
return inline
end
function reset_report(report::Report)
report.cur_result = ""
report.figures = AbstractString[]
report.term_state = :text
end
reset_report(report::Report) = report.figures = String[]
function run_code(chunk::CodeChunk, report::Report, SandBox::Module)
exs = parse_input(chunk.content)
n = length(exs)
function run_code(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module)
ss = parse_input(chunk.content)
n = length(ss)
results = ChunkOutput[]
for (i, (str_expr, expr)) in enumerate(exs)
for (i, s) in enumerate(ss)
reset_report(report)
obj, out = capture_output(
expr,
SandBox,
mod,
s,
doc.path,
chunk.options[:term],
chunk.options[:display],
i == n,
report.throw_errors,
)
figures = report.figures # Captured figures
result = ChunkOutput(str_expr, out, report.cur_result, report.rich_output, figures)
result = ChunkOutput(s, out, report.rich_output, figures)
report.rich_output = ""
push!(results, result)
end
return results
end
# TODO: run in document source path
function capture_output(expr, SandBox::Module, term, disp, lastline, throw_errors = false)
out = nothing
obj = nothing
old = stdout
rw, wr = redirect_stdout()
reader = @async read(rw, String)
try
obj = Core.eval(SandBox, expr)
!isnothing(obj) && ((term || disp) || lastline) && display(obj)
catch err
throw_errors && throw(err)
display(err)
@warn "ERROR: $(typeof(err)) occurred, including output in Weaved document"
finally
redirect_stdout(old)
close(wr)
out = fetch(reader)
close(rw)
end
out = replace(out, r"\u001b\[.*?m" => "") # remove ANSI color codes
return (obj, out)
end
# Parse chunk input to array of expressions
function parse_input(s)
res = []
res = String[]
s = lstrip(s)
n = sizeof(s)
pos = 1 # The first character is extra line end
pos = 1
while (oldpos = pos) n
ex, pos = Meta.parse(s, pos)
push!(res, (s[oldpos:pos-1], ex))
_, pos = Meta.parse(s, pos)
push!(res, s[oldpos:pos-1])
end
return res
end
function eval_chunk(chunk::CodeChunk, report::Report, SandBox::Module)
function capture_output(mod, s, path, term, lastline, throw_errors = false)
local out = nothing
local obj = nothing
old = stdout
rw, wr = redirect_stdout()
reader = @async read(rw, String)
task_local_storage(:SOURCE_PATH, path) do
try
obj = include_string(mod, s, path) # TODO: fix line number
!isnothing(obj) && (term || lastline) && display(obj)
catch _err
err = unwrap_load_err(_err)
throw_errors && throw(err)
display(err)
@warn "ERROR: $(typeof(err)) occurred, including output in Weaved document"
finally
redirect_stdout(old)
close(wr)
out = fetch(reader)
close(rw)
end
end
out = replace(out, r"\u001b\[.*?m" => "") # remove ANSI color codes
return (obj, out)
end
unwrap_load_err(err) = return err
unwrap_load_err(err::LoadError) = return err.error
function eval_chunk(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module)
if !chunk.options[:eval]
chunk.output = ""
chunk.options[:fig] = false
@ -259,7 +281,7 @@ function eval_chunk(chunk::CodeChunk, report::Report, SandBox::Module)
chunk.options[:out_width] = report.format.out_width
end
chunk.result = run_code(chunk, report, SandBox)
chunk.result = run_code(doc, chunk, report, mod)
# Run post_execute chunks
for hook in postexecute_hooks
@ -317,41 +339,6 @@ function get_figname(report::Report, chunk; fignum = nothing, ext = nothing)
return full_name, rel_name
end
function get_cwd(doc::WeaveDoc, out_path)
# Set the output directory
if out_path === :doc
cwd = doc.path
elseif out_path === :pwd
cwd = pwd()
else
# If there is no extension, use as path
splitted = splitext(out_path)
if splitted[2] == ""
cwd = expanduser(out_path)
else
cwd = splitdir(expanduser(out_path))[1]
end
end
return cwd
end
"""Get output file name based on out_path"""
function get_outname(out_path::Symbol, doc::WeaveDoc; ext = nothing)
isnothing(ext) && (ext = doc.format.extension)
outname = "$(doc.cwd)/$(doc.basename).$ext"
end
"""Get output file name based on out_path"""
function get_outname(out_path::AbstractString, doc::WeaveDoc; ext = nothing)
isnothing(ext) && (ext = doc.format.extension)
splitted = splitext(out_path)
if (splitted[2]) == ""
outname = "$(doc.cwd)/$(doc.basename).$ext"
else
outname = expanduser(out_path)
end
end
function set_rc_params(doc::WeaveDoc, fig_path, fig_ext)
if isnothing(fig_ext)
doc.chunk_defaults[:fig_ext] = doc.format.fig_ext
@ -379,7 +366,7 @@ function collect_results(chunk::CodeChunk)
)
content = ""
rchunk.figures = r.figures
rchunk.output = r.stdout * r.displayed
rchunk.output = r.stdout
rchunk.rich_output = r.rich_output
push!(result_chunks, rchunk)
end
@ -404,8 +391,7 @@ function collect_term_results(chunk::CodeChunk)
prompt = chunk.options[:prompt]
result_chunks = CodeChunk[]
for r in chunk.result
output *= prompt * r.code
output *= r.displayed * r.stdout
output *= string(prompt, r.code, r.stdout)
if !isempty(r.figures)
rchunk = CodeChunk(
"",

View File

@ -18,11 +18,10 @@ mutable struct WeaveDoc
end
struct ChunkOutput
code::AbstractString
stdout::AbstractString
displayed::AbstractString
rich_output::AbstractString
figures::Vector{AbstractString}
code::String
stdout::String
rich_output::String
figures::Vector{String}
end
mutable struct CodeChunk <: WeaveChunk

View File

@ -1,6 +0,0 @@
Functions:
<<>>=
f(x)=x^2
println(f(2))
@

View File

@ -1,13 +0,0 @@
Functions:
~~~~{.julia}
f(x)=x^2
println(f(2))
~~~~~~~~~~~~~
~~~~
4
~~~~

View File

@ -1,96 +0,0 @@
````julia
import Base
function Base.show(io::IO, m::MIME"text/html", x::Array)
print(io, "<table>")
for i in 1:size(x,1)
print(io, "<tr>")
[print(io, "<td>$r</td>") for r in x[i,:]]
print(io, "</tr>")
end
print(io, "</table>")
end
#This isn't valid latex, doesn't matter for the test
function Base.show(io::IO, m::MIME"text/latex", x::Array)
println(io, "\\begin{tabular}")
for i in 1:size(x,1)
[print(io, "$r & ") for r in x[i,:]]
print(io, "\\\\")
println(io, " \\hline")
end
print(io, "\\end{tabular")
end
#This isn't valid markdown, doesn't matter for the test
function Base.show(io::IO, m::MIME"text/markdown", x::Array)
println(io, "-----")
for i in 1:size(x,1)
print(io, "| ")
[print(io, "$r | ") for r in x[i,:]]
println(io, "")
end
print(io, "-----")
end
x = [collect(1:3) collect(1:3)]
ca = collect('a':'d')
ca
````
-----
| a |
| b |
| c |
| d |
-----
````julia
display(ca)
display(x)
````
-----
| a |
| b |
| c |
| d |
-----
-----
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
-----
````julia
julia> x
3×2 Array{Int64,2}:
1 1
2 2
3 3
julia> ca
4-element Array{Char,1}:
'a'
'b'
'c'
'd'
````
````julia
using Markdown
m = Markdown.parse("**Some Markdown**")
m
````
**Some Markdown**

View File

@ -1,84 +0,0 @@
<pre class='hljl'>
<span class='hljl-k'>import</span><span class='hljl-t'> </span><span class='hljl-n'>Base</span><span class='hljl-t'>
</span><span class='hljl-k'>function</span><span class='hljl-t'> </span><span class='hljl-n'>Base</span><span class='hljl-oB'>.</span><span class='hljl-nf'>show</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-oB'>::</span><span class='hljl-n'>IO</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>m</span><span class='hljl-oB'>::</span><span class='hljl-so'>MIME&quot;text/html&quot;</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-oB'>::</span><span class='hljl-n'>Array</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-nf'>print</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;&lt;table&gt;&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-k'>for</span><span class='hljl-t'> </span><span class='hljl-n'>i</span><span class='hljl-t'> </span><span class='hljl-kp'>in</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-oB'>:</span><span class='hljl-nf'>size</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>,</span><span class='hljl-ni'>1</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-nf'>print</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;&lt;tr&gt;&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-p'>[</span><span class='hljl-nf'>print</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;&lt;td&gt;</span><span class='hljl-si'>$r</span><span class='hljl-s'>&lt;/td&gt;&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-k'>for</span><span class='hljl-t'> </span><span class='hljl-n'>r</span><span class='hljl-t'> </span><span class='hljl-kp'>in</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-p'>[</span><span class='hljl-n'>i</span><span class='hljl-p'>,</span><span class='hljl-oB'>:</span><span class='hljl-p'>]]</span><span class='hljl-t'>
</span><span class='hljl-nf'>print</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;&lt;/tr&gt;&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-k'>end</span><span class='hljl-t'>
</span><span class='hljl-nf'>print</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;&lt;/table&gt;&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-k'>end</span><span class='hljl-t'>
</span><span class='hljl-cs'>#This isn&#39;t valid latex, doesn&#39;t matter for the test</span><span class='hljl-t'>
</span><span class='hljl-k'>function</span><span class='hljl-t'> </span><span class='hljl-n'>Base</span><span class='hljl-oB'>.</span><span class='hljl-nf'>show</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-oB'>::</span><span class='hljl-n'>IO</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>m</span><span class='hljl-oB'>::</span><span class='hljl-so'>MIME&quot;text/latex&quot;</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-oB'>::</span><span class='hljl-n'>Array</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-nf'>println</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;</span><span class='hljl-se'>\\</span><span class='hljl-s'>begin{tabular}&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-k'>for</span><span class='hljl-t'> </span><span class='hljl-n'>i</span><span class='hljl-t'> </span><span class='hljl-kp'>in</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-oB'>:</span><span class='hljl-nf'>size</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>,</span><span class='hljl-ni'>1</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-p'>[</span><span class='hljl-nf'>print</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;</span><span class='hljl-si'>$r</span><span class='hljl-s'> &amp; &quot;</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-k'>for</span><span class='hljl-t'> </span><span class='hljl-n'>r</span><span class='hljl-t'> </span><span class='hljl-kp'>in</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-p'>[</span><span class='hljl-n'>i</span><span class='hljl-p'>,</span><span class='hljl-oB'>:</span><span class='hljl-p'>]]</span><span class='hljl-t'>
</span><span class='hljl-nf'>print</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;</span><span class='hljl-se'>\\\\</span><span class='hljl-s'>&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-nf'>println</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot; </span><span class='hljl-se'>\\</span><span class='hljl-s'>hline&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-k'>end</span><span class='hljl-t'>
</span><span class='hljl-nf'>print</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;</span><span class='hljl-se'>\\</span><span class='hljl-s'>end{tabular&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-k'>end</span><span class='hljl-t'>
</span><span class='hljl-cs'>#This isn&#39;t valid markdown, doesn&#39;t matter for the test</span><span class='hljl-t'>
</span><span class='hljl-k'>function</span><span class='hljl-t'> </span><span class='hljl-n'>Base</span><span class='hljl-oB'>.</span><span class='hljl-nf'>show</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-oB'>::</span><span class='hljl-n'>IO</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>m</span><span class='hljl-oB'>::</span><span class='hljl-so'>MIME&quot;text/markdown&quot;</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-oB'>::</span><span class='hljl-n'>Array</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-nf'>println</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;-----&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-k'>for</span><span class='hljl-t'> </span><span class='hljl-n'>i</span><span class='hljl-t'> </span><span class='hljl-kp'>in</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-oB'>:</span><span class='hljl-nf'>size</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>,</span><span class='hljl-ni'>1</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-nf'>print</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;| &quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-p'>[</span><span class='hljl-nf'>print</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;</span><span class='hljl-si'>$r</span><span class='hljl-s'> | &quot;</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-k'>for</span><span class='hljl-t'> </span><span class='hljl-n'>r</span><span class='hljl-t'> </span><span class='hljl-kp'>in</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-p'>[</span><span class='hljl-n'>i</span><span class='hljl-p'>,</span><span class='hljl-oB'>:</span><span class='hljl-p'>]]</span><span class='hljl-t'>
</span><span class='hljl-nf'>println</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-k'>end</span><span class='hljl-t'>
</span><span class='hljl-nf'>print</span><span class='hljl-p'>(</span><span class='hljl-n'>io</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-s'>&quot;-----&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-k'>end</span><span class='hljl-t'>
</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-p'>[</span><span class='hljl-nf'>collect</span><span class='hljl-p'>(</span><span class='hljl-ni'>1</span><span class='hljl-oB'>:</span><span class='hljl-ni'>3</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-nf'>collect</span><span class='hljl-p'>(</span><span class='hljl-ni'>1</span><span class='hljl-oB'>:</span><span class='hljl-ni'>3</span><span class='hljl-p'>)]</span><span class='hljl-t'>
</span><span class='hljl-n'>ca</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nf'>collect</span><span class='hljl-p'>(</span><span class='hljl-sc'>&#39;a&#39;</span><span class='hljl-oB'>:</span><span class='hljl-sc'>&#39;d&#39;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-n'>ca</span>
</pre>
<table><tr><td>a</td></tr><tr><td>b</td></tr><tr><td>c</td></tr><tr><td>d</td></tr></table>
<pre class='hljl'>
<span class='hljl-nf'>display</span><span class='hljl-p'>(</span><span class='hljl-n'>ca</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-nf'>display</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>)</span>
</pre>
<table><tr><td>a</td></tr><tr><td>b</td></tr><tr><td>c</td></tr><tr><td>d</td></tr></table>
<table><tr><td>1</td><td>1</td></tr><tr><td>2</td><td>2</td></tr><tr><td>3</td><td>3</td></tr></table>
<pre class='hljl'>
<span class='hljl-nB'>julia&gt; </span><span class='hljl-n'>x</span><span class='hljl-t'>
3×2 Array{Int64,2}:
1 1
2 2
3 3
</span><span class='hljl-nB'>julia&gt; </span><span class='hljl-n'>ca</span><span class='hljl-t'>
4-element Array{Char,1}:
&#39;a&#39;
&#39;b&#39;
&#39;c&#39;
&#39;d&#39;</span>
</pre>
<pre class='hljl'>
<span class='hljl-k'>using</span><span class='hljl-t'> </span><span class='hljl-n'>Markdown</span><span class='hljl-t'>
</span><span class='hljl-n'>m</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-n'>Markdown</span><span class='hljl-oB'>.</span><span class='hljl-nf'>parse</span><span class='hljl-p'>(</span><span class='hljl-s'>&quot;**Some Markdown**&quot;</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-n'>m</span>
</pre>
<div class="markdown"><p><strong>Some Markdown</strong></p>
</div>

View File

@ -1,96 +0,0 @@
~~~~{.julia}
import Base
function Base.show(io::IO, m::MIME"text/html", x::Array)
print(io, "<table>")
for i in 1:size(x,1)
print(io, "<tr>")
[print(io, "<td>$r</td>") for r in x[i,:]]
print(io, "</tr>")
end
print(io, "</table>")
end
#This isn't valid latex, doesn't matter for the test
function Base.show(io::IO, m::MIME"text/latex", x::Array)
println(io, "\\begin{tabular}")
for i in 1:size(x,1)
[print(io, "$r & ") for r in x[i,:]]
print(io, "\\\\")
println(io, " \\hline")
end
print(io, "\\end{tabular")
end
#This isn't valid markdown, doesn't matter for the test
function Base.show(io::IO, m::MIME"text/markdown", x::Array)
println(io, "-----")
for i in 1:size(x,1)
print(io, "| ")
[print(io, "$r | ") for r in x[i,:]]
println(io, "")
end
print(io, "-----")
end
x = [collect(1:3) collect(1:3)]
ca = collect('a':'d')
ca
~~~~~~~~~~~~~
-----
| a |
| b |
| c |
| d |
-----
~~~~{.julia}
display(ca)
display(x)
~~~~~~~~~~~~~
-----
| a |
| b |
| c |
| d |
-----
-----
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
-----
~~~~{.julia}
julia> x
3×2 Array{Int64,2}:
1 1
2 2
3 3
julia> ca
4-element Array{Char,1}:
'a'
'b'
'c'
'd'
~~~~~~~~~~~~~
~~~~{.julia}
using Markdown
m = Markdown.parse("**Some Markdown**")
m
~~~~~~~~~~~~~
**Some Markdown**

View File

@ -1,89 +0,0 @@
\begin{juliacode}
import Base
function Base.show(io::IO, m::MIME"text/html", x::Array)
print(io, "<table>")
for i in 1:size(x,1)
print(io, "<tr>")
[print(io, "<td>$r</td>") for r in x[i,:]]
print(io, "</tr>")
end
print(io, "</table>")
end
#This isn't valid latex, doesn't matter for the test
function Base.show(io::IO, m::MIME"text/latex", x::Array)
println(io, "\\begin{tabular}")
for i in 1:size(x,1)
[print(io, "$r & ") for r in x[i,:]]
print(io, "\\\\")
println(io, " \\hline")
end
print(io, "\\end{tabular")
end
#This isn't valid markdown, doesn't matter for the test
function Base.show(io::IO, m::MIME"text/markdown", x::Array)
println(io, "-----")
for i in 1:size(x,1)
print(io, "| ")
[print(io, "$r | ") for r in x[i,:]]
println(io, "")
end
print(io, "-----")
end
x = [collect(1:3) collect(1:3)]
ca = collect('a':'d')
ca
\end{juliacode}
\begin{tabular}
a & \\ \hline
b & \\ \hline
c & \\ \hline
d & \\ \hline
\end{tabular
\begin{juliacode}
display(ca)
display(x)
\end{juliacode}
\begin{tabular}
a & \\ \hline
b & \\ \hline
c & \\ \hline
d & \\ \hline
\end{tabular
\begin{tabular}
1 & 1 & \\ \hline
2 & 2 & \\ \hline
3 & 3 & \\ \hline
\end{tabular
\begin{juliaterm}
julia> x
3×2 Array{Int64,2}:
1 1
2 2
3 3
julia> ca
4-element Array{Char,1}:
'a'
'b'
'c'
'd'
\end{juliaterm}
\begin{juliacode}
using Markdown
m = Markdown.parse("**Some Markdown**")
m
\end{juliacode}
\textbf{Some Markdown}

View File

@ -1,58 +0,0 @@
```julia
import Base
function Base.show(io::IO, m::MIME"text/html", x::Array)
print(io, "<table>")
for i in 1:size(x,1)
print(io, "<tr>")
[print(io, "<td>$r</td>") for r in x[i,:]]
print(io, "</tr>")
end
print(io, "</table>")
end
#This isn't valid latex, doesn't matter for the test
function Base.show(io::IO, m::MIME"text/latex", x::Array)
println(io, "\\begin{tabular}")
for i in 1:size(x,1)
[print(io, "$r & ") for r in x[i,:]]
print(io, "\\\\")
println(io, " \\hline")
end
print(io, "\\end{tabular")
end
#This isn't valid markdown, doesn't matter for the test
function Base.show(io::IO, m::MIME"text/markdown", x::Array)
println(io, "-----")
for i in 1:size(x,1)
print(io, "| ")
[print(io, "$r | ") for r in x[i,:]]
println(io, "")
end
print(io, "-----")
end
x = [collect(1:3) collect(1:3)]
ca = collect('a':'d')
ca
```
```julia; hold=true
display(ca)
display(x)
```
```julia; term=true
x
ca
```
```julia
using Markdown
m = Markdown.parse("**Some Markdown**")
m
```

View File

@ -1,12 +0,0 @@
```julia
p = Array(linspace(0, 2π))
```
```julia;term=true
p = Array(linspace(0, 2π))
```
```julia;term=true
p = Array(linspace(0, 2π));
```

View File

@ -1,73 +0,0 @@
~~~~{.julia}
p = Array(linspace(0, 2π))
~~~~~~~~~~~~~
~~~~{.julia}
julia> p = Array(linspace(0, 2π))
50-element Array{Float64,1}:
0.0
0.128228
0.256457
0.384685
0.512913
0.641141
0.76937
0.897598
1.02583
1.15405
1.28228
1.41051
1.53874
1.66697
1.7952
1.92342
2.05165
2.17988
2.30811
2.43634
2.56457
2.69279
2.82102
2.94925
3.07748
3.20571
3.33394
3.46216
3.59039
3.71862
3.84685
3.97508
4.1033
4.23153
4.35976
4.48799
4.61622
4.74445
4.87267
5.0009
5.12913
5.25736
5.38559
5.51382
5.64204
5.77027
5.8985
6.02673
6.15496
6.28319
~~~~~~~~~~~~~
~~~~{.julia}
julia> p = Array(linspace(0, 2π));
~~~~~~~~~~~~~

View File

@ -103,13 +103,13 @@ str = """
α = 10
```
"""
doc = mock_doc(str; doctype = "md2tex")
doc = mock_run(str; doctype = "md2tex")
Weave.set_rendering_options!(doc.format)
doc = Weave.render_doc(doc)
@test occursin(Weave.uc2tex("α"), doc)
@test !occursin("α", doc)
doc = mock_doc(str; doctype = "md2tex")
doc = mock_run(str; doctype = "md2tex")
Weave.set_rendering_options!(doc.format; keep_unicode = true)
doc = Weave.render_doc(doc)
@test occursin("α", doc)

2
test/mocks/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -1,18 +0,0 @@
# XXX: this test is too frigile
function mmtest(source, resfile, doctype)
weave(
"documents/$source",
out_path = "documents/multimedia/$resfile",
doctype = doctype,
template = "templates/mini.tpl",
)
result = read("documents/multimedia/$resfile", String)
ref = read("documents/multimedia/$resfile.ref", String)
@test result == ref
rm("documents/multimedia/$resfile")
end
mmtest("rich_output.jmd", "rich_output.html", "md2html")
mmtest("rich_output.jmd", "rich_output.md", "pandoc")
mmtest("rich_output.jmd", "rich_output.tex", "tex")
mmtest("rich_output.jmd", "rich_output.github", "github")

View File

@ -5,14 +5,26 @@ using Weave: WeaveDoc, run_doc
# TODO: add test for header processsing
# TODO: add test for `include_weave`
# constructs `WeaveDoc` from `String` and run it
function mock_doc(str; informat = "markdown", run = true, doctype = "md2html", kwargs...)
function mock_doc(str, informat = "markdown")
f = tempname()
write(f, str)
doc = WeaveDoc(f, informat)
return run ? run_doc(doc; doctype = doctype, kwargs...) : doc
return WeaveDoc(f, informat)
end
mock_run(str, informat = "markdown"; kwargs...) = run_doc(mock_doc(str, informat); kwargs...)
function test_mock_weave(test_function, str; kwargs...)
f = tempname()
write(f, str)
f = weave(f; kwargs...)
try
weave_body = read(f, String)
test_function(weave_body)
catch
rethrow()
finally
rm(f)
end
end
macro jmd_str(s) mock_doc(s) end
@testset "Weave" begin
@ -32,6 +44,10 @@ macro jmd_str(s) mock_doc(s) end
include("test_chunk_options.jl")
end
@testset "evaluation's meta info" begin
include("test_meta.jl")
end
@testset "error rendering" begin
include("test_error_rendering.jl")
end
@ -50,10 +66,6 @@ macro jmd_str(s) mock_doc(s) end
include("figureformatter_test.jl")
end
@testset "Rich output" begin
include("rich_output.jl")
end
@testset "Cache" begin
include("cache_test.jl")
end

View File

@ -3,23 +3,23 @@
@static VERSION v"1.4" && let
# no limit
doc = jmd"""
doc = mock_run("""
```julia
using DataFrames
DataFrame(rand(10,3))
```
"""
"""; doctype = "md2html")
@test isdefined(doc.chunks[1], :rich_output)
@test count("<tr>", doc.chunks[1].rich_output) == 12 # additonal 2 for name and type row
# limit
n = 100000
doc = jmd"""
doc = mock_run("""
```julia
using DataFrames
DataFrame(rand(n,3))
DataFrame(rand($n,3))
```
"""
"""; doctype = "md2html")
@test isdefined(doc.chunks[1], :rich_output)
@test count("<tr>", doc.chunks[1].rich_output) < n

View File

@ -1,11 +1,14 @@
function get_err_str(ex)
using Weave: unwrap_load_err
function get_err_str(str::AbstractString)
try
eval(ex)
catch err
include_string(Main, str)
catch _err
err = unwrap_load_err(_err)
return sprint(showerror, err)
end
end
get_err_str(str::AbstractString) = get_err_str(Meta.parse(str; raise = false))
err_stmt1 = "using NonExisting"
err_stmt2 = "x = "
@ -35,7 +38,7 @@ err_str3_1 = get_err_str("plot(x)")
err_str3_2 = get_err_str("f(y")
let doc = mock_doc(str; doctype = "github")
let doc = mock_run(str; doctype = "github")
get_output(i) = doc.chunks[i].output
@test occursin(err_str1, get_output(1))
@ -44,6 +47,6 @@ let doc = mock_doc(str; doctype = "github")
@test occursin(err_str3_2, get_output(3))
end
@test_throws ArgumentError mock_doc(str; doctype = "github", throw_errors = true)
@test_throws ArgumentError mock_run(str; doctype = "github", throw_errors = true)
# TODO: test error rendering in `rich_output`

View File

@ -45,14 +45,14 @@ end
weave_options:
---
"""
@test (mock_doc(str; run = true); true) # no throw
@test (mock_run(str); true) # no throw
end
@testset "dynamic header specifications" begin
let
d = mock_doc("""
d = mock_run("""
---
title: No. `j 1`
---
@ -65,7 +65,7 @@ let
# run in target module
@eval m n = 1
d = mock_doc("""
d = mock_run("""
---
title: No. `j n`
---
@ -74,7 +74,7 @@ let
# strip quotes by default
@eval m s = "1"
d = mock_doc("""
d = mock_run("""
---
title: No. `j s`
---
@ -119,3 +119,48 @@ let github_options = copy(weave_options)
end
end
@testset "end to end test" begin
# preserve header
test_mock_weave("""
---
key: value
---
find_me
"""; informat = "markdown", doctype = "github") do body
@test occursin("key: \"value\"", body)
@test occursin("find_me", body)
end
# only strips weave specific header
test_mock_weave("""
---
key: value
weave_options:
doctype: github
---
find_me
"""; informat = "markdown", doctype = "github") do body
@test occursin("key: \"value\"", body)
@test !occursin("weave_options", body)
@test occursin("find_me", body)
end
# don't preserve header
test_mock_weave("""
---
weave_options:
doctype: md2html
---
find_me
"""; informat = "markdown", doctype = "md2html") do body
@test !occursin("weave_options", body)
@test occursin("find_me", body)
end
end

45
test/test_meta.jl Normal file
View File

@ -0,0 +1,45 @@
doc_body = """
```julia
include("test_include.jl")
```
```julia
@__MODULE__
```
```julia
@__DIR__
```
```julia
@__FILE__
```
```julia
@__LINE__ # broken
```
```julia
read("./test_include.jl", String)
```
"""
doc_dir = joinpath(@__DIR__, "mocks")
doc_path = joinpath(doc_dir, "test_meta.jmd")
write(doc_path, doc_body)
script_line = ":include_me"
script_body = "$script_line"
script_path = joinpath(@__DIR__, "mocks", "test_include.jl")
write(script_path, script_body)
m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end))
mock = run_doc(WeaveDoc(doc_path); mod = m)
check_output(i, s) = occursin(s, mock.chunks[i].output)
@test check_output(1, script_line)
@test check_output(2, string(m))
@test check_output(3, doc_dir)
@test check_output(4, doc_path)
@test_broken check_output(5, 18)
@test check_output(6, string('"', script_line, '"')) # current working directory

View File

@ -1,6 +1,6 @@
@testset "evaluation module" begin
function mock_output(str, mod = nothing)
result_doc = mock_doc(str; mod = mod)
result_doc = mock_run(str; mod = mod)
return result_doc.chunks[1].output
end