Browse Source

better test coverage for markdown writer

pull/5/head
Fredrik Ekre 8 years ago
parent
commit
40dea1d6c1
  1. 161
      test/runtests.jl

161
test/runtests.jl

@ -154,98 +154,103 @@ content = """
""" """
@testset "Examples.markdown" begin @testset "Examples.markdown" begin
withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Examples.jl", mktempdir(@__DIR__) do sandbox
"TRAVIS_TAG" => "v1.2.0", cd(sandbox) do
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do # write content to inputfile
# test defaults inputfile = "inputfile.jl"
mktempdir(@__DIR__) do sandbox write(inputfile, content)
cd(sandbox) do outdir = mktempdir(pwd())
# write content to inputfile
inputfile = "inputfile.jl" # test defaults
write(inputfile, content) withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Examples.jl",
outdir = mktempdir(pwd()) "TRAVIS_TAG" => "v1.2.0",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do
Examples.markdown(inputfile, outdir) Examples.markdown(inputfile, outdir)
expected_markdown = """ end
```@meta expected_markdown = """
EditURL = "https://github.com/fredrikekre/Examples.jl/blob/master/test/$(basename(sandbox))/inputfile.jl" ```@meta
``` EditURL = "https://github.com/fredrikekre/Examples.jl/blob/master/test/$(basename(sandbox))/inputfile.jl"
```
Line 1 Line 1
```@example inputfile ```@example inputfile
Line 2 Line 2
``` ```
Line 3 Line 3
```@example inputfile ```@example inputfile
Line 4 Line 4
# #' Line 11 # #' Line 11
# Line 12 # Line 12
``` ```
```@example inputfile; continued = true ```@example inputfile; continued = true
Line 14 Line 14
Line 15 Line 15
``` ```
Line 16 Line 16
```@example inputfile ```@example inputfile
Line 17 Line 17
``` ```
https://github.com/fredrikekre/Examples.jl/blob/master/ https://github.com/fredrikekre/Examples.jl/blob/master/
```@example inputfile ```@example inputfile
https://github.com/fredrikekre/Examples.jl/blob/master/ https://github.com/fredrikekre/Examples.jl/blob/master/
``` ```
https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/v1.2.0/ https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/v1.2.0/
```@example inputfile ```@example inputfile
https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/v1.2.0/ https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/v1.2.0/
``` ```
""" """
@test read(joinpath(outdir, "inputfile.md"), String) == expected_markdown @test read(joinpath(outdir, "inputfile.md"), String) == expected_markdown
end
end # no tag -> latest directory
# test kwargs and pre- and post-processing withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Examples.jl",
mktempdir(@__DIR__) do sandbox "TRAVIS_TAG" => "",
cd(sandbox) do "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do
# write content to inputfile Examples.markdown(inputfile, outdir)
inputfile = "inputfile.jl"
write(inputfile, content)
outdir = mktempdir(pwd())
# pre- and post-processing
Examples.markdown(inputfile, outdir,
preprocess = x -> replace(x, "Line 11" => "Foo"),
postprocess = x -> replace(x, "Line 12" => "Bar"))
markdown = read(joinpath(outdir, "inputfile.md"), String)
@test !contains(markdown, "Line 11")
@test contains(markdown, "Foo")
@test !contains(markdown, "Line 12")
@test contains(markdown, "Bar")
# documenter = false
Examples.markdown(inputfile, outdir, documenter = false)
markdown = read(joinpath(outdir, "inputfile.md"), String)
@test contains(markdown, "```julia")
@test !contains(markdown, "```@example")
@test !contains(markdown, "continued = true")
@test !contains(markdown, "EditURL")
# codefence
Examples.markdown(inputfile, outdir, codefence = "```c" => "```")
markdown = read(joinpath(outdir, "inputfile.md"), String)
@test contains(markdown, "```c")
@test !contains(markdown, "```@example")
@test !contains(markdown, "```julia")
# name
Examples.markdown(inputfile, outdir, name = "foobar")
markdown = read(joinpath(outdir, "foobar.md"), String)
@test contains(markdown, "```@example foobar")
@test !contains(markdown, "```@example inputfile")
end end
markdown = read(joinpath(outdir, "inputfile.md"), String)
@test contains(markdown, "fredrikekre/Examples.jl/blob/gh-pages/latest/")
# pre- and post-processing
Examples.markdown(inputfile, outdir,
preprocess = x -> replace(x, "Line 11" => "Foo"),
postprocess = x -> replace(x, "Line 12" => "Bar"))
markdown = read(joinpath(outdir, "inputfile.md"), String)
@test !contains(markdown, "Line 11")
@test contains(markdown, "Foo")
@test !contains(markdown, "Line 12")
@test contains(markdown, "Bar")
# documenter = false
Examples.markdown(inputfile, outdir, documenter = false)
markdown = read(joinpath(outdir, "inputfile.md"), String)
@test contains(markdown, "```julia")
@test !contains(markdown, "```@example")
@test !contains(markdown, "continued = true")
@test !contains(markdown, "EditURL")
# codefence
Examples.markdown(inputfile, outdir, codefence = "```c" => "```")
markdown = read(joinpath(outdir, "inputfile.md"), String)
@test contains(markdown, "```c")
@test !contains(markdown, "```@example")
@test !contains(markdown, "```julia")
# name
Examples.markdown(inputfile, outdir, name = "foobar")
markdown = read(joinpath(outdir, "foobar.md"), String)
@test contains(markdown, "```@example foobar")
@test !contains(markdown, "```@example inputfile")
end end
end end
end end

Loading…
Cancel
Save