Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/facter/custom_facts/core/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ def with_env(values, &block)
# @return [String/nil] Output of the program, or nil if the command does
# not exist or could not be executed.
#
# @deprecated Use #{execute} instead
# @deprecated Use {execute} instead
# @api public
def exec(command)
Facter.warnonce('Facter::Core::Execution.exec is deprecated and will be removed in a future major version. ' \
'Use Facter::Core::Execution.execute instead.')
@@impl.execute(command, on_fail: nil)
end

Expand Down
21 changes: 14 additions & 7 deletions lib/facter/custom_facts/util/resolution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ class Resolution
extend Facter::Core::Execution

class << self
# Expose command execution methods that were extracted into
# Facter::Core::Execution from Facter::Util::Resolution in Facter 2.0.0 for
# compatibility.
#
# @deprecated
#
# @deprecated Use Facter::Core::Execution.which instead
# @api public
public :which, :exec
def which(bin)
Facter.warnonce('Facter::Util::Resolution.which is deprecated and will be removed in a future major version. ' \
'Use Facter::Core::Execution.which instead.')
Facter::Core::Execution.which(bin)
end

# @deprecated Use Facter::Core::Execution.execute instead
# @api public
def exec(command)
Facter.warnonce('Facter::Util::Resolution.exec is deprecated and will be removed in a future major version. ' \
'Use Facter::Core::Execution.execute instead.')
Facter::Core::Execution.execute(command, on_fail: nil)
end

# @api private
public :with_env
Expand Down
1 change: 1 addition & 0 deletions spec/custom_facts/core/execution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
end

it 'delegates #exec to #execute' do
expect(Facter).to receive(:warnonce).with(a_string_including('Facter::Core::Execution.exec is deprecated'))
expect(impl).to receive(:execute).with('waffles', { on_fail: nil })
execution.exec('waffles')
end
Expand Down
28 changes: 28 additions & 0 deletions spec/custom_facts/util/resolution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,34 @@
end
end

describe '.which (deprecated)' do
it 'emits a deprecation warning' do
allow(Facter::Core::Execution).to receive(:which).and_return('/usr/bin/foo')
expect(Facter).to receive(:warnonce).with(a_string_including('Facter::Util::Resolution.which is deprecated'))
Facter::Util::Resolution.which('foo')
end

it 'delegates to Facter::Core::Execution.which' do
allow(Facter).to receive(:warnonce)
expect(Facter::Core::Execution).to receive(:which).with('foo').and_return('/usr/bin/foo')
expect(Facter::Util::Resolution.which('foo')).to eq('/usr/bin/foo')
end
end

describe '.exec (deprecated)' do
it 'emits a deprecation warning' do
allow(Facter::Core::Execution).to receive(:execute).and_return('output')
expect(Facter).to receive(:warnonce).with(a_string_including('Facter::Util::Resolution.exec is deprecated'))
Facter::Util::Resolution.exec('foo')
end

it 'delegates to Facter::Core::Execution.execute with on_fail: nil' do
allow(Facter).to receive(:warnonce)
expect(Facter::Core::Execution).to receive(:execute).with('foo', on_fail: nil).and_return('output')
expect(Facter::Util::Resolution.exec('foo')).to eq('output')
end
end

describe 'evaluating' do
it 'evaluates the block in the context of the given resolution' do
expect(resolution).to receive(:setcode).with('code')
Expand Down