Skip to content

Commit

Permalink
Add better noop/neutral reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Jul 7, 2014
1 parent d5f5564 commit 7813f92
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/flay.yml
@@ -1,3 +1,3 @@
---
threshold: 18
total_score: 1053
total_score: 1040
1 change: 1 addition & 0 deletions lib/mutant.rb
Expand Up @@ -195,6 +195,7 @@ def inspect
require 'mutant/reporter/cli/report/env'
require 'mutant/reporter/cli/report/subject'
require 'mutant/reporter/cli/report/mutation'
require 'mutant/reporter/cli/report/test'
require 'mutant/reporter/cli/progress'
require 'mutant/reporter/cli/progress/env'
require 'mutant/reporter/cli/progress/config'
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/delegator.rb
Expand Up @@ -25,7 +25,7 @@ def delegate(*names)
# @api private
#
def define_delegator(name)
fail if instance_methods.include?(name)
fail "method #{name} already defined" if instance_methods.include?(name)
define_method(name) do
object.public_send(name)
end
Expand Down
25 changes: 15 additions & 10 deletions lib/mutant/reporter/cli/report/mutation.rb
Expand Up @@ -8,7 +8,7 @@ class Mutation < self

handle Mutant::Result::Mutation

delegate :mutation
delegate :mutation, :failed_test_results

DIFF_ERROR_MESSAGE = 'BUG: Mutation NOT resulted in exactly one diff. Please report a reproduction!'.freeze

Expand All @@ -26,13 +26,15 @@ class Mutation < self
"%s\n" \
"Unparsed Source:\n" \
"%s\n" \
"-----------------------\n".freeze
"Test Reports: %d\n"

NOOP_MESSAGE =
"--- Noop failure ---\n" \
"---- Noop failure -----\n" \
"No code was inserted. And the test did NOT PASS.\n" \
"This is typically a problem of your specs not passing unmutated.\n" \
"--------------------\n".freeze
"Test Reports: %d\n"

FOOTER = '-----------------------'.freeze

# Run report printer
#
Expand All @@ -42,19 +44,20 @@ class Mutation < self
#
def run
puts(mutation.identification)
puts(details)
print_details
puts(FOOTER)
self
end

private

# Return details
#
# @return [String]
# @return [undefined]
#
# @api private
#
def details
def print_details
send(MAP.fetch(mutation.class))
end

Expand All @@ -68,7 +71,7 @@ def evil_details
original, current = mutation.original_source, mutation.source
diff = Mutant::Diff.build(original, current)
diff = color? ? diff.colorized_diff : diff.diff
diff || DIFF_ERROR_MESSAGE
info(diff || DIFF_ERROR_MESSAGE)
end

# Noop details
Expand All @@ -78,7 +81,8 @@ def evil_details
# @api private
#
def noop_details
NOOP_MESSAGE
info(NOOP_MESSAGE, failed_test_results.length)
visit_collection(failed_test_results)
end

# Neutral details
Expand All @@ -88,7 +92,8 @@ def noop_details
# @api private
#
def neutral_details
format(NEUTRAL_MESSAGE, mutation.subject.node.inspect, mutation.source)
info(NEUTRAL_MESSAGE, mutation.subject.node.inspect, mutation.source, failed_test_results.length)
visit_collection(failed_test_results)
end

end # Mutation
Expand Down
28 changes: 28 additions & 0 deletions lib/mutant/reporter/cli/report/test.rb
@@ -0,0 +1,28 @@
module Mutant
class Reporter
class CLI
class Report
# Test result reporter
class Test < self

handle(Mutant::Result::Test)

delegate :test, :runtime

# Run test result reporter
#
# @return [self]
#
# @api private
#
def run
status('- %s / runtime: %s', test.identification, object.runtime)
puts('Test Output:')
puts(object.output)
end

end
end # Report
end # CLI
end # Reporter
end # Mutant
10 changes: 10 additions & 0 deletions lib/mutant/result.rb
Expand Up @@ -284,6 +284,16 @@ def success?
test_results.any?(&:success?)
end

# Return failed test results
#
# @return [Array]
#
# @api private
#
def failed_test_results
test_results.select(&:fail?)
end

sum :killtime, :test_results

end # Mutation
Expand Down
31 changes: 28 additions & 3 deletions spec/unit/mutant/reporter/cli_spec.rb
Expand Up @@ -70,6 +70,19 @@ def contents
)
end

let(:test_results) do
[
double(
'Test Result',
class: Mutant::Result::Test,
test: _subject.tests.first,
runtime: 1.0,
output: 'test-output',
success?: mutation_result_success
)
]
end

let(:subject_results) do
[
Mutant::Result::Subject.new(
Expand All @@ -81,7 +94,9 @@ def contents
class: Mutant::Result::Mutation,
mutation: mutation,
killtime: 0.5,
success?: mutation_result_success
success?: mutation_result_success,
test_results: test_results,
failed_test_results: mutation_result_success ? [] : test_results
)
]
)
Expand Down Expand Up @@ -192,6 +207,7 @@ def contents
@@ -1,2 +1,2 @@
-true
+false
-----------------------
Subjects: 1
Mutations: 1
Kills: 0
Expand All @@ -215,6 +231,7 @@ def contents
- test_id
mutation_id
BUG: Mutation NOT resulted in exactly one diff. Please report a reproduction!
-----------------------
Subjects: 1
Mutations: 1
Kills: 0
Expand Down Expand Up @@ -246,6 +263,10 @@ def contents
(true)
Unparsed Source:
true
Test Reports: 1
- test_id / runtime: 1.0
Test Output:
test-output
-----------------------
Subjects: 1
Mutations: 1
Expand All @@ -269,10 +290,14 @@ def contents
subject_id
- test_id
mutation_id
--- Noop failure ---
---- Noop failure -----
No code was inserted. And the test did NOT PASS.
This is typically a problem of your specs not passing unmutated.
--------------------
Test Reports: 1
- test_id / runtime: 1.0
Test Output:
test-output
-----------------------
Subjects: 1
Mutations: 1
Kills: 0
Expand Down

0 comments on commit 7813f92

Please sign in to comment.