crispr 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e22eb1dbacaba9bb6d1e3cb3397f53f1d38eb8c4fec6b8f9296faafb17f1bec
4
- data.tar.gz: 650c04d67c82db6c211a98da8d8e0cfcd01d6b8c442f3425fd0bd34814dd8098
3
+ metadata.gz: d070d677dfe3f0926fff8ddf0a2f31aae859ed65a5fdeb76164eaf180a2fc921
4
+ data.tar.gz: 1a76d002b52a92f4ff756eb11cac032dbaccda83e23fec8bbbfa4ababbfe64a9
5
5
  SHA512:
6
- metadata.gz: 88583c8997c5c85c7d57fe26c779cd6f7fb86fd96c1559cf97174539f8d0c15d1baa58134752ad3f26d469bfc1cb2d7390dbfb1bd46876e95d6709b286db5fc7
7
- data.tar.gz: df10e617deb154c9568707a4d2649213d3a82ff0244b26c1d61e7409843155e4c668f8462209dcfffc719f6c7c80187713f789d0dce0cc97e41aabe1ea5b7c03
6
+ metadata.gz: 7bdf7c8476653270d00188101b87ae5b3de8fbcd6c6d5c572211ed35833dbbd88ad3f9e69fe9abd3921567e7914a50899bc071071f50547dc273b560b0823a5e
7
+ data.tar.gz: cf43c052481ebd7f10d4eaa67056d46e8e85e76419af7675e5b960b743a096e22cbd967bffebfbf86099e693e9f092847f9344e44748c1e5101dac298255ce97
data/.rubocop.yml CHANGED
@@ -7,14 +7,23 @@ AllCops:
7
7
  TargetRubyVersion: 3.1
8
8
 
9
9
  Metrics/AbcSize:
10
- Max: 30
10
+ Enabled: false
11
+
12
+ Metrics/CyclomaticComplexity:
13
+ Enabled: false
11
14
 
12
15
  Metrics/MethodLength:
13
16
  Max: 100
14
17
 
18
+ Metrics/PerceivedComplexity:
19
+ Enabled: false
20
+
15
21
  RSpec/ExampleLength:
16
22
  Max: 20
17
23
 
24
+ RSpec/MultipleExpectations:
25
+ Enabled: false
26
+
18
27
  Style/StringLiterals:
19
28
  EnforcedStyle: double_quotes
20
29
 
data/lib/crispr/cli.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "crispr/mutator"
4
4
  require "crispr/runner"
5
+ require "crispr/reporter"
5
6
 
6
7
  module Crispr
7
8
  # Provides the command-line interface for the Crispr gem.
@@ -11,26 +12,40 @@ module Crispr
11
12
  command = argv.shift
12
13
  case command
13
14
  when "run"
14
- path = argv.shift
15
- unless path && File.exist?(path)
16
- puts "Error: Please specify a valid Ruby file to mutate."
15
+ input_path = argv.shift
16
+ unless input_path && File.exist?(input_path)
17
+ puts "Error: Please specify a valid Ruby file or directory to mutate."
17
18
  exit 1
18
19
  end
19
20
 
20
- source = File.read(path)
21
- mutator = Crispr::Mutator.new(source)
22
- mutations = mutator.mutations
21
+ paths = File.directory?(input_path) ? Dir.glob("#{input_path}/**/*.rb") : [input_path]
23
22
 
24
- if mutations.empty?
25
- puts "No mutations found."
26
- exit 0
27
- end
23
+ reporter = Crispr::Reporter.new
24
+
25
+ paths.each do |path|
26
+ source = File.read(path)
27
+ mutator = Crispr::Mutator.new(source)
28
+ mutations = mutator.mutations
28
29
 
29
- mutations.each_with_index do |mutated, index|
30
- puts "Running mutation #{index + 1}/#{mutations.size}..."
31
- killed = Crispr::Runner.run_mutation(path: path, mutated_source: mutated)
32
- puts killed ? "💥 Mutation killed" : "⚠️ Mutation survived"
30
+ if mutations.empty?
31
+ puts "No mutations found in #{path}."
32
+ next
33
+ end
34
+
35
+ mutations.each_with_index do |mutated, index|
36
+ puts "Running mutation #{index + 1}/#{mutations.size} on #{path}..."
37
+ killed = Crispr::Runner.run_mutation(path: path, mutated_source: mutated)
38
+ reporter.record(killed: killed)
39
+ puts killed ? "💥 Mutation killed" : "⚠️ Mutation survived"
40
+ end
33
41
  end
42
+
43
+ summary = reporter.summary
44
+ puts
45
+ puts "Mutations: #{summary[:mutations]}"
46
+ puts "💥 Killed: #{summary[:killed]}"
47
+ puts "⚠️ Survived: #{summary[:survived]}"
48
+ puts "Score: #{summary[:score]}%"
34
49
  else
35
50
  puts "Usage: crispr run path/to/file.rb"
36
51
  exit 1
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crispr
4
+ # Reporter collects mutation testing results and prints a summary.
5
+ class Reporter
6
+ # Initializes a new Reporter.
7
+ def initialize
8
+ @killed = 0
9
+ @survived = 0
10
+ end
11
+
12
+ # Records the result of a mutation test.
13
+ #
14
+ # @param killed [Boolean] whether the mutation was killed
15
+ # @return [void]
16
+ def record(killed:)
17
+ killed ? @killed += 1 : @survived += 1
18
+ end
19
+
20
+ # Returns the mutation score as a percentage.
21
+ #
22
+ # @return [Float] the mutation score
23
+ def score
24
+ total = @killed + @survived
25
+ total.zero? ? 0.0 : (@killed.to_f / total * 100).round(2)
26
+ end
27
+
28
+ # Returns a summary of mutation results.
29
+ #
30
+ # @return [Hash] summary statistics including totals and score
31
+ def summary
32
+ total = @killed + @survived
33
+ {
34
+ mutations: total,
35
+ killed: @killed,
36
+ survived: @survived,
37
+ score: score
38
+ }
39
+ end
40
+ end
41
+ end
data/lib/crispr/runner.rb CHANGED
@@ -11,14 +11,16 @@ module Crispr
11
11
  #
12
12
  # @param path [String] the path to the source file to mutate
13
13
  # @param mutated_source [String] the mutated version of the file's source code
14
+ # @param test_path [String, nil] optional path to a specific test file to run
14
15
  # @return [Boolean] true if the mutation was killed (test suite failed), false otherwise
15
- def self.run_mutation(path:, mutated_source:)
16
+ def self.run_mutation(path:, mutated_source:, test_path: nil)
16
17
  original_source = File.read(path)
17
18
 
18
19
  begin
19
20
  File.write(path, mutated_source)
20
21
 
21
- stdout, stderr, status = Open3.capture3("bundle exec rspec")
22
+ test_cmd = test_path ? "bundle exec rspec #{test_path}" : "bundle exec rspec"
23
+ stdout, stderr, status = Open3.capture3(test_cmd)
22
24
  killed = !status.success?
23
25
 
24
26
  puts stdout unless status.success?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Crispr
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crispr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron F Stanton
@@ -56,6 +56,7 @@ files:
56
56
  - lib/crispr/cli.rb
57
57
  - lib/crispr/mutations/boolean_mutations.rb
58
58
  - lib/crispr/mutator.rb
59
+ - lib/crispr/reporter.rb
59
60
  - lib/crispr/runner.rb
60
61
  - lib/crispr/version.rb
61
62
  - sig/crispr.rbs