Skip to content

Commit 3fd6549

Browse files
committed
Use sandboxing for examples
1 parent fab0eca commit 3fd6549

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

examples/run_examples.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
using Test
22

3+
"""
4+
_include_sandbox(filename)
5+
6+
Include the `filename` in a temporary module that acts as a sandbox. (Ensuring
7+
no constants or functions leak into other files.)
8+
9+
This function was taken from `JuMP/docs/make.jl`.
10+
"""
11+
function _include_sandbox(filename)
12+
mod = @eval module $(gensym()) end
13+
return Base.include(mod, filename)
14+
end
15+
316
const _TUTORIAL_DIR = joinpath(@__DIR__, "..", "docs", "src", "tutorials")
417

518
@testset "run_examples.jl" begin
@@ -9,7 +22,7 @@ const _TUTORIAL_DIR = joinpath(@__DIR__, "..", "docs", "src", "tutorials")
922
continue
1023
end
1124
path = joinpath(_TUTORIAL_DIR, dir, filename)
12-
include(path)
25+
_include_sandbox(path)
1326
end
1427
end
1528
@testset "Chordal" begin

0 commit comments

Comments
 (0)