From 3fd65494b148f88d77ce7aeaa03246f3a79850c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 16 Feb 2023 13:43:07 +0100 Subject: [PATCH] Use sandboxing for examples --- examples/run_examples.jl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/run_examples.jl b/examples/run_examples.jl index 5522935ba..c696f7bbc 100644 --- a/examples/run_examples.jl +++ b/examples/run_examples.jl @@ -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 @@ -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