local Y=game:GetService("\084\101\115\116\083\101\114\118\105\099\101")local J=require(script.Parent.Parent.TestEnum)local q=(" "):rep(3)local G={[J.TestStatus.Success]="\043",[J.TestStatus.Failure]="-",[J.TestStatus.Skipped]="~"}local p="\063"local L={}local function e(Y,J)return Y.planNode.phrase:lower()<J.planNode.phrase:lower()end local function S(Y,L,Z)L=L or{}Z=Z or 0 if Y.status==J.TestStatus.Skipped then return L end local N if Y.status then local J=G[Y.status]or p N=("\037\115\091\037\115\093 \037\115"):format(q:rep(Z),J,Y.planNode.phrase)else N=("\037\115\037\115"):format(q:rep(Z),Y.planNode.phrase)end table.insert(L,N)table.sort(Y.children,e)for Y,J in ipairs(Y.children)do S(J,L,Z+1)end return L end local function Z(Y)local J={}table.sort(Y.children,e)for Y,q in ipairs(Y.children)do S(q,J,0)end return J end local function N(Y)local J=Z(Y)return table.concat(J,"\n")end function L.report(J)local q={"\084\101\115\116 \114\101\115\117\108\116\115\058";N(J),("\037\100 \112\097\115\115\101\100\044 \037\100 \102\097\105\108\101\100\044 \037\100 \115\107\105\112\112\101\100"):format(J.successCount,J.failureCount,J.skippedCount)}print(table.concat(q,"\n"))if J.failureCount>0 then print(("\037\100 \116\101\115\116 \110\111\100\101\115 \114\101\112\111\114\116\101\100 \102\097\105\108\117\114\101\115\046"):format(J.failureCount))end if#J.errors>0 then print("\069\114\114\111\114\115 \114\101\112\111\114\116\101\100 \098\121 \116\101\115\116\115\058")print("")for J,q in ipairs(J.errors)do Y:Error(q)print("")end end end return L
--[[
	The TextReporter uses the results from a completed test to output text to
	standard output and TestService.
]]

local TestService = game:GetService("TestService")

local TestEnum = require(script.Parent.Parent.TestEnum)

local INDENT = (" "):rep(3)
local STATUS_SYMBOLS = {
	[TestEnum.TestStatus.Success] = "+",
	[TestEnum.TestStatus.Failure] = "-",
	[TestEnum.TestStatus.Skipped] = "~"
}
local UNKNOWN_STATUS_SYMBOL = "?"

local TextReporter = {}

local function compareNodes(a, b)
	return a.planNode.phrase:lower() < b.planNode.phrase:lower()
end

local function reportNode(node, buffer, level)
	buffer = buffer or {}
	level = level or 0

	if node.status == TestEnum.TestStatus.Skipped then
		return buffer
	end

	local line

	if node.status then
		local symbol = STATUS_SYMBOLS[node.status] or UNKNOWN_STATUS_SYMBOL

		line = ("%s[%s] %s"):format(
			INDENT:rep(level),
			symbol,
			node.planNode.phrase
		)
	else
		line = ("%s%s"):format(
			INDENT:rep(level),
			node.planNode.phrase
		)
	end

	table.insert(buffer, line)
	table.sort(node.children, compareNodes)

	for _, child in ipairs(node.children) do
		reportNode(child, buffer, level + 1)
	end

	return buffer
end

local function reportRoot(node)
	local buffer = {}
	table.sort(node.children, compareNodes)

	for _, child in ipairs(node.children) do
		reportNode(child, buffer, 0)
	end

	return buffer
end

local function report(root)
	local buffer = reportRoot(root)

	return table.concat(buffer, "\n")
end

function TextReporter.report(results)
	local resultBuffer = {
		"Test results:",
		report(results),
		("%d passed, %d failed, %d skipped"):format(
			results.successCount,
			results.failureCount,
			results.skippedCount
		)
	}

	print(table.concat(resultBuffer, "\n"))

	if results.failureCount > 0 then
		print(("%d test nodes reported failures."):format(results.failureCount))
	end

	if #results.errors > 0 then
		print("Errors reported by tests:")
		print("")

		for _, message in ipairs(results.errors) do
			TestService:Error(message)

			-- Insert a blank line after each error
			print("")
		end
	end
end

return TextReporter