mutant 0.10.32 → 0.10.33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b12eb31fc385dfce5e13bfb8341ac87efea9f8cb6e26531c584477e8eda2a73
4
- data.tar.gz: 576c9eb28548bec20da7818589f110c56f4ffb230af11914bca2bed27c0f8b1a
3
+ metadata.gz: 2c20fb3fdc41f7d6e0f8164916206353716c037ec596fccccd06db10c05e810c
4
+ data.tar.gz: 276612decdc11bf06de38e704fed0d6dc3b9b0b590d9e2f333be7ae383396ca0
5
5
  SHA512:
6
- metadata.gz: 0c8a3ae71a2e8f1d82a11a0793c89e47a61cc5169025e0081801bf3211aadf5aadb84c23ea220077ae10746fb35ae6095f3d64969ba751ec1d766575cacc78ae
7
- data.tar.gz: 118ee4f62eea31fe0ae3a616e6abf9ede75b03b7095af0bc9e75082c55ad199c9bb143677007411b3409bbfec47d37db73c7ec0716424b8dbc86b64eac2b005a
6
+ metadata.gz: 652ac4959565f27514568c25c43a0ab64d3af74f9f9de50712bf6e6e825dcf44d27e55e40ff76f0e7c91e27c4199c4f67a0d2205f2268eefae5acc338e2aecb5
7
+ data.tar.gz: a7e9b023ffefb0d3da5a13d7ec83fbb6696a10efe0f8840b867e8f6e788a55e7d2eabd077173957a697e9f0689ce109fec5d8668078946e317f7c9c4b7216614
@@ -10,7 +10,7 @@ module Mutant
10
10
  class Root < self
11
11
  NAME = 'mutant'
12
12
  SHORT_DESCRIPTION = 'mutation testing engine main command'
13
- SUBCOMMANDS = [Environment::Run, Environment, Subscription].freeze
13
+ SUBCOMMANDS = [Environment::Run, Environment, Subscription, Util].freeze
14
14
  end # Root
15
15
  end # Command
16
16
  end # CLI
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutant
4
+ module CLI
5
+ class Command
6
+ class Util < self
7
+ NAME = 'util'
8
+ SHORT_DESCRIPTION = 'Utility subcommands'
9
+
10
+ class Mutation < self
11
+ NAME = 'mutation'
12
+ SHORT_DESCRIPTION = 'Print mutations of a code snippet'
13
+ SUBCOMMANDS = [].freeze
14
+ OPTIONS = %i[add_target_options].freeze
15
+
16
+ def action
17
+ @targets.each(&method(:print_mutations))
18
+ Either::Right.new(nil)
19
+ end
20
+
21
+ private
22
+
23
+ class Target
24
+ include Adamantium
25
+
26
+ def node
27
+ Unparser.parse(source)
28
+ end
29
+ memoize :node
30
+
31
+ class File < self
32
+ include Concord.new(:pathname, :source)
33
+
34
+ public :source
35
+
36
+ def identification
37
+ "file:#{pathname}"
38
+ end
39
+ end # File
40
+
41
+ class Source < self
42
+ include Concord::Public.new(:source)
43
+
44
+ def identification
45
+ '<cli-source>'
46
+ end
47
+ end # source
48
+ end # Target
49
+
50
+ def initialize(_arguments)
51
+ super
52
+
53
+ @targets = []
54
+ end
55
+
56
+ def add_target_options(parser)
57
+ parser.on('-e', '--evaluate SOURCE') do |source|
58
+ @targets << Target::Source.new(source)
59
+ end
60
+ end
61
+
62
+ def print_mutations(target)
63
+ world.stdout.puts(target.identification)
64
+ Mutator.mutate(target.node).each do |mutation|
65
+ Reporter::CLI::Printer::Mutation.call(
66
+ world.stdout,
67
+ Mutant::Mutation::Evil.new(target, mutation)
68
+ )
69
+ end
70
+ end
71
+
72
+ def parse_remaining_arguments(arguments)
73
+ @targets.concat(
74
+ arguments.map do |argument|
75
+ parse_pathname(argument)
76
+ .bind(&method(:read_file))
77
+ .from_right { |error| return Either::Left.new(error) }
78
+ end
79
+ )
80
+
81
+ Either::Right.new(self)
82
+ end
83
+
84
+ def read_file(pathname)
85
+ Either::Right.new(Target::File.new(pathname, pathname.read))
86
+ rescue StandardError => exception
87
+ Either::Left.new("Cannot read file: #{exception}")
88
+ end
89
+
90
+ def parse_pathname(input)
91
+ Either.wrap_error(ArgumentError) { Pathname.new(input) }
92
+ .lmap(&:message)
93
+ end
94
+ end # Mutation
95
+
96
+ SUBCOMMANDS = [Mutation].freeze
97
+ end # Util
98
+ end # Command
99
+ end # CLI
100
+ end # Mutant
@@ -69,6 +69,8 @@ module Mutant
69
69
  false
70
70
  end
71
71
 
72
+ abstract_method :action
73
+
72
74
  private
73
75
 
74
76
  def subcommands
@@ -72,6 +72,15 @@ module Mutant
72
72
  )
73
73
  end
74
74
 
75
+ # Rendered mutation diff
76
+ #
77
+ # @return [String, nil]
78
+ # the diff, if present
79
+ def diff
80
+ Unparser::Diff.build(original_source, source)
81
+ end
82
+ memoize :diff
83
+
75
84
  private
76
85
 
77
86
  def sha1
@@ -80,7 +89,6 @@ module Mutant
80
89
 
81
90
  # Evil mutation that should case mutations to fail tests
82
91
  class Evil < self
83
-
84
92
  SYMBOL = 'evil'
85
93
  TEST_PASS_SUCCESS = false
86
94
 
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutant
4
+ class Reporter
5
+ class CLI
6
+ class Printer
7
+ # Reporter for mutations
8
+ class Mutation < self
9
+ NO_DIFF_MESSAGE = <<~'MESSAGE'
10
+ --- Internal failure ---
11
+ BUG: A generted mutation did not result in exactly one diff hunk!
12
+ This is an invariant violation by the mutation generation engine.
13
+ Please report a reproduction to https://github.com/mbj/mutant
14
+ Original unparsed source:
15
+ %s
16
+ Original AST:
17
+ %s
18
+ Mutated unparsed source:
19
+ %s
20
+ Mutated AST:
21
+ %s
22
+ MESSAGE
23
+
24
+ SEPARATOR = '-----------------------'
25
+
26
+ # Run report printer
27
+ #
28
+ # @return [undefined]
29
+ def run
30
+ diff = object.diff
31
+ diff = color? ? diff.colorized_diff : diff.diff
32
+
33
+ if diff
34
+ output.write(diff)
35
+ else
36
+ print_no_diff_message
37
+ end
38
+ end
39
+
40
+ def print_no_diff_message
41
+ info(
42
+ NO_DIFF_MESSAGE,
43
+ object.original_source,
44
+ original_node.inspect,
45
+ object.source,
46
+ object.node.inspect
47
+ )
48
+ end
49
+
50
+ def original_node
51
+ object.subject.node
52
+ end
53
+
54
+ end # MutationResult
55
+ end # Printer
56
+ end # CLI
57
+ end # Reporter
58
+ end # Mutant
@@ -66,23 +66,7 @@ module Mutant
66
66
  end
67
67
 
68
68
  def evil_details
69
- diff = Unparser::Diff.build(mutation.original_source, mutation.source)
70
- diff = color? ? diff.colorized_diff : diff.diff
71
- if diff
72
- output.write(diff)
73
- else
74
- print_no_diff_message
75
- end
76
- end
77
-
78
- def print_no_diff_message
79
- info(
80
- NO_DIFF_MESSAGE,
81
- mutation.original_source,
82
- original_node.inspect,
83
- mutation.source,
84
- mutation.node.inspect
85
- )
69
+ visit(Mutation, mutation)
86
70
  end
87
71
 
88
72
  def noop_details
@@ -90,11 +74,7 @@ module Mutant
90
74
  end
91
75
 
92
76
  def neutral_details
93
- info(NEUTRAL_MESSAGE, original_node.inspect, mutation.source)
94
- end
95
-
96
- def original_node
97
- mutation.subject.node
77
+ info(NEUTRAL_MESSAGE, mutation.node.inspect, mutation.source)
98
78
  end
99
79
 
100
80
  end # MutationResult
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Mutant
4
4
  # Current mutant version
5
- VERSION = '0.10.32'
5
+ VERSION = '0.10.33'
6
6
  end # Mutant
data/lib/mutant.rb CHANGED
@@ -197,6 +197,7 @@ require 'mutant/cli/command/environment/run'
197
197
  require 'mutant/cli/command/environment/show'
198
198
  require 'mutant/cli/command/environment/subject'
199
199
  require 'mutant/cli/command/environment/test'
200
+ require 'mutant/cli/command/util'
200
201
  require 'mutant/cli/command/root'
201
202
  require 'mutant/runner'
202
203
  require 'mutant/runner/sink'
@@ -212,6 +213,7 @@ require 'mutant/reporter/cli/printer/env'
212
213
  require 'mutant/reporter/cli/printer/env_progress'
213
214
  require 'mutant/reporter/cli/printer/env_result'
214
215
  require 'mutant/reporter/cli/printer/isolation_result'
216
+ require 'mutant/reporter/cli/printer/mutation'
215
217
  require 'mutant/reporter/cli/printer/mutation_result'
216
218
  require 'mutant/reporter/cli/printer/status_progressive'
217
219
  require 'mutant/reporter/cli/printer/subject_result'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mutant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.32
4
+ version: 0.10.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-16 00:00:00.000000000 Z
11
+ date: 2021-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs
@@ -186,6 +186,7 @@ files:
186
186
  - lib/mutant/cli/command/environment/test.rb
187
187
  - lib/mutant/cli/command/root.rb
188
188
  - lib/mutant/cli/command/subscription.rb
189
+ - lib/mutant/cli/command/util.rb
189
190
  - lib/mutant/config.rb
190
191
  - lib/mutant/config/coverage_criteria.rb
191
192
  - lib/mutant/context.rb
@@ -316,6 +317,7 @@ files:
316
317
  - lib/mutant/reporter/cli/printer/env_progress.rb
317
318
  - lib/mutant/reporter/cli/printer/env_result.rb
318
319
  - lib/mutant/reporter/cli/printer/isolation_result.rb
320
+ - lib/mutant/reporter/cli/printer/mutation.rb
319
321
  - lib/mutant/reporter/cli/printer/mutation_result.rb
320
322
  - lib/mutant/reporter/cli/printer/status_progressive.rb
321
323
  - lib/mutant/reporter/cli/printer/subject_result.rb
@@ -364,7 +366,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
364
366
  - !ruby/object:Gem::Version
365
367
  version: '0'
366
368
  requirements: []
367
- rubygems_version: 3.2.15
369
+ rubygems_version: 3.1.6
368
370
  signing_key:
369
371
  specification_version: 4
370
372
  summary: ''