From 89d66e48657f502b6d7e101266930f961dd3cf63 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Tue, 17 Apr 2018 12:18:09 +0200 Subject: [PATCH] test for script writer --- test/runtests.jl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index dc49459..0871883 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -159,6 +159,70 @@ content = """ @__NBVIEWER_ROOT_URL__ """ +@testset "Examples.script" begin + mktempdir(@__DIR__) do sandbox + cd(sandbox) do + # write content to inputfile + inputfile = "inputfile.jl" + write(inputfile, content) + outdir = mktempdir(pwd()) + + # test defaults + withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Examples.jl", + "TRAVIS_TAG" => "v1.2.0", + "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do + Examples.script(inputfile, outdir) + end + expected_script = """ + Line 2 + + Line 8 + + Line 10 + # #' Line 11 + # Line 12 + + Line 14 + Line 15 + + Line 17 + + https://github.com/fredrikekre/Examples.jl/blob/master/ + + https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/v1.2.0/ + + """ + @test read(joinpath(outdir, "inputfile.jl"), String) == expected_script + + # no tag -> latest directory + withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Examples.jl", + "TRAVIS_TAG" => "", + "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do + Examples.script(inputfile, outdir) + end + script = read(joinpath(outdir, "inputfile.jl"), String) + @test contains(script, "fredrikekre/Examples.jl/blob/gh-pages/latest/") + + # pre- and post-processing + Examples.script(inputfile, outdir, + preprocess = x -> replace(x, "Line 11" => "Foo"), + postprocess = x -> replace(x, "Line 12" => "Bar")) + script = read(joinpath(outdir, "inputfile.jl"), String) + @test !contains(script, "Line 11") + @test contains(script, "Foo") + @test !contains(script, "Line 12") + @test contains(script, "Bar") + + # name + Examples.script(inputfile, outdir, name = "foobar") + namedscript = read(joinpath(outdir, "foobar.jl"), String) + Examples.script(inputfile, outdir) + nonamescrip = read(joinpath(outdir, "inputfile.jl"), String) + @test namedscript == nonamescrip + end + end +end + @testset "Examples.markdown" begin mktempdir(@__DIR__) do sandbox cd(sandbox) do