mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-10-29 19:53:33 +00:00
- standardized output format for test results
- added color coding to output git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@58 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
if RUBY_PLATFORM =~/(win|w)32$/
|
||||
begin
|
||||
require 'Win32API'
|
||||
rescue LoadError
|
||||
puts "ERROR! \"Win32API\" library not found"
|
||||
puts "\"Win32API\" is required for colour on a windows machine"
|
||||
puts " try => \"gem install Win32API\" on the command line"
|
||||
puts
|
||||
end
|
||||
# puts
|
||||
# puts 'Windows Environment Detected...'
|
||||
# puts 'Win32API Library Found.'
|
||||
# puts
|
||||
end
|
||||
|
||||
class ColourCommandLine
|
||||
def initialize
|
||||
if RUBY_PLATFORM =~/(win|w)32$/
|
||||
get_std_handle = Win32API.new("kernel32", "GetStdHandle", ['L'], 'L')
|
||||
@set_console_txt_attrb =
|
||||
Win32API.new("kernel32","SetConsoleTextAttribute",['L','N'], 'I')
|
||||
@hout = get_std_handle.call(-11)
|
||||
end
|
||||
end
|
||||
|
||||
def change_to(new_colour)
|
||||
if RUBY_PLATFORM =~/(win|w)32$/
|
||||
@set_console_txt_attrb.call(@hout,self.win32_colour(new_colour))
|
||||
else
|
||||
"\033[30;#{posix_colour(new_colour)};22m"
|
||||
end
|
||||
end
|
||||
|
||||
def win32_colour(colour)
|
||||
case colour
|
||||
when :black then 0
|
||||
when :dark_blue then 1
|
||||
when :dark_green then 2
|
||||
when :dark_cyan then 3
|
||||
when :dark_red then 4
|
||||
when :dark_purple then 5
|
||||
when :dark_yellow, :narrative then 6
|
||||
when :default_white, :default, :dark_white then 7
|
||||
when :silver then 8
|
||||
when :blue then 9
|
||||
when :green, :success then 10
|
||||
when :cyan, :output then 11
|
||||
when :red, :failure then 12
|
||||
when :purple then 13
|
||||
when :yellow then 14
|
||||
when :white then 15
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
def posix_colour(colour)
|
||||
case colour
|
||||
when :black then 30
|
||||
when :red, :failure then 31
|
||||
when :green, :success then 32
|
||||
when :yellow then 33
|
||||
when :blue, :narrative then 34
|
||||
when :purple, :magenta then 35
|
||||
when :cyan, :output then 36
|
||||
when :white, :default_white, :default then 37
|
||||
else
|
||||
30
|
||||
end
|
||||
end
|
||||
|
||||
def out_c(mode, colour, str)
|
||||
case RUBY_PLATFORM
|
||||
when /(win|w)32$/
|
||||
change_to(colour)
|
||||
$stdout.puts str if mode == :puts
|
||||
$stdout.print str if mode == :print
|
||||
change_to(:default_white)
|
||||
else
|
||||
$stdout.puts("#{change_to(colour)}#{str}\033[0m") if mode == :puts
|
||||
$stdout.print("#{change_to(colour)}#{str}\033[0m") if mode == :print
|
||||
end
|
||||
end
|
||||
end # ColourCommandLine
|
||||
|
||||
def colour_puts(role,str) ColourCommandLine.new.out_c(:puts, role, str) end
|
||||
def colour_print(role,str) ColourCommandLine.new.out_c(:print, role, str) end
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
File.expand_path(File.join(File.dirname(__FILE__),'colour_prompt'))
|
||||
|
||||
class UnityTestRunnerGenerator
|
||||
|
||||
@@ -17,10 +18,10 @@ class UnityTestRunnerGenerator
|
||||
require 'yaml'
|
||||
yaml_guts = YAML.load_file(config_file)
|
||||
yaml_goodness = yaml_guts[:unity] ? yaml_guts[:unity] : yaml_guts[:cmock]
|
||||
options[:cexception] = 1 if (yaml_goodness[:plugins].include? :cexception)
|
||||
options[:coverage ] = 1 if (yaml_goodness[:coverage])
|
||||
options[:order] = 1 if (yaml_goodness[:enforce_strict_ordering])
|
||||
options[:includes] << (yaml_goodness[:includes])
|
||||
options[:cexception] = 1 unless (yaml_goodness[:plugins] & ['cexception', :cexception]).empty?
|
||||
options[:coverage ] = 1 if (yaml_goodness[:coverage])
|
||||
options[:order] = 1 if (yaml_goodness[:enforce_strict_ordering])
|
||||
options[:includes] << (yaml_goodness[:includes])
|
||||
end
|
||||
return(options)
|
||||
end
|
||||
@@ -59,19 +60,35 @@ class UnityTestRunnerGenerator
|
||||
end
|
||||
|
||||
def find_tests(input_file)
|
||||
tests_raw = []
|
||||
tests_and_line_numbers = []
|
||||
|
||||
input_file.rewind
|
||||
tests = []
|
||||
source = input_file.read()
|
||||
source = source.gsub(/\/\/.*$/, '') #remove line comments
|
||||
source = source.gsub(/\/\*.*?\*\//m, '') #remove block comments
|
||||
lines = source.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
|
||||
source_raw = input_file.read
|
||||
source_scrubbed = source_raw.gsub(/\/\/.*$/, '') #remove line comments
|
||||
source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') #remove block comments
|
||||
lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
|
||||
| (;|\{|\}) /x) # Match ;, {, and } as end of lines
|
||||
lines.each do |line|
|
||||
|
||||
lines.each_with_index do |line, index|
|
||||
if line =~ /^\s*void\s+test(.*?)\s*\(\s*void\s*\)/
|
||||
tests << "test" + $1
|
||||
tests_raw << ("test" + $1)
|
||||
end
|
||||
end
|
||||
return tests
|
||||
|
||||
source_lines = source_raw.split("\n")
|
||||
source_index = 0;
|
||||
|
||||
tests_raw.each do |test|
|
||||
source_lines[source_index..-1].each_with_index do |line, index|
|
||||
if (line =~ /#{test}/)
|
||||
source_index += index
|
||||
tests_and_line_numbers << {:name => test, :line_number => (source_index+1)}
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
return tests_and_line_numbers
|
||||
end
|
||||
|
||||
def find_includes(input_file)
|
||||
@@ -122,7 +139,7 @@ class UnityTestRunnerGenerator
|
||||
output.puts("extern void tearDown(void);")
|
||||
output.puts('')
|
||||
tests.each do |test|
|
||||
output.puts("extern void #{test}(void);")
|
||||
output.puts("extern void #{test[:name]}(void);")
|
||||
end
|
||||
output.puts('')
|
||||
end
|
||||
@@ -202,7 +219,7 @@ class UnityTestRunnerGenerator
|
||||
|
||||
output.puts(" // RUN_TEST calls runTest")
|
||||
tests.each do |test|
|
||||
output.puts(" RUN_TEST(#{test});")
|
||||
output.puts(" RUN_TEST(#{test[:name]}, #{test[:line_number]});")
|
||||
end
|
||||
|
||||
output.puts()
|
||||
|
||||
Reference in New Issue
Block a user