diff --git a/.travis.yml b/.travis.yml index 72a07ab..98a4f05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ script: - julia --color=yes runtests.jl jive - julia --color=yes runtests.jl jive/s jive/m start=2 - julia --color=yes -pauto runtests.jl jive/s jive/m start=2 - - julia --color=yes -pauto -e 'using Jive; runtests(@__DIR__, skip=["Example", "errors", "jive/onlyonce/heavy.jl", "jive/s"], node1=["jive/m"])' + - julia --color=yes -pauto -e 'using Jive; runtests(@__DIR__, skip=["Example", "errors", "jive/onlyonce/heavy.jl", "jive/__END__/included.jl", "jive/s"], node1=["jive/m"])' - julia --color=yes -pauto -e 'using Jive; runtests(@__DIR__, targets=["errors", "jive"], node1=["jive/m"])' || true - cd Example diff --git a/docs/make.jl b/docs/make.jl index 474dcc8..180793b 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -17,5 +17,6 @@ makedocs( "@If" => "If.md", "@useinside" => "useinside.md", "@mockup" => "mockup.md", + "`@__END__`" => "END.md", ], ) diff --git a/docs/src/END.md b/docs/src/END.md new file mode 100644 index 0000000..04fc7bc --- /dev/null +++ b/docs/src/END.md @@ -0,0 +1,7 @@ +# `@__END__` + +`throw(Jive.EndError())` + +```@docs +Jive.@__END__ +``` diff --git a/src/Jive.jl b/src/Jive.jl index 61c7ff9..b53879c 100644 --- a/src/Jive.jl +++ b/src/Jive.jl @@ -15,6 +15,9 @@ include("If.jl") export @useinside include("useinside.jl") +export @__END__ +include("__END__.jl") + export runtests include("runtests.jl") diff --git a/src/__END__.jl b/src/__END__.jl new file mode 100644 index 0000000..3b5908a --- /dev/null +++ b/src/__END__.jl @@ -0,0 +1,33 @@ +# module Jive + +struct EndError <: Exception +end + +function isenderror(ex::LoadError) + if ex.error isa EndError + return true + elseif ex.error isa LoadError + return isenderror(ex.error) + else + return false + end +end + +""" + @__END__ + +`throw(Jive.EndError())` +""" +macro __END__() + @eval function Base.showerror(io::IO, ex::LoadError, bt; backtrace=true) + if isenderror(ex) + printstyled(io, "@__END__", color=:cyan) + print(io, " at ", basename(ex.file), ":", ex.line) + else + print(io, "Error while loading expression starting at ", ex.file, ":", ex.line) + end + end + throw(EndError()) +end + +# module Jive diff --git a/test/jive/__END__/included.jl b/test/jive/__END__/included.jl new file mode 100644 index 0000000..4d2a675 --- /dev/null +++ b/test/jive/__END__/included.jl @@ -0,0 +1,4 @@ +using Jive +push!(stack, 10) +@__END__ +push!(stack, 20) diff --git a/test/jive/__END__/test.jl b/test/jive/__END__/test.jl new file mode 100644 index 0000000..d22c2d9 --- /dev/null +++ b/test/jive/__END__/test.jl @@ -0,0 +1,23 @@ +module test_jive__END__ + +using Test + +stack = [] + +try + include("included.jl") +catch + push!(stack, 1) +end + +try + include("included.jl") +catch + push!(stack, 2) +end + +push!(stack, 3) + +@test stack == [10, 1, 10, 2, 3] + +end # module test_jive__END__ diff --git a/test/runtests.jl b/test/runtests.jl index 9429f35..02797c2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,2 +1,2 @@ using Jive # runtests -runtests(@__DIR__, skip=["Example", "errors", "jive/onlyonce/heavy.jl"]) +runtests(@__DIR__, skip=["Example", "errors", "jive/onlyonce/heavy.jl", "jive/__END__/included.jl"])