Class: XCPretty::Formatter

Inherits:
Object
  • Object
show all
Includes:
ANSI, FormatMethods
Defined in:
lib/xcpretty/formatters/formatter.rb

Direct Known Subclasses

Knock, RSpec, Simple

Constant Summary collapse

ERROR =
""
ASCII_ERROR =
"[!]"

Constants included from FormatMethods

XCPretty::FormatMethods::EMPTY

Constants included from ANSI

ANSI::COLORS, ANSI::EFFECT, ANSI::FORMATTED_MATCHER

Instance Attribute Summary collapse

Attributes included from ANSI

#colorize

Instance Method Summary collapse

Methods included from FormatMethods

#format_analyze, #format_build_target, #format_check_dependencies, #format_clean, #format_clean_remove, #format_clean_target, #format_codesign, #format_compile, #format_compile_command, #format_compile_xib, #format_copy_strings_file, #format_cpresource, #format_failing_test, #format_generate_dsym, #format_libtool, #format_linking, #format_passing_test, #format_pbxcp, #format_pending_test, #format_phase_script_execution, #format_preprocess, #format_process_info_plist, #format_process_pch, #format_test_run_finished, #format_test_run_started, #format_test_suite_started, #format_tiffutil, #format_touch

Methods included from ANSI

#ansi_parse, #applied_effects, #colorize?, #cyan, #green, #red, #strip, #white, #yellow

Constructor Details

#initialize(use_unicode, colorize) ⇒ Formatter

Returns a new instance of Formatter.



57
58
59
60
61
# File 'lib/xcpretty/formatters/formatter.rb', line 57

def initialize(use_unicode, colorize)
  @use_unicode = use_unicode
  @colorize = colorize
  @parser = Parser.new(self)
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



55
56
57
# File 'lib/xcpretty/formatters/formatter.rb', line 55

def parser
  @parser
end

Instance Method Details

#format_compile_error(file, file_path, reason, line, cursor) ⇒ Object



93
94
95
96
# File 'lib/xcpretty/formatters/formatter.rb', line 93

def format_compile_error(file, file_path, reason, line, cursor)
  "\n#{red(error_symbol + " ")}#{file_path}: #{red(reason)}\n\n" +
  "#{line}\n#{cyan(cursor)}\n\n"
end

#format_duplicate_symbols(message, file_paths) ⇒ Object



104
105
106
107
# File 'lib/xcpretty/formatters/formatter.rb', line 104

def format_duplicate_symbols(message, file_paths)
  "\n#{red(error_symbol + " " + message)}\n" +
  "> #{file_paths.map { |path| path.split('/').last }.join("\n> ")}\n"
end

#format_error(message) ⇒ Object



89
90
91
# File 'lib/xcpretty/formatters/formatter.rb', line 89

def format_error(message)
  "\n#{red(error_symbol + " " + message)}\n\n"
end

#format_test_summary(executed_message, failures_per_suite) ⇒ Object

Will be printed by default. Override with ” if you don’t want summary



78
79
80
81
82
83
84
# File 'lib/xcpretty/formatters/formatter.rb', line 78

def format_test_summary(executed_message, failures_per_suite)
  failures = format_failures(failures_per_suite)
  final_message = failures.empty? ? green(executed_message) : red(executed_message)

  text = [failures, final_message].join("\n\n\n").strip
  "\n\n#{text}"
end

#format_undefined_symbols(message, symbol, reference) ⇒ Object



98
99
100
101
102
# File 'lib/xcpretty/formatters/formatter.rb', line 98

def format_undefined_symbols(message, symbol, reference)
  "\n#{red(error_symbol + " " + message)}\n" +
  "> Symbol: #{symbol}\n" +
  "> Referenced from: #{reference}\n\n"
end

#optional_newlineObject

If you want to print inline, override #optional_newline with ”



69
70
71
# File 'lib/xcpretty/formatters/formatter.rb', line 69

def optional_newline
  "\n"
end

#pretty_format(text) ⇒ Object

Override if you want to catch something specific with your regex



64
65
66
# File 'lib/xcpretty/formatters/formatter.rb', line 64

def pretty_format(text)
  parser.parse(text)
end

#use_unicode?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/xcpretty/formatters/formatter.rb', line 73

def use_unicode?
  !!@use_unicode
end