xref: /freebsd/contrib/ntp/sntp/unity/auto/colour_reporter.rb (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1# ==========================================
2#   Unity Project - A Test Framework for C
3#   Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
4#   [Released under MIT License. Please refer to license.txt for details]
5# ==========================================
6
7require "#{File.expand_path(File.dirname(__FILE__))}/colour_prompt"
8
9$colour_output = true
10
11def report(message)
12  if not $colour_output
13    $stdout.puts(message)
14  else
15    message = message.join('\n') if (message.class == Array)
16    message.each_line do |line|
17      line.chomp!
18      colour = case(line)
19        when /(?:total\s+)?tests:?\s+(\d+)\s+(?:total\s+)?failures:?\s+\d+\s+Ignored:?/i
20          ($1.to_i == 0) ? :green : :red
21        when /PASS/
22          :green
23        when /^OK$/
24          :green
25        when /(?:FAIL|ERROR)/
26          :red
27        when /IGNORE/
28          :yellow
29        when /^(?:Creating|Compiling|Linking)/
30          :white
31        else
32          :silver
33      end
34      colour_puts(colour, line)
35    end
36  end
37  $stdout.flush
38  $stderr.flush
39end