Skip to content

Commit

Permalink
Rename functions to prevent signature collision, add deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhammerlund committed Oct 20, 2017
1 parent 0e105a3 commit 6985e27
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 98 deletions.
48 changes: 43 additions & 5 deletions lib/xcpretty/formatters/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ def format_device_tests_passed(device) EMPTY; end
def format_generate_dsym(dsym); EMPTY; end
def format_linking(file, build_variant, arch); EMPTY; end
def format_libtool(library); EMPTY; end
def format_passing_test(suite, test, device, time); EMPTY; end
def format_pending_test(suite, test, device); EMPTY; end
def format_passing_device_test(suite, test, time, device); EMPTY; end
def format_pending_device_test(suite, test, device); EMPTY; end
def format_measuring_test(suite, test, time); EMPTY; end
def format_failing_test(suite, test, device, reason, file_path); EMPTY; end
def format_failing_device_test(suite, test, reason,
file_path, device); EMPTY; end
def format_process_pch(file); EMPTY; end
def format_process_pch_command(file_path); EMPTY; end
def format_phase_success(phase_name); EMPTY; end
Expand All @@ -43,9 +44,9 @@ def format_codesign(file); EMPTY; end
def format_preprocess(file); EMPTY; end
def format_pbxcp(file); EMPTY; end
def format_shell_command(command, arguments); EMPTY; end
def format_test_run_started(name, device); EMPTY; end
def format_device_test_run_started(name, device); EMPTY; end
def format_test_run_finished(name, time); EMPTY; end
def format_test_suite_started(name, device); EMPTY; end
def format_device_test_suite_started(name, device); EMPTY; end
def format_test_summary(message, failures_per_suite); EMPTY; end
def format_touch(file_path, file_name); EMPTY; end
def format_tiffutil(file); EMPTY; end
Expand All @@ -66,12 +67,20 @@ def format_warning(message); message; end
# the same for warnings
def format_compile_warning(file_name, file_path, reason,
line, cursor); EMPTY; end

# DEPRECATED
def format_passing_test(suite, test, time); EMPTY; end
def format_pending_test(suite, test); EMPTY; end
def format_failing_test(suite, test, reason, file_path); EMPTY; end
def format_test_run_started(name); EMPTY; end
def format_test_suite_started(name); EMPTY; end
end

class Formatter

include ANSI
include FormatMethods
extend Gem::Deprecate

attr_reader :parser

Expand Down Expand Up @@ -154,6 +163,35 @@ def format_will_not_be_code_signed(message)
"#{yellow(warning_symbol + " " + message)}"
end

# Backwards Compatibility / Deprecated Methods

def format_passing_device_test(suite, test, time, device)
format_passing_test(suite, test, time)
end

def format_pending_device_test(suite, test, device)
format_pending_test(suite, test)
end

def format_failing_device_test(suite, test, reason, file_path, device)
format_failing_test(suite, test, reason, file_path)
end

def format_device_test_run_started(name, device)
format_test_run_started(name)
end

def format_device_test_suite_started(name, device)
format_test_suite_started(name)
end

deprecate :format_passing_test, :format_passing_device_test, 2017, 10
deprecate :format_pending_test, :format_pending_device_test, 2017, 10
deprecate :format_failing_test, :format_failing_device_test, 2017, 10
deprecate :format_test_run_started,
:format_device_test_run_started, 2017, 10
deprecate :format_test_suite_started,
:format_device_test_suite_started, 2017, 10

private

Expand Down
4 changes: 2 additions & 2 deletions lib/xcpretty/formatters/knock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class Knock < Formatter
FAIL = 'not ok'
PASS = 'ok'

def format_passing_test(suite, test_case, device, time)
def format_passing_device_test(suite, test_case, time, device)
"#{PASS} - #{format_test_description(test_case, device)}"
end

def format_failing_test(test_suite, test_case, device, reason, file)
def format_failing_device_test(test_suite, test_case, reason, file, device)
knock_result =
"#{FAIL} - #{format_test_description(test_case, device)}: FAILED"
if reason.to_s.empty? || file.to_s.empty?
Expand Down
6 changes: 3 additions & 3 deletions lib/xcpretty/formatters/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ def optional_newline
''
end

def format_passing_test(suite, test_case, device, time)
def format_passing_device_test(suite, test_case, time, device)
green(PASS)
end

def format_failing_test(test_suite, test_case, device, reason, file)
def format_failing_device_test(test_suite, test_case, reason, file, device)
red(FAIL)
end

def format_pending_test(suite, test_case, device)
def format_pending_device_test(suite, test_case, device)
yellow(PENDING)
end

Expand Down
10 changes: 5 additions & 5 deletions lib/xcpretty/formatters/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def format_linking(target, build_variants, arch)
format("Linking", target)
end

def format_failing_test(suite, test_case, device, reason, file)
def format_failing_device_test(suite, test_case, reason, file, device)
test_description = test_case
unless device.to_s.empty?
test_description = "#{test_description} (#{colored_device(device)})"
Expand All @@ -98,7 +98,7 @@ def format_failing_test(suite, test_case, device, reason, file)
INDENT + format_test(test_description, :fail)
end

def format_passing_test(suite, test_case, device, time)
def format_passing_device_test(suite, test_case, time, device)
time = colored_time(time)
if device.to_s.empty?
INDENT +
Expand All @@ -110,7 +110,7 @@ def format_passing_test(suite, test_case, device, time)
end
end

def format_pending_test(suite, test_case, device)
def format_pending_device_test(suite, test_case, device)
if device.to_s.empty?
INDENT + format_test("#{test_case} [PENDING]", :pending)
else
Expand Down Expand Up @@ -153,7 +153,7 @@ def format_pbxcp(file)
format("Copying", file)
end

def format_test_run_started(name, device)
def format_device_test_run_started(name, device)
if device.to_s.empty?
heading("Test Suite", name, "started")
else
Expand All @@ -164,7 +164,7 @@ def format_test_run_started(name, device)
end
end

def format_test_suite_started(name, device)
def format_device_test_suite_started(name, device)
if device.to_s.empty?
heading("", name, "")
else
Expand Down
6 changes: 3 additions & 3 deletions lib/xcpretty/formatters/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ def initialize(unicode, color)
@counter = 0
end

def format_passing_test(suite, test_case, device, time)
def format_passing_device_test(suite, test_case, time, device)
increment_counter
"#{PASS} #{counter} - #{format_test_description(test_case, device)}"
end

def format_failing_test(test_suite, test_case, device, reason, file)
def format_failing_device_test(test_suite, test_case, reason, file, device)
increment_counter
test_description = format_test_description(test_case, device)
tap_result = "#{FAIL} #{counter} - #{test_description}"
Expand All @@ -25,7 +25,7 @@ def format_failing_test(test_suite, test_case, device, reason, file)
format_failure_diagnostics(test_suite, test_case, reason, file)
end

def format_pending_test(test_suite, test_case, device)
def format_pending_device_test(test_suite, test_case, device)
increment_counter
test_description = format_test_description(test_case, device)
"#{FAIL} #{counter} - #{test_description} # TODO Not written yet"
Expand Down
14 changes: 7 additions & 7 deletions lib/xcpretty/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,11 @@ def parse(text)
when EXECUTED_MATCHER
format_summary_if_needed(text)
when UI_FAILING_TEST_MATCHER
formatter.format_failing_test(@test_suite, @test_case, nil, $2, $1)
formatter.format_failing_device_test(@test_suite, @test_case, $2, $1, nil)
when PARALLEL_FAILING_TEST_MATCHER
formatter.format_failing_test($1, $2, $3, nil, nil)
formatter.format_failing_device_test($1, $2, nil, nil, $3)
when FAILING_TEST_MATCHER
formatter.format_failing_test($2, $3, nil, $4, $1)
formatter.format_failing_device_test($2, $3, $4, $1, nil)
when FATAL_ERROR_MATCHER
formatter.format_error($1)
when FILE_MISSING_ERROR_MATCHER
Expand All @@ -402,9 +402,9 @@ def parse(text)
when TEST_CASE_MEASURED_MATCHER
formatter.format_measuring_test($1, $2, $3)
when TEST_CASE_PENDING_MATCHER
formatter.format_pending_test($1, $2, $3)
formatter.format_pending_device_test($1, $2, $3)
when TEST_CASE_PASSED_MATCHER
formatter.format_passing_test($1, $2, $3, $4)
formatter.format_passing_device_test($1, $2, $4, $3)
when PODS_ERROR_MATCHER
formatter.format_error($1)
when PROCESS_INFO_PLIST_MATCHER
Expand All @@ -424,9 +424,9 @@ def parse(text)
when TESTS_RUN_COMPLETION_MATCHER
formatter.format_test_run_finished($1, $3)
when TEST_SUITE_STARTED_MATCHER
formatter.format_test_run_started($1, $3)
formatter.format_device_test_run_started($1, $3)
when TEST_SUITE_START_MATCHER
formatter.format_test_suite_started($1, $2)
formatter.format_device_test_suite_started($1, $2)
when TIFFUTIL_MATCHER
formatter.format_tiffutil($1)
when TOUCH_MATCHER
Expand Down
4 changes: 2 additions & 2 deletions lib/xcpretty/reporters/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def handle(line)
@parser.parse(line)
end

def format_failing_test(suite, test_case, device, reason, file)
def format_failing_device_test(suite, test_case, reason, file, device)
add_test(suite, name: test_case, failing: true,
reason: reason, file: file, device: device,
snippet: formatted_snippet(file),
screenshots: [])
end

def format_passing_test(suite, test_case, device, time)
def format_passing_device_test(suite, test_case, time, device)
add_test(suite, name: test_case, device: device,
time: time, screenshots: [])
end
Expand Down
8 changes: 4 additions & 4 deletions lib/xcpretty/reporters/junit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ def handle(line)
@parser.parse(line)
end

def format_test_run_started(name, device)
def format_device_test_run_started(name, device)
@document.root.add_attribute('name', name)
end

def format_passing_test(classname, test_case, device, time)
def format_passing_device_test(classname, test_case, time, device)
test_node = suite(classname).add_element('testcase')
test_node.attributes['classname'] = classname
test_node.attributes['name'] = format_name(test_case, device)
test_node.attributes['time'] = time
@test_count += 1
end

def format_pending_test(classname, test_case, device)
def format_pending_device_test(classname, test_case, device)
test_node = suite(classname).add_element('testcase')
test_node.attributes['classname'] = classname
test_node.attributes['name'] = format_name(test_case, device)
test_node.add_element('skipped')
@test_count += 1
end

def format_failing_test(classname, test_case, device, reason, file)
def format_failing_device_test(classname, test_case, reason, file, device)
test_node = suite(classname).add_element('testcase')
test_node.attributes['classname'] = classname
test_node.attributes['name'] = format_name(test_case, device)
Expand Down
6 changes: 3 additions & 3 deletions lib/xcpretty/reporters/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def finish
write_report
end

def format_failing_test(suite, test_case, device, reason, file)
def format_failing_device_test(suite, test_case, reason, file, device)
@test_count += 1
@fail_count += 1
test_description = test_case
Expand All @@ -47,7 +47,7 @@ def format_failing_test(suite, test_case, device, reason, file)
end
end

def format_passing_test(suite, test_case, device, time)
def format_passing_device_test(suite, test_case, time, device)
@test_count += 1
test_description = test_case
unless device.to_s.empty?
Expand All @@ -56,7 +56,7 @@ def format_passing_test(suite, test_case, device, time)
@tests.push("#{test_description} PASSED")
end

def format_pending_test(classname, test_case, device)
def format_pending_device_test(classname, test_case, device)
@test_count += 1
test_description = test_case
unless device.to_s.empty?
Expand Down
6 changes: 3 additions & 3 deletions spec/fixtures/custom_reporter.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# encoding: utf-8
class DogeReporter < XCPretty::Reporter

def format_failing_test(suite, test_case, device, reason, file)
def format_failing_device_test(suite, test_case, reason, file, device)
@test_count += 1
@fail_count += 1
@tests.push("WOW such FAIL. Many #{test_case}. Much #{reason}. Very #{file}.")
end

def format_passing_test(suite, test_case, device, time)
def format_passing_device_test(suite, test_case, time, device)
@test_count += 1
@tests.push("WOW such PASS. Many #{test_case}. Much green. Very success.")
end

def format_pending_test(classname, test_case, device)
def format_pending_device_test(classname, test_case, device)
@test_count += 1
@tests.push("WOW such PENDING. Many #{test_case}. Much stop. Very wait.")
end
Expand Down
16 changes: 8 additions & 8 deletions spec/xcpretty/formatters/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ module XCPretty
context "without colors" do

it "prints dots for passing tests" do
@formatter.format_passing_test("sweez testz", "sample spec", "iPhone X", "0.002").should == "."
@formatter.format_passing_device_test("sweez testz", "sample spec", "0.002", "iPhone X").should == "."
end

it "prints P for pending tests" do
@formatter.format_pending_test("sweez testz", "iPhone X", "sample spec").should == "P"
@formatter.format_pending_device_test("sweez testz", "sample spec", "iPhone X").should == "P"
end

it "prints F for failing tests" do
@formatter.format_failing_test(
"///file", "NSNumber Specs", "adding numbers", nil, "should add 2 numbers"
@formatter.format_failing_device_test(
"///file", "NSNumber Specs", "adding numbers", "should add 2 numbers", nil
).should == "F"
end
end
Expand All @@ -36,18 +36,18 @@ module XCPretty
before { @formatter.colorize = true }

it "prints green for passing tests" do
@formatter.format_passing_test("sweez testz", "sample spec", "iPhone X", "0.002"
@formatter.format_passing_device_test("sweez testz", "sample spec", "0.002", "iPhone X"
).should be_colored :green
end

it "prints yellow for pending tests" do
@formatter.format_pending_test("sweez testz", "iPhone X", "sample spec"
@formatter.format_pending_device_test("sweez testz", "sample spec", "iPhone X"
).should be_colored :yellow
end

it "prints red for failing tests" do
@formatter.format_failing_test(
"///file", "NSNumber Specs", "adding numbers", nil, "should add 2 numbers"
@formatter.format_failing_device_test(
"///file", "NSNumber Specs", "adding numbers", "should add 2 numbers", nil
).should be_colored :red
end
end
Expand Down
Loading

0 comments on commit 6985e27

Please sign in to comment.