local l=import("\046\047\119\097\114\110")local function B()local l=io.stderr local B=spy.new(function() end)io.stderr={write=B}return l,B end describe("\102\117\110\099\116\105\111\110\115\046\119\097\114\110",function()it("\115\104\111\117\108\100 \098\101 \097 \102\117\110\099\116\105\111\110",function()assert.is_function(l)end)it("\115\104\111\117\108\100 \119\097\114\110",function()local u,Y=B()l("\068\111\103\101 \104\097\115 \116\097\107\101\110 \111\118\101\114 \116\104\101 \119\111\114\108\100\033");(assert.spy(Y)).was_called_with(io.stderr,"\068\111\103\101 \104\097\115 \116\097\107\101\110 \111\118\101\114 \116\104\101 \119\111\114\108\100\033")io.stderr=u end)it("\115\104\111\117\108\100 \119\097\114\110 \119\105\116\104 \109\117\108\116\105\112\108\101 \097\114\103\117\109\101\110\116\115",function()local u,Y=B()l("\073\084\'\083 \068\079\071\069\033","\065\065\072\033");(assert.spy(Y)).was.called(4)io.stderr=u end)it("\115\104\111\117\108\100 \119\097\114\110 \119\105\116\104 \097 \110\111\110-\115\116\114\105\110\103 \097\114\103\117\109\101\110\116",function()local u,Y=B()l(1);(assert.spy(Y)).was_called_with(io.stderr,"\049")io.stderr=u end)it("\115\104\111\117\108\100 \119\097\114\110 \119\105\116\104 \110\111\110-\115\116\114\105\110\103 \097\114\103\117\109\101\110\116\115",function()local u,Y=B()l(2,3);(assert.spy(Y)).was.called(4)io.stderr=u end)end)
local warn = import("./warn")

local function setupWarnDetour()
	local oldErr = io.stderr

	local writeSpy = spy.new(function() end)

	io.stderr = { -- luacheck: ignore
		write = writeSpy
	}

	return oldErr, writeSpy
end

describe("functions.warn", function()
	it("should be a function", function()
		assert.is_function(warn)
	end)

	it("should warn", function()
		local oldErr, writeSpy = setupWarnDetour()
		warn("Doge has taken over the world!")
		assert.spy(writeSpy).was_called_with(io.stderr, "Doge has taken over the world!")
		io.stderr = oldErr -- luacheck: ignore
	end)

	it("should warn with multiple arguments", function()
		local oldErr, writeSpy = setupWarnDetour()
		warn("IT'S DOGE!", "AAH!")
		assert.spy(writeSpy).was.called(4) -- IT'S DOGE, \t, AAH!, \n
		io.stderr = oldErr -- luacheck: ignore
	end)

	it("should warn with a non-string argument", function()
		local oldErr, writeSpy = setupWarnDetour()
		warn(1)
		assert.spy(writeSpy).was_called_with(io.stderr, "1")
		io.stderr = oldErr -- luacheck: ignore
	end)

	it("should warn with non-string arguments", function()
		local oldErr, writeSpy = setupWarnDetour()
		warn(2, 3)
		assert.spy(writeSpy).was.called(4) -- 2, \t, 3, \n
		io.stderr = oldErr -- luacheck: ignore
	end)
end)