diff --git a/.gitignore b/.gitignore index 5b29fbd..c96e00f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ +Manifest.toml -src/*.cov -test.jl examples/figures/ examples/*.md examples/*.pdf @@ -22,15 +21,9 @@ test/**/*.ipynb doc/build doc/site -stable/ -doc/Manifest.toml -Manifest.toml -tmp/ .idea *.*~ *.aux *.log *.out -\#*\# -.juliahistory diff --git a/Project.toml b/Project.toml index 1183ac6..0a2c047 100644 --- a/Project.toml +++ b/Project.toml @@ -27,12 +27,10 @@ julia = "1.2" [extras] Cairo = "159f3aea-2a34-519c-b102-8c37f9878175" -Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004" -IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Cairo", "Conda", "DataFrames", "Gadfly", "IJulia", "Plots", "Test"] +test = ["Cairo", "DataFrames", "Gadfly", "Plots", "Test"] diff --git a/src/plots.jl b/src/plots.jl index 5f6059e..9211c35 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -10,7 +10,7 @@ function plots_set_size!(chunk) Plots.default(size = (w, h)) end -Weave.push_preexecution_hook!(plots_set_size) +Weave.push_preexecution_hook!(plots_set_size!) # PNG or SVG is not working, output html function Base.display( diff --git a/test/cache_test.jl b/test/cache_test.jl index ee87b78..d2d8943 100644 --- a/test/cache_test.jl +++ b/test/cache_test.jl @@ -1,7 +1,4 @@ -using Weave -using Test - -#Test if running document with and without cache works +# Test if running document with and without cache works isdir("documents/cache") && rm("documents/cache", recursive = true) weave("documents/chunk_options.noweb", cache=:all) result = read("documents/chunk_options.md", String) diff --git a/test/documents/jupyter_test.jmd b/test/documents/jupyter_test.jmd deleted file mode 100644 index ae0570a..0000000 --- a/test/documents/jupyter_test.jmd +++ /dev/null @@ -1,17 +0,0 @@ -Here's some text - -And here's some code - -```julia - x = 1 - y = 2 - @show x + y -``` - -Here's some more complicated code - -```julia - @code_native +(1.0, π) - using Test - @test 1 == 1 -``` diff --git a/test/documents/markdown_beamer.jmd b/test/documents/markdown_beamer.jmd deleted file mode 100644 index a07602c..0000000 --- a/test/documents/markdown_beamer.jmd +++ /dev/null @@ -1,31 +0,0 @@ ---- -title: A minimal beamer example using Weave markdown -author: Matti Pastell -weave_options: - out_path: inline ---- - -```julia; echo=false -struct Begin - text - title -end - -struct End - text -end -Base.show(io::IO, m::MIME"text/latex", b::Begin) = write(io, "\\begin{$(b.text)}[fragile]\n\\frametitle{$(b.title)}\n") -Base.show(io::IO, m::MIME"text/latex", e::End) = write(io, "\\end{$(e.text)}") - -Base.show(io::IO, m::MIME"text/html", b::Begin) = write(io, "
\n") -Base.show(io::IO, m::MIME"text/html", e::End) = write(io, "
") -``` - -! Begin("frame", "Random plot") - -Some inline `j print("output")` - -```julia -println("Testing output") -``` -! End("frame") diff --git a/test/documents/markdown_output.jmd b/test/documents/markdown_output.jmd deleted file mode 100644 index 68769cc..0000000 --- a/test/documents/markdown_output.jmd +++ /dev/null @@ -1,31 +0,0 @@ - - -```julia -display("text/markdown", -""" - -### Small markdown sample - -**Hello** from `code` block. - -""") -``` - - -```julia -struct Dummy - s::String -end - -function Base.show(io::IO, m::MIME"text/markdown", d::Dummy) - print(io, d.s) -end - -Dummy(""" - -* one -* two -* three - -""") -``` diff --git a/test/end2end.jl b/test/end2end.jl deleted file mode 100644 index ac9af4e..0000000 --- a/test/end2end.jl +++ /dev/null @@ -1,32 +0,0 @@ -# NOTE -# this file keeps old end2end tests, which are very fragile -# - they are being gradually replaced with unit tests, that are much more maintainable and -# much more helpful for detecting bugs -# - the purpose of this file is to temporarily keep the old end2end tests in a way that -# they're allowed to fail - -tpl = mt""" -{{{ :body }}} -""" - -out = weave(joinpath(@__DIR__, "documents", "markdown_beamer.jmd"), doctype="md2html", template=tpl) -@test read(out, String) == read(out*".ref", String) -rm(out) - -out = weave(joinpath(@__DIR__, "documents", "markdown_beamer.jmd"), doctype="md2tex", template=tpl) -@test read(out, String) == read(out*".ref", String) -rm(out) - - -@testset "chunk options" begin - -result = read("documents/chunk_options.md", String) -ref = read("documents/chunk_options_ref.md", String) -@test result == ref - -tangle("documents/chunk_options.noweb", out_path = "documents/tangle") -result = read("documents/tangle/chunk_options.jl", String) -ref = read("documents/tangle/chunk_options.jl.ref", String) -@test ref == result - -end diff --git a/test/formatter_test.jl b/test/formatter_test.jl index 11a03e8..52fb9d5 100644 --- a/test/formatter_test.jl +++ b/test/formatter_test.jl @@ -1,85 +1,3 @@ -# TODO: this test is horrible, refactor - -using Weave: Highlights.Themes.DefaultTheme - -# Test rendering of doc chunks -content = """ -# Test chunk - -Test rendering \$\alpha\$ -""" - -dchunk = Weave.DocChunk(content, 1, 1) - -pformat = Weave.FORMATS["github"] -f = Weave.format_chunk(dchunk, pformat) -@test f == content - -docformat = Weave.FORMATS["md2html"] -f_check = "

Test chunk

\n

Test rendering \$\alpha\$

\n" -f = Weave.format_chunk(dchunk, docformat) -@test f_check == f - -# Test with actual doc - -parsed = Weave.WeaveDoc("documents/chunk_options.noweb") -doc = run_doc(parsed, doctype = "md2html") - -c_check = "
\nx = [12, 10]\nprintln(y)\n
\n" -doc.format.highlight_theme = DefaultTheme -c = Weave.format_code(doc.chunks[3].content, doc.format) -@test c_check == c - -o_check = "\nprintln(x)\n" -o = Weave.format_output(doc.chunks[4].content, doc.format) -@test o_check == o - -# Tex format -parsed = Weave.WeaveDoc("documents/chunk_options.noweb") -doc = run_doc(parsed, doctype = "md2tex") - -c_check = "\\begin{lstlisting}\n(*@\\HLJLnf{println}@*)(*@\\HLJLp{(}@*)(*@\\HLJLn{x}@*)(*@\\HLJLp{)}@*)\n\\end{lstlisting}\n" -doc.format.highlight_theme = DefaultTheme -c = Weave.format_code(doc.chunks[4].content, doc.format) -@test c_check == c - -o_check = "\nx = [12, 10]\nprintln(y)\n" -o = Weave.format_output(doc.chunks[3].content, doc.format) -@test o_check == o - -# Test wrapping - -cows = repeat("🐄", 100) -testcows = """ -🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄 -🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄""" - -wcows = Weave.wrapline(cows) - -@test wcows == testcows -@test length(split(wcows, "\n")[1]) == 75 -@test length(split(wcows, "\n")[2]) == 25 - - -tfied = "\\ensuremath{\\bm{\\mathrm{L}}} \\ensuremath{\\bm{\\mathfrak{F}}} \\ensuremath{\\bm{\\iota}} \\ensuremath{\\mathfrak{A}} \\ensuremath{\\bm{\\varTheta}}" - -@test Weave.uc2tex("𝐋 𝕱 𝛊 𝔄 𝚹") == tfied - -# Test markdown output from chunks -parsed = Weave.WeaveDoc("documents/markdown_output.jmd") -doc = run_doc(parsed, doctype = "md2html") -@test doc.chunks[1].rich_output == "\n

Small markdown sample

\n

Hello from code block.

\n
" -@test doc.chunks[2].rich_output == "\n
\n
" - -ldoc = run_doc(parsed, doctype = "md2tex") -@test ldoc.chunks[1].rich_output == "\n\\subsubsection{Small markdown sample}\n\\textbf{Hello} from \\texttt{code} block.\n\n" -@test ldoc.chunks[2].rich_output == "\n\\begin{itemize}\n\\item one\n\n\n\\item two\n\n\n\\item three\n\n\\end{itemize}\n" - -mdoc = run_doc(parsed, doctype = "github") -@test mdoc.chunks[1].rich_output == "\n\n### Small markdown sample\n\n**Hello** from `code` block.\n\n" -@test mdoc.chunks[2].rich_output == "\n\n* one\n* two\n* three\n\n" - - # Test disable escaping of unicode @testset "escape/unescape unicode characters" begin diff --git a/test/markdown_test.jl b/test/markdown_test.jl index ce54618..5d23ccd 100644 --- a/test/markdown_test.jl +++ b/test/markdown_test.jl @@ -1,6 +1,9 @@ -using Test -import Weave: WeaveMarkdown -import Markdown +# TODO: make this more sensible: +# - separate tests for +# 1. features that are "copy-and-pasted" from `Markdown` module +# 2. features that are extended by Weave + +using Weave: WeaveMarkdown, Markdown # Test markdown2html writer diff --git a/test/notebooks.jl b/test/notebooks.jl deleted file mode 100644 index ece21ac..0000000 --- a/test/notebooks.jl +++ /dev/null @@ -1,7 +0,0 @@ -file = joinpath(@__DIR__, "documents", "jupyter_test.jmd") -using IJulia, Conda - -Conda.add("nbconvert") # should be the same as IJulia.JUPYTER, i.e. the miniconda Python - -Weave.notebook(file, jupyter_path = IJulia.JUPYTER) -@test "jupyter_test.ipynb" ∈ readdir(@__DIR__) # test if the result was weaved diff --git a/test/test_chunk_options.jl b/test/reader/test_chunk_options.jl similarity index 100% rename from test/test_chunk_options.jl rename to test/reader/test_chunk_options.jl diff --git a/test/test_inline.jl b/test/reader/test_inline.jl similarity index 100% rename from test/test_inline.jl rename to test/reader/test_inline.jl diff --git a/test/test_error_rendering.jl b/test/run/test_error.jl similarity index 92% rename from test/test_error_rendering.jl rename to test/run/test_error.jl index d3d9c96..f3820a8 100644 --- a/test/test_error_rendering.jl +++ b/test/run/test_error.jl @@ -1,3 +1,5 @@ +@testset "evaluation error handling" begin + using Weave: unwrap_load_err @@ -60,4 +62,4 @@ using NonExisting # will be thrown @test_throws ArgumentError mock_run(str; doctype = "github") -# TODO: test error rendering in `rich_output` +end # @testset "evaluation error handling" diff --git a/test/test_meta.jl b/test/run/test_meta.jl similarity index 74% rename from test/test_meta.jl rename to test/run/test_meta.jl index cacb0b8..144109a 100644 --- a/test/test_meta.jl +++ b/test/run/test_meta.jl @@ -1,3 +1,5 @@ +@testset "meta information for evaluation" begin + doc_body = """ ```julia include("test_include.jl") @@ -23,13 +25,13 @@ include("test_include.jl") read("./test_include.jl", String) ``` """ -doc_dir = joinpath(@__DIR__, "mocks") -doc_path = joinpath(doc_dir, "test_meta.jmd") +doc_dir = normpath(@__DIR__, "..", "mocks") +doc_path = normpath(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") +script_path = normpath(@__DIR__, "..", "mocks", "test_include.jl") write(script_path, script_body) @@ -43,3 +45,5 @@ check_output(i, s) = occursin(s, mock.chunks[i].output) @test check_output(4, doc_path) @test_broken check_output(5, 18) @test check_output(6, string('"', script_line, '"')) # current working directory + +end # @testset "meta information for evaluation" diff --git a/test/run/test_module.jl b/test/run/test_module.jl new file mode 100644 index 0000000..8757953 --- /dev/null +++ b/test/run/test_module.jl @@ -0,0 +1,49 @@ +@testset "module evaluation" begin + +function mock_output(str, mod = nothing) + result_doc = mock_run(str; mod = mod) + return result_doc.chunks[1].output +end + +str = """ +```julia +@__MODULE__ +``` +""" + +# in sandbox +@test occursin(r"\#+WeaveSandBox[\#\d]+", mock_output(str)) + +# in Main +@test strip(mock_output(str, Main)) == "Main" + +end # @testset "module evaluation" + +@testset "clear_module!" begin + +ary = rand(1000000) +size = Base.summarysize(ary) + +# simple case +m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end)) +Core.eval(m, :(a = $ary)) +Weave.clear_module!(m) +@test Base.summarysize(m) < size + +# recursive case +m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end)) +Core.eval(m, :( + module $(gensym(:WeaveTestSubModule)) + a = $ary + end +)) +Weave.clear_module!(m) +@test Base.summarysize(m) < size + +# doesn't work with constants +m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end)) +Core.eval(m, :(const a = $ary)) +Weave.clear_module!(m) +@test_broken Base.summarysize(m) < size + +end # @testset "clear_module!" diff --git a/test/runtests.jl b/test/runtests.jl index 84ba8ed..04b6622 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,10 +1,14 @@ +# TODO: +# - reorganize this +# - test for `include_weave` +# - fire horrible tests +# - test for ipynb integration + +# %% using Weave, Test using Weave: WeaveDoc, run_doc -# TODO: add test for header processsing -# TODO: add test for `include_weave` - function mock_doc(str, informat = "markdown") f = tempname() write(f, str) @@ -27,29 +31,21 @@ function test_mock_weave(test_function, str; kwargs...) end +# %% @testset "Weave" begin - @testset "module evaluation" begin - include("test_module_evaluation.jl") + @testset "reader" begin + include("reader/test_chunk_options.jl") + include("reader/test_inline.jl") end - @testset "header" begin + @testset "header processing" begin include("test_header.jl") end - @testset "inline" begin - include("test_inline.jl") - end - - @testset "chunk options" begin - 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") + @testset "run" begin + include("run/test_module.jl") + include("run/test_meta.jl") + include("run/test_error.jl") end @testset "conversions" begin @@ -66,15 +62,10 @@ end include("figureformatter_test.jl") end - @testset "Cache" begin + @testset "cache" begin include("cache_test.jl") end - # @testset "Notebooks" begin - # @info("Testing Jupyter options") - # include("notebooks.jl") - # end - # trigger only on CI if get(ENV, "CI", nothing) == "true" @testset "Plots" begin @@ -87,12 +78,4 @@ end else @info "skipped Plots.jl and Gadfly.jl integration test" end - - try - @testset "end2end (maybe fail)" begin - include("end2end.jl") - end - catch err - @error err - end end diff --git a/test/templates/mini.tpl b/test/templates/mini.tpl deleted file mode 100644 index 6279a0f..0000000 --- a/test/templates/mini.tpl +++ /dev/null @@ -1,2 +0,0 @@ - -{{{ :body }}} diff --git a/test/test_module_evaluation.jl b/test/test_module_evaluation.jl deleted file mode 100644 index bc2d3cb..0000000 --- a/test/test_module_evaluation.jl +++ /dev/null @@ -1,45 +0,0 @@ -@testset "evaluation module" begin - function mock_output(str, mod = nothing) - result_doc = mock_run(str; mod = mod) - return result_doc.chunks[1].output - end - - str = """ - ```julia - @__MODULE__ - ``` - """ - - # in sandbox - @test occursin(r"\#+WeaveSandBox[\#\d]+", mock_output(str)) - - # in Main - @test strip(mock_output(str, Main)) == "Main" -end - -@testset "clear_module!" begin - ary = rand(1000000) - size = Base.summarysize(ary) - - # simple case - m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end)) - Core.eval(m, :(a = $ary)) - Weave.clear_module!(m) - @test Base.summarysize(m) < size - - # recursive case - m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end)) - Core.eval(m, :( - module $(gensym(:WeaveTestSubModule)) - a = $ary - end - )) - Weave.clear_module!(m) - @test Base.summarysize(m) < size - - # doesn't work with constants - m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end)) - Core.eval(m, :(const a = $ary)) - Weave.clear_module!(m) - @test_broken Base.summarysize(m) < size -end