local a=require(script.Parent.Parent.TestEZ)local function O(O,Y)local m=a.TestPlanner.createPlan({{method=function()setfenv(Y,getfenv())Y()end,path={"\101\114\114\111\114\084\121\112\101\084\101\115\116\115"}}})local S=a.TestRunner.runPlan(m)assert(#S.errors>0,"\069\120\112\101\099\116\101\100 \115\111\109\101 \101\114\114\111\114\115\044 \103\111\116 \110\111\110\101\046")for a,Y in ipairs(S.errors)do local m=string.find(Y,O)assert(m,string.format("\069\120\112\101\099\116\101\100 \101\114\114\111\114\115 \099\111\110\116\097\105\110\105\110\103 \091\037\115\093\044 \102\111\117\110\100 \091\037\115\093",O,Y))end end return{["\069\114\114\111\114 \109\101\115\115\097\103\101 \115\104\111\117\108\100 \115\104\111\119 \117\112 \105\110 \111\117\116\112\117\116"]=function()O("\070\079\079",function()error("\070\079\079")end)end,["\069\114\114\111\114\105\110\103 \119\105\116\104 \097\110 \111\098\106\101\099\116 \115\104\111\117\108\100 \109\101\110\116\105\111\110 \116\104\101 \111\098\106\101\099\116"]=function()O("\116\097\098\108\101\058",function()error({})end)end;["\069\114\114\111\114\105\110\103 \119\105\116\104 \097\110 \111\098\106\101\099\116 \119\105\116\104 \095\095\116\111\115\116\114\105\110\103 \115\104\111\117\108\100 \115\104\111\119 \116\104\101 \115\116\114\105\110\103"]=function()O("\070\079\079",function()local a=setmetatable({},{__tostring=function()return"\070\079\079"end})error(a)end)end}
local TestEZ = require(script.Parent.Parent.TestEZ)

local function check(str, test)
	local plan = TestEZ.TestPlanner.createPlan({
		{
			-- This function environment hack is needed because the test
			-- function is not defined or required from within a test. This
			-- shouldn't come up in real tests.
			method = function()
				setfenv(test, getfenv())
				test()
			end,
			path = {"errorTypeTests"}
		}
	})

	local results = TestEZ.TestRunner.runPlan(plan)

	assert(#results.errors > 0, "Expected some errors, got none.")
	for _, err in ipairs(results.errors) do
		local find = string.find(err, str)
		assert(find, string.format("Expected errors containing [%s], found [%s]", str, err))
	end
end

return {
	["Error message should show up in output"] = function()
		check("FOO", function()
			error("FOO")
		end)
	end,
	["Erroring with an object should mention the object"] = function()
		check("table:", function()
			error({})
		end)
	end,
	["Erroring with an object with __tostring should show the string"] = function()
		check("FOO", function()
			local obj = setmetatable({}, {__tostring=function()
				return "FOO"
			end})
			error(obj)
		end)
	end,
}
