mirror of
https://github.com/mgcaret/of816.git
synced 2025-01-15 23:31:01 +00:00
enhance unit test runner
This commit is contained in:
parent
06da03f925
commit
e9ab1c0eb4
@ -4,28 +4,74 @@ require 'open3'
|
|||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
require 'timeout'
|
require 'timeout'
|
||||||
|
require 'optparse'
|
||||||
|
|
||||||
TEST_DIR = '../../test'
|
@opts = {
|
||||||
|
test_dir: '../../test',
|
||||||
|
suites: '*',
|
||||||
|
output_file: nil,
|
||||||
|
cov_file: nil,
|
||||||
|
verbose: $DEBUG,
|
||||||
|
list_only: false
|
||||||
|
}
|
||||||
|
|
||||||
|
@coverage = Hash.new(0)
|
||||||
|
|
||||||
|
OptionParser.new do |o|
|
||||||
|
o.banner = "Usage: #{$0} [options]"
|
||||||
|
|
||||||
|
o.on('-d', '--dir TEST_DIR', 'Specify test directory.') do |d|
|
||||||
|
@opts[:test_dir] = d
|
||||||
|
end
|
||||||
|
|
||||||
|
o.on('-s', '--suites PATTERN', 'Specify suites as shell glob.') do |p|
|
||||||
|
@opts[:suites] = p
|
||||||
|
end
|
||||||
|
|
||||||
|
o.on('-o', '--outfile FILENAME', 'Specify test output file (default none).') do |f|
|
||||||
|
@opts[:output_file] = f
|
||||||
|
end
|
||||||
|
|
||||||
|
o.on('-c', '--coverage FILENAME', 'Specify test coverage file (default none).') do |f|
|
||||||
|
@opts[:cov_file] = f
|
||||||
|
end
|
||||||
|
|
||||||
|
o.on('-l', '--list-suites', 'List available test suites.') do |d|
|
||||||
|
@opts[:list_only] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
o.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
||||||
|
@opts[:verbose] = v
|
||||||
|
end
|
||||||
|
|
||||||
|
o.on_tail("-h", "--help", "Show this message") do
|
||||||
|
puts o
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
end.parse!
|
||||||
|
|
||||||
@verbose = $DEBUG
|
|
||||||
@total_errors = 0
|
@total_errors = 0
|
||||||
|
|
||||||
def run_suite(suite)
|
def verbose
|
||||||
puts "Executing suite: #{suite['name']}"
|
@opts[:verbose]
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_suite(suite, outfile = nil)
|
||||||
errors = 0
|
errors = 0
|
||||||
suite_text = []
|
suite_text = []
|
||||||
outbuf = StringIO.new
|
outbuf = StringIO.new
|
||||||
errbuf = StringIO.new
|
errbuf = StringIO.new
|
||||||
suite['load'].each do |file|
|
suite['load'].each do |file|
|
||||||
suite_text += File.readlines("#{TEST_DIR}/#{file}")
|
suite_text += File.readlines("#{@opts[:test_dir]}/#{file}")
|
||||||
end
|
end
|
||||||
|
colons = {}
|
||||||
suite_text << "\nbye\n"
|
suite_text << "\nbye\n"
|
||||||
Open3.popen3('./gosxb-of816.sh') do |stdin, stdout, stderr, wait_thr|
|
Open3.popen3('./gosxb-of816.sh') do |stdin, stdout, stderr, wait_thr|
|
||||||
until [stdout, stderr].find {|f| !f.eof}.nil?
|
until [stdout, stderr].find {|f| !f.eof}.nil?
|
||||||
readable, writable, errored = IO.select([stdout,stderr],[stdin],[],0)
|
readable, writable, errored = IO.select([stdout,stderr],[stdin],[],0)
|
||||||
if writable.include?(stdin)
|
if writable.include?(stdin)
|
||||||
if line = suite_text.shift
|
if line = suite_text.shift
|
||||||
puts ">> #{line}" if @verbose
|
puts ">> #{line}" if verbose
|
||||||
stdin.write(line)
|
stdin.write(line)
|
||||||
else
|
else
|
||||||
puts "Lines complete."
|
puts "Lines complete."
|
||||||
@ -40,18 +86,18 @@ def run_suite(suite)
|
|||||||
rescue IO::EAGAINWaitReadable
|
rescue IO::EAGAINWaitReadable
|
||||||
# nothing
|
# nothing
|
||||||
end
|
end
|
||||||
puts outbuf.string unless @verbose
|
puts outbuf.string unless verbose
|
||||||
STDERR.puts "Emulator did not exit on its own."
|
STDERR.puts "Emulator did not exit on its own."
|
||||||
errors += 1
|
errors += 1
|
||||||
end
|
end
|
||||||
stdin.close
|
stdin.close
|
||||||
puts outbuf.string if @verbose
|
puts outbuf.string if verbose
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if readable.include?(stdout)
|
if readable.include?(stdout)
|
||||||
text = stdout.readline
|
text = stdout.readline
|
||||||
puts "<< #{text}" if @verbose
|
puts "<< #{text}" if verbose
|
||||||
outbuf.write(text)
|
outbuf.write(text)
|
||||||
end
|
end
|
||||||
if readable.include?(stderr)
|
if readable.include?(stderr)
|
||||||
@ -66,6 +112,7 @@ def run_suite(suite)
|
|||||||
end
|
end
|
||||||
break unless wait_thr.alive?
|
break unless wait_thr.alive?
|
||||||
end
|
end
|
||||||
|
outfile.write(outbuf.string) if outfile
|
||||||
prevline = ""
|
prevline = ""
|
||||||
outbuf.string.lines.each do |line|
|
outbuf.string.lines.each do |line|
|
||||||
case line
|
case line
|
||||||
@ -80,6 +127,19 @@ def run_suite(suite)
|
|||||||
when /TESTING/i
|
when /TESTING/i
|
||||||
puts line unless line.start_with?(':')
|
puts line unless line.start_with?(':')
|
||||||
end
|
end
|
||||||
|
if line =~ /\s*:\s+(\S+)/
|
||||||
|
colons[$1.downcase] = true
|
||||||
|
end
|
||||||
|
if line =~ /\s*[tT]\{\s+:\s+(\S+)/
|
||||||
|
colons[$1.downcase] = true
|
||||||
|
end
|
||||||
|
if line =~ /T\{(.+) \}T/
|
||||||
|
words = $1.split
|
||||||
|
words.each do |word|
|
||||||
|
next if word == '->'
|
||||||
|
@coverage[word.downcase] += 1 unless colons[word.downcase]
|
||||||
|
end
|
||||||
|
end
|
||||||
prevline = line
|
prevline = line
|
||||||
end
|
end
|
||||||
puts "Errors = #{errors}"
|
puts "Errors = #{errors}"
|
||||||
@ -88,15 +148,32 @@ def run_suite(suite)
|
|||||||
return errors
|
return errors
|
||||||
end
|
end
|
||||||
|
|
||||||
|
outfile = nil
|
||||||
|
begin
|
||||||
|
manifest = YAML.load(File.read("#{@opts[:test_dir]}/test-manifest.yaml"))
|
||||||
|
#puts manifest.inspect
|
||||||
|
|
||||||
manifest = YAML.load(File.read("#{TEST_DIR}/test-manifest.yaml"))
|
unless @opts[:verbose]
|
||||||
|
outfile = File.open(@opts[:output_file], 'w') if @opts[:output_file]
|
||||||
|
end
|
||||||
|
|
||||||
#puts manifest.inspect
|
manifest.each do |suite|
|
||||||
|
if File.fnmatch(@opts[:suites], suite['name'])
|
||||||
manifest.each do |suite|
|
print "Executing suite: " unless @opts[:list_only]
|
||||||
@total_errors += run_suite(suite)
|
puts suite['name']
|
||||||
|
@total_errors += run_suite(suite, outfile) unless @opts[:list_only]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue RuntimeError => e
|
||||||
|
STDERR.puts e.to_s
|
||||||
|
ensure
|
||||||
|
outfile.close if outfile
|
||||||
end
|
end
|
||||||
|
|
||||||
|
exit 0 if @opts[:list_only]
|
||||||
|
|
||||||
|
File.write(@opts[:cov_file], @coverage.to_yaml) if @opts[:cov_file]
|
||||||
|
|
||||||
if @total_errors > 0
|
if @total_errors > 0
|
||||||
STDERR.puts "Tests complete, total errors: #{@total_errors}"
|
STDERR.puts "Tests complete, total errors: #{@total_errors}"
|
||||||
exit 1
|
exit 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user