<commit_before>--
-- tests/testfx.lua
-- Automated test framework for Premake.
-- Copyright (c) 2008-2009 <NAME> and the Premake project
--


--
-- Define a namespace for the testing functions
--

	test = { }


--
-- Assertion functions
--
	function test.string_contains(buffer, expected)
		if not string.find(buffer,expected) then
			test.fail("\n==Fail==: Expected to find :\n%s\nyet it was not found in buffer:\n%s\n", expected,buffer)
		end
	end
	
	function test.string_does_not_contain(buffer, expected)
		if string.find(buffer,expected) then
			test.fail("\n==Fail==: Did not expected to find :\n%s\nyet it was found in buffer:\n%s\n", expected,buffer)
		end
	end
	
	function test.capture(expected)
		local actual = io.endcapture()
		
		-- create line-by-line iterators for both values
		local ait = actual:gfind("(.-)" .. io.eol)
		local eit = expected:gfind("(.-)\n")
		
		-- compare each value line by line
		local linenum = 1
		local atxt = ait()
		local etxt = eit()
		while etxt do
			if (etxt ~= atxt) then
				test.fail("(%d) expected:\n%s\n...but was:\n%s", linenum, etxt, atxt)
			end
			
			linenum = linenum + 1
			atxt = ait()
			etxt = eit()
		end
	end

	
	function test.closedfile(expected)
		if expected and not test.value_closedfile then
			test.fail("expected file to be closed")
		elseif not expected and test.value_closedfile then
			test.fail("expected file to remain open")
		end
	end
	

	function test.contains(value, expected)
		if not table.contains(value, expected) then
			test.fail("expected value %s not found", expected)
		end
	end
	
		
	function test.fail(format, ...)
		-- convert nils into something more usefuls
		for i = 1, arg.n do
			if (arg[i] == nil) then 
				arg[i] = "(nil)"
			elseif (type(arg[i]) == "table") then
				arg[i] = "{" .. table.concat(arg[i], ", ") .. "}"
			end
		end
		error(string.format(format, unpack(arg)), 3)
	end
		
	
	function test.filecontains(expected, fn)
		local f = io.open(fn)
		local actual = f:read("*a")
		f:close()
		if (expected ~= actual) then
			test.fail("expected %s but was %s", expected, actual)
		end
	end
	

	function test.isemptycapture()
		local actual = io.endcapture()
		if actual ~= "" then
			test.fail("expected empty capture, but was %s", actual);
		end
	end

	
	function test.isequal(expected, actual)
		if type(expected) == "table" then
			if #expected < #actual then
				test.fail("expected %d items, got %d", #expected, #actual)
			end
			for k,v in pairs(expected) do
				if not (test.isequal(expected[k], actual[k])) then
					test.fail("expected %s but was %s", expected, actual)<commit_msg>Improved error message for nil table comparison in testing framework<commit_after>--
-- tests/testfx.lua
-- Automated test framework for Premake.
-- Copyright (c) 2008-2009 <NAME> and the Premake project
--


--
-- Define a namespace for the testing functions
--

	test = { }


--
-- Assertion functions
--
	function test.string_contains(buffer, expected)
		if not string.find(buffer,expected) then
			test.fail("\n==Fail==: Expected to find :\n%s\nyet it was not found in buffer:\n%s\n", expected,buffer)
		end
	end
	
	function test.string_does_not_contain(buffer, expected)
		if string.find(buffer,expected) then
			test.fail("\n==Fail==: Did not expected to find :\n%s\nyet it was found in buffer:\n%s\n", expected,buffer)
		end
	end
	
	function test.capture(expected)
		local actual = io.endcapture()
		
		-- create line-by-line iterators for both values
		local ait = actual:gfind("(.-)" .. io.eol)
		local eit = expected:gfind("(.-)\n")
		
		-- compare each value line by line
		local linenum = 1
		local atxt = ait()
		local etxt = eit()
		while etxt do
			if (etxt ~= atxt) then
				test.fail("(%d) expected:\n%s\n...but was:\n%s", linenum, etxt, atxt)
			end
			
			linenum = linenum + 1
			atxt = ait()
			etxt = eit()
		end
	end

	
	function test.closedfile(expected)
		if expected and not test.value_closedfile then
			test.fail("expected file to be closed")
		elseif not expected and test.value_closedfile then
			test.fail("expected file to remain open")
		end
	end
	

	function test.contains(value, expected)
		if not table.contains(value, expected) then
			test.fail("expected value %s not found", expected)
		end
	end
	
		
	function test.fail(format, ...)
		-- convert nils into something more usefuls
		for i = 1, arg.n do
			if (arg[i] == nil) then 
				arg[i] = "(nil)"
			elseif (type(arg[i]) == "table") then
				arg[i] = "{" .. table.concat(arg[i], ", ") .. "}"
			end
		end
		error(string.format(format, unpack(arg)), 3)
	end
		
	
	function test.filecontains(expected, fn)
		local f = io.open(fn)
		local actual = f:read("*a")
		f:close()
		if (expected ~= actual) then
			test.fail("expected %s but was %s", expected, actual)
		end
	end
	

	function test.isemptycapture()
		local actual = io.endcapture()
		if actual ~= "" then
			test.fail("expected empty capture, but was %s", actual);
		end
	end

	
	function test.isequal(expected, actual)
		if type(expected) == "table" then
			if expected and not actual then
				test.fail("expected table, got nil")
			end
			if #expected < #actual then
				test.fail("expected %d items, got %d", #expected, #actual)
			end
			for k,v in pairs(expected) do
				if not (test.isequal(expected[k], actual[k])) then
					test.fail("expected %s but was %s", expected, actual)
{'fraction_non_alphanumeric': 0.1380863039399625, 'fraction_numerical': 0.00450281425891182, 'mean_word_length': 3.204258675078864, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4465011', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1796, 'n_words': 563}