Skip to content

Commit

Permalink
Actually we just need one runner
Browse files Browse the repository at this point in the history
  • Loading branch information
hanneskaeufler committed Dec 19, 2019
1 parent 4151c18 commit 541ea23
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 126 deletions.
2 changes: 1 addition & 1 deletion bin/test-mutations
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

list=(`find spec -name '*_spec.cr' -and -not -name 'integration_spec.cr'`)
printf '%s\n' "${list[@]}" | sort
./bin/crytic test-parallel --min-msi=70.0 --reporters=Console,Stryker,ConsoleFileSummary "${list[@]}"
./bin/crytic test --min-msi=70.0 --reporters=Console,Stryker,ConsoleFileSummary "${list[@]}"
2 changes: 1 addition & 1 deletion bin/test-unit
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

crystal spec -D skip-integration
crystal spec -Dpreview-mt -D skip-integration
20 changes: 9 additions & 11 deletions spec/integration_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ require "./spec_helper"
end
end

{% for command in ["test", "test-parallel"] %}
describe "the {{ command.id }} command" do
describe "the test command" do
describe "--preamble/-p" do
it "injects the given custom preamble, failing the neutral mutant" do
result = run_crytic("{{ command.id }} -s ./fixtures/conditionals/fully_covered.cr ./fixtures/conditionals/uncovered_spec.cr -p 'exit 1'")
result = run_crytic("test -s ./fixtures/conditionals/fully_covered.cr ./fixtures/conditionals/uncovered_spec.cr -p 'exit 1'")
result.output.should contain("unmodified subject")
result.output.should_not contain("ConditionFlip")
result.exit_code.should eq 1
Expand All @@ -26,7 +25,7 @@ require "./spec_helper"

describe "with a fully covered subject" do
it "passes the mutation specs" do
result = run_crytic("{{ command.id }} -s ./fixtures/conditionals/fully_covered.cr ./fixtures/conditionals/fully_covered_spec.cr")
result = run_crytic("test -s ./fixtures/conditionals/fully_covered.cr ./fixtures/conditionals/fully_covered_spec.cr")
result.output.should contain("✅ ConditionFlip")
result.output.should contain("✅ BoolLiteralFlip")
result.output.should contain("3 covered")
Expand All @@ -36,22 +35,22 @@ require "./spec_helper"

describe "with an insufficiently covered subject" do
it "fails the mutation specs" do
result = run_crytic("{{ command.id }} -s ./fixtures/conditionals/fully_covered.cr ./fixtures/conditionals/uncovered_spec.cr")
result = run_crytic("test -s ./fixtures/conditionals/fully_covered.cr ./fixtures/conditionals/uncovered_spec.cr")
result.output.should contain("❌ ConditionFlip")
result.output.should contain("❌ BoolLiteralFlip")
result.output.should contain("3 uncovered")
result.exit_code.should be > 0
end

it "exits successfully when the msi threshold is set sufficiently" do
result = run_crytic("{{ command.id }} --min-msi=0.0 -s ./fixtures/conditionals/fully_covered.cr ./fixtures/conditionals/uncovered_spec.cr")
result = run_crytic("test --min-msi=0.0 -s ./fixtures/conditionals/fully_covered.cr ./fixtures/conditionals/uncovered_spec.cr")
result.exit_code.should eq 0
end
end

describe "without passing a subject or tests" do
it "mutates all sources and runs all tests" do
result = run_crytic_in_dir("./fixtures/autofind", {{ command }})
result = run_crytic_in_dir("./fixtures/autofind", "test")
result.output.should contain("✅ ConditionFlip")
result.output.should contain("✅ BoolLiteralFlip")
result.output.should contain("✅ NumberLiteralSignFlip")
Expand All @@ -65,7 +64,7 @@ require "./spec_helper"

describe "subject without any coverage" do
it "fails all mutants" do
result = run_crytic("{{ command.id }} -s ./fixtures/uncovered/without.cr ./fixtures/uncovered/without_spec.cr")
result = run_crytic("test -s ./fixtures/uncovered/without.cr ./fixtures/uncovered/without_spec.cr")
result.output.should contain("❌ BoolLiteralFlip")
result.output.should contain("❌ ConditionFlip")
result.output.should contain("❌ NumberLiteralSignFlip")
Expand All @@ -77,7 +76,7 @@ require "./spec_helper"

describe "a failing initial test suite" do
it "reports initial failure" do
result = run_crytic("{{ command.id }} -s ./fixtures/uncovered/without.cr ./fixtures/failing/failing_spec.cr")
result = run_crytic("test -s ./fixtures/uncovered/without.cr ./fixtures/failing/failing_spec.cr")
result.output.should contain "❌ Original test suite failed.\n"
result.output.should contain "no overload matches"
result.exit_code.should be > 0
Expand All @@ -86,14 +85,13 @@ require "./spec_helper"

describe "a subject that is mutated into an endless loop" do
it "finishes and reports a timed out spec" do
result = run_crytic("{{ command.id }} -s ./fixtures/timeout/timeout.cr ./fixtures/timeout/timeout_spec.cr")
result = run_crytic("test -s ./fixtures/timeout/timeout.cr ./fixtures/timeout/timeout_spec.cr")
result.output.should contain "✅ Original test suite passed.\n"
result.output.should contain "1 timeout"
result.exit_code.should be > 0
end
end
end
{% end %}

describe "the noop command" do
it "outputs the noop'ed code to stdout" do
Expand Down
51 changes: 0 additions & 51 deletions spec/runner/sequential_spec.cr

This file was deleted.

7 changes: 2 additions & 5 deletions src/crytic/cli.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "./command/*"
require "./runner/parallel"
require "./runner/sequential"
require "./side_effects"

module Crytic
Expand All @@ -12,15 +11,13 @@ module Crytic
def run(args)
case args.first?
when "test"
Command::Test.new(Runner::Sequential.new, @side_effects).execute(args.tap(&.shift))
when "test-parallel"
Command::Test.new(Runner::Parallel.new, @side_effects).execute(args.tap(&.shift))
Command::Test.new(@side_effects).execute(args.tap(&.shift))
when "noop"
Command::Noop
.new(@side_effects, Command::Noop::DEFAULT_SPEC_FILES_GLOB)
.execute(args.tap(&.shift))
else
Command::Test.new(Runner::Sequential.new, @side_effects).execute(args)
Command::Test.new(@side_effects).execute(args)
end
end
end
Expand Down
1 change: 0 additions & 1 deletion src/crytic/cli_options.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module Crytic
@preamble = Generator::Generator::DEFAULT_PREAMBLE
@spec_files = [] of String
@subject = [] of String
getter multi_threaded : Bool = false

def initialize(@side_effects : SideEffects, @spec_files_glob : String)
@reporters << Reporter::IoReporter.new(@side_effects.std_out)
Expand Down
6 changes: 3 additions & 3 deletions src/crytic/command/test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ require "../cli_options"
require "../generator/in_memory_generator"
require "../generator/isolated_mutation_factory"
require "../mutation/no_mutation"
require "../runner/parallel"
require "../runner/run"
require "../runner/runner"
require "../side_effects"
require "../subject"

class Crytic::Command::Test
def initialize(@runner : Runner::Runner, @side_effects : SideEffects)
def initialize(@side_effects : SideEffects)
end

def execute(args)
Expand All @@ -18,7 +18,7 @@ class Crytic::Command::Test
Mutation::NoMutation.with(specs)
}

@runner.run(Crytic::Runner::Run.from_options(options, generator, factory), @side_effects)
Crytic::Runner::Parallel.run(Crytic::Runner::Run.from_options(options, generator, factory), @side_effects)
end

private def parse_options(args)
Expand Down
13 changes: 3 additions & 10 deletions src/crytic/runner/parallel.cr
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require "../mutation/result_set"
require "./runner"

module Crytic::Runner
class Parallel < Runner
private SLICE_SIZE = 2
class Parallel
private SLICE_SIZE = 5

def run(run, side_effects) : Bool
original_result = run.execute_original_test_suite(side_effects)
Expand All @@ -28,22 +27,16 @@ module Crytic::Runner
mutation_sets.each_slice(SLICE_SIZE) do |slice|
channel = Channel(Array(Mutation::Result)).new(SLICE_SIZE)

slice.each_with_index do |set, idx|
STDOUT.puts "--- Mutant ##{idx}"
slice.each do |set|
spawn do
STDOUT.puts "Run neutral mutant ##{idx}"
neutral_result = set.run_neutral(run)
STDOUT.puts "Finished neutral mutant ##{idx}"

if neutral_result.errored?
channel.send(discard_further_mutations_for_single_subject)
else
STDOUT.puts "Run mutant ##{idx}"
channel.send(set.run_mutated(run))
STDOUT.puts "Finished mutant ##{idx}"
end
rescue exc
STDOUT.puts exc
run.report_exception(exc)
channel.send(discard_further_mutations_for_single_subject)
end
Expand Down
8 changes: 0 additions & 8 deletions src/crytic/runner/runner.cr

This file was deleted.

35 changes: 0 additions & 35 deletions src/crytic/runner/sequential.cr

This file was deleted.

0 comments on commit 541ea23

Please sign in to comment.