Skip to content

Commit

Permalink
Use sandboxing for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Feb 16, 2023
1 parent fab0eca commit 3fd6549
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion examples/run_examples.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
using Test

"""
_include_sandbox(filename)
Include the `filename` in a temporary module that acts as a sandbox. (Ensuring
no constants or functions leak into other files.)
This function was taken from `JuMP/docs/make.jl`.
"""
function _include_sandbox(filename)
mod = @eval module $(gensym()) end
return Base.include(mod, filename)
end

const _TUTORIAL_DIR = joinpath(@__DIR__, "..", "docs", "src", "tutorials")

@testset "run_examples.jl" begin
Expand All @@ -9,7 +22,7 @@ const _TUTORIAL_DIR = joinpath(@__DIR__, "..", "docs", "src", "tutorials")
continue
end
path = joinpath(_TUTORIAL_DIR, dir, filename)
include(path)
_include_sandbox(path)
end
end
@testset "Chordal" begin
Expand Down

0 comments on commit 3fd6549

Please sign in to comment.