diff --git a/busted/context.lua b/busted/context.lua index a93a903a..6596302a 100644 --- a/busted/context.lua +++ b/busted/context.lua @@ -23,9 +23,9 @@ local function restore(state) rawset(_G, k, v) end end - for k,_ in pairs(package.loaded) do - package.loaded[k] = state.loaded[k] - end + local set = function(k) package.loaded[k] = state.loaded[k] end + for k,_ in pairs(package.loaded) do set(k) end + for k,_ in pairs(state.loaded) do set(k) end end return function() diff --git a/busted/core.lua b/busted/core.lua index aa61cb66..9c304fda 100644 --- a/busted/core.lua +++ b/busted/core.lua @@ -1,9 +1,19 @@ +local busted_internal_loaded = {} + +local busted_require = function (path) + local default_loaded = package.loaded + package.loaded = busted_internal_loaded + local pack = require(path) + package.loaded = default_loaded + return pack +end + local getfenv = require 'busted.compatibility'.getfenv local setfenv = require 'busted.compatibility'.setfenv local unpack = require 'busted.compatibility'.unpack -local path = require 'pl.path' -local pretty = require 'pl.pretty' -local system = require 'system' +local path = busted_require 'pl.path' +local pretty = busted_require 'pl.pretty' +local system = busted_require 'system' local throw = error local failureMt = { @@ -42,11 +52,13 @@ local function isCallable(obj) end return function() - local mediator = require 'mediator'() - local busted = {} busted.version = '2.2.0' + busted.require = busted_require + + local mediator = busted.require 'mediator'() + local root = require 'busted.context'() busted.context = root.ref() diff --git a/busted/init.lua b/busted/init.lua index 01d6d4a5..0d368128 100644 --- a/busted/init.lua +++ b/busted/init.lua @@ -87,11 +87,11 @@ local function init(busted) busted.hide('file') - local assert = require 'luassert' - local spy = require 'luassert.spy' - local mock = require 'luassert.mock' - local stub = require 'luassert.stub' - local match = require 'luassert.match' + local assert = busted.require 'luassert' + local spy = busted.require 'luassert.spy' + local mock = busted.require 'luassert.mock' + local stub = busted.require 'luassert.stub' + local match = busted.require 'luassert.match' require 'busted.fixtures' -- just load into the environment, not exposing it diff --git a/busted/runner.lua b/busted/runner.lua index ad8257af..ac8b9eb4 100644 --- a/busted/runner.lua +++ b/busted/runner.lua @@ -1,8 +1,5 @@ -- Busted command-line runner -local path = require 'pl.path' -local tablex = require 'pl.tablex' -local term = require 'term' local utils = require 'busted.utils' local exit = require 'busted.compatibility'.exit local loadstring = require 'busted.compatibility'.loadstring @@ -11,12 +8,16 @@ local loaded = false return function(options) if loaded then return function() end else loaded = true end + local busted = require 'busted.core'() + + local path = busted.require 'pl.path' + local tablex = busted.require 'pl.tablex' + local term = busted.require 'term' + local isatty = io.type(io.stdout) == 'file' and term.isatty(io.stdout) options = tablex.update(require 'busted.options', options or {}) options.output = options.output or (isatty and 'utfTerminal' or 'plainTerminal') - local busted = require 'busted.core'() - local cli = require 'busted.modules.cli'(options) local filterLoader = require 'busted.modules.filter_loader'() local helperLoader = require 'busted.modules.helper_loader'() diff --git a/spec/insulate-expose_spec.lua b/spec/insulate-expose_spec.lua index 4c78e576..af372160 100644 --- a/spec/insulate-expose_spec.lua +++ b/spec/insulate-expose_spec.lua @@ -1,6 +1,20 @@ assert.is_nil(package.loaded.pl) assert.is_nil(package.loaded['pl.file']) +describe('Isolation from Busted', function() + it('in normal blocks', function() + assert.is_nil(package.loaded['pl.path']) + end) + + insulate('in insulated blocks', function() + assert.is_nil(package.loaded['pl.path']) + end) + + expose('in exposed blocks', function() + assert.is_nil(package.loaded['pl.path']) + end) +end) + describe('Tests insulation', function() insulate('environment inside insulate', function() pl = require 'pl'