Merge pull request #384 from mbj/fix/incremental-working-set-on-out-of-tree-subjects

Fix incremental working set on out of tree subjects
This commit is contained in:
Dan Kubb 2015-07-23 14:45:21 -07:00
commit d4426ce93a
4 changed files with 76 additions and 30 deletions

View file

@ -1,3 +1,3 @@
---
threshold: 18
total_score: 1204
total_score: 1208

View file

@ -130,6 +130,7 @@ UtilityFunction:
- Mutant::Integration::Null#call
- Mutant::Integration::Rspec#parse_example
- Mutant::Meta::Example::Verification#format_mutation
- Mutant::Repository::Diff#tracks? # intentional, private
- Mutant::Reporter::CLI::Format::Progressive#new_buffer
- Mutant::Reporter::CLI::Printer::StatusProgressive#object # False positive calls super
- Mutant::Integration::Rspec#parse_expression # intentional, private

View file

@ -48,8 +48,10 @@ module Mutant
#
# @api private
def touches?(path, line_range)
return false unless tracks?(path)
command = %W[
git log --pretty=oneline
git log
#{from}...#{to}
-L #{line_range.begin},#{line_range.end}:#{path}
]
@ -61,6 +63,26 @@ module Mutant
!stdout.empty?
end
private
# Test if path is tracked in repository
#
# FIXME: Cache results, to avoid spending time on producing redundant results.
#
# @param [Pathname] path
#
# @return [Boolean]
#
# @api private
def tracks?(path)
command = %W[git ls-files --error-unmatch -- #{path}]
Kernel.system(
*command,
out: File::NULL,
err: File::NULL
)
end
end # Diff
end # Repository
end # Mutant

View file

@ -11,46 +11,69 @@ describe Mutant::Repository::Diff do
let(:object) { described_class.new('from_rev', 'to_rev') }
let(:path) { Pathname.new('foo.rb') }
let(:line_range) { 1..2 }
let(:status) { double('Status', success?: success?) }
let(:stdout) { double('Stdout', empty?: stdout_empty?) }
let(:stdout_empty?) { false }
subject { object.touches?(path, line_range) }
before do
expect(Open3).to receive(:capture2).with(
*expected_command,
binmode: true
).and_return([stdout, status])
expect(Kernel).to receive(:system)
.ordered
.with(
*%w[git ls-files --error-unmatch -- foo.rb],
out: File::NULL,
err: File::NULL
).and_return(git_ls_success?)
end
let(:expected_command) do
%w[
git log --pretty=oneline from_rev...to_rev -L 1,2:foo.rb
]
context 'when file is NOT tracked in repository' do
let(:git_ls_success?) { false }
it { should be(false) }
end
context 'on failure of git command' do
let(:success?) { false }
context 'when file is tracked in repository' do
let(:git_ls_success?) { true }
let(:status) { double('Status', success?: success?) }
let(:stdout) { double('Stdout', empty?: stdout_empty?) }
let(:stdout_empty?) { false }
it 'raises error' do
expect { subject }.to raise_error(Mutant::Repository::RepositoryError, "Command #{expected_command} failed!")
end
end
context 'on suuccess of git command' do
let(:success?) { true }
context 'on empty stdout' do
let(:stdout_empty?) { true }
it { should be(false) }
before do
expect(Open3).to receive(:capture2)
.ordered
.with(*expected_git_log_command, binmode: true)
.and_return([stdout, status])
end
context 'on non empty stdout' do
let(:stdout_empty?) { false }
let(:expected_git_log_command) do
%w[
git log from_rev...to_rev -L 1,2:foo.rb
]
end
it { should be(true) }
context 'on failure of git log command' do
let(:success?) { false }
it 'raises error' do
expect { subject }.to raise_error(
Mutant::Repository::RepositoryError,
"Command #{expected_git_log_command} failed!"
)
end
end
context 'on suuccess of git command' do
let(:success?) { true }
context 'on empty stdout' do
let(:stdout_empty?) { true }
it { should be(false) }
end
context 'on non empty stdout' do
let(:stdout_empty?) { false }
it { should be(true) }
end
end
end
end