local V=true local S={}local function W()local V={warnings={}}setmetatable(V,{__tostring=function(V)return("\076\111\103\073\110\102\111\n\t\087\097\114\110\105\110\103\115 \040\037\100\041\058\n\t\t\037\115"):format(#V.warnings,table.concat(V.warnings,"\n\t\t"))end})return V end local A={}function A.capture(A)local y=W()local R=V V=false S[y]=true local m,U=pcall(A)S[y]=nil V=R assert(m,U)return y end function A.warn(W)for V in pairs(S)do table.insert(V.warnings,W)end if V then warn(W)end end return A
-- This is taken from Roact internal implementation details as a temporary helper
-- so that we can control warnings spew and also validate warning logs in unit tests.
-- We should clean it up and turn it into a nice central logging facility later on.

local outputEnabled = true
local collectors = {}

local function createLogInfo()
	local logInfo = {
		warnings = {},
	}

	setmetatable(logInfo, {
		__tostring = function(self)
			return ("LogInfo\n\tWarnings (%d):\n\t\t%s"):format(#self.warnings, table.concat(self.warnings, "\n\t\t"))
		end,
	})

	return logInfo
end

local Logging = {}

function Logging.capture(callback)
	local collector = createLogInfo()

	local wasOutputEnabled = outputEnabled
	outputEnabled = false
	collectors[collector] = true

	local success, result = pcall(callback)

	collectors[collector] = nil
	outputEnabled = wasOutputEnabled

	assert(success, result)

	return collector
end

function Logging.warn(message)
	for collector in pairs(collectors) do
		table.insert(collector.warnings, message)
	end

	if outputEnabled then
		warn(message)
	end
end

return Logging
