require('os')

function report( s )
	print('>>>>>>> '..s )
end

function validate_junit_xml()
	-- validate that junit output is a valid xml file
	-- this assumes that xmllint is installed !
	
	fnameJunitXml = 'output_junit.xml' -- os.tmpname()
	fnameJunitStdout = 'junit_stdout.txt' -- os.tmpname()
	exitSuccess, exitReason, exitCode = os.execute(string.format(
		'lua example_with_luaunit.lua --output junit --name %s > %s', fnameJunitXml, fnameJunitStdout )	 )
	exitSuccess, exitReason, exitCode = os.execute( string.format( 
		'xmllint %s', fnameJunitXml ) )
	if exitSuccess == true or (exitReason == 'exit' and exitCode == 0) then
		report(string.format('XMLLint validation successful: file %s', fnameJunitXml) )
	else
		report(string.format('XMLLint reported errors : file %s', fnameJunitXml) )
	end

end

validate_junit_xml()
require('os')

function report( s )
	print('>>>>>>> '..s )
end

function validate_junit_xml( generateJunitXml )
	-- Set generateJunitXml to refresh XML. Default is true.

	local retCode = 0
	-- validate that junit output is a valid xml file
	-- this assumes that xmllint is installed !

	if generateJunitXml == nil then
		generateJunitXml = true
	end

	fnameJunitXml = 'output_junit.xml' -- os.tmpname()
	fnameJunitStdout = 'junit_stdout.txt' -- os.tmpname()
	if generateJunitXml then
		exitSuccess, exitReason, exitCode = os.execute(string.format(
			'lua example_with_luaunit.lua --output junit --name %s > %s', fnameJunitXml, fnameJunitStdout )	 )
	end
	exitSuccess, exitReason, exitCode = os.execute( string.format( 
		'xmllint %s', fnameJunitXml ) )

	-- Lua 5.1 : exitSuccess == 0
	-- Lua 5.2 : exitSuccess == true and exitReason == exit and exitCode == 0
	if exitSuccess == 0 or (exitSuccess == true and exitReason == 'exit' and exitCode == 0) then
		report(string.format('XMLLint validation successful: file %s', fnameJunitXml) )
	else
		report(string.format('XMLLint reported errors : file %s', fnameJunitXml) )
		retCode = 1
	end
	return retCode
end


-- main section
errorCount = 0
errorCount = errorCount + validate_junit_xml()
os.exit( errorCount )


Improve run_func_tests and make it compatible with Lua 5.1 / 5.2
Improve run_func_tests and make it compatible with Lua 5.1 / 5.2

- report success in exit code
- structure to support more than one functional test
- option to not generate the xml output to be validated
