diff --git a/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb b/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb index 6c586cbb..7740f4a2 100644 --- a/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb +++ b/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb @@ -1076,6 +1076,10 @@ def remove_secret_identifiers(text) def ps_manager debug_output = Puppet::Util::Log.level == :debug # TODO: Allow you to specify an alternate path, either to pwsh generally or a specific pwsh path. - Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args, debug: debug_output) + if Pwsh::Util.on_windows? + Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args, debug: debug_output) + else + Pwsh::Manager.instance(Pwsh::Manager.pwsh_path, Pwsh::Manager.pwsh_args, debug: debug_output) + end end end diff --git a/lib/pwsh.rb b/lib/pwsh.rb index 49c80a2d..9cbfb336 100644 --- a/lib/pwsh.rb +++ b/lib/pwsh.rb @@ -380,7 +380,7 @@ def self.pwsh_path(additional_paths = []) pwsh_paths << File.join(path, 'pwsh.exe') if File.exist?(File.join(path, 'pwsh.exe')) end else - search_paths.split(File::PATH_SEPARATOR).each do |path| + search_paths.split(':').each do |path| pwsh_paths << File.join(path, 'pwsh') if File.exist?(File.join(path, 'pwsh')) end end diff --git a/lib/pwsh/util.rb b/lib/pwsh/util.rb index 1976112a..ae2c5f32 100644 --- a/lib/pwsh/util.rb +++ b/lib/pwsh/util.rb @@ -7,12 +7,12 @@ module Util module_function # Verifies whether or not the current context is running on a Windows node. + # Implementation copied from `facets`: https://github.com/rubyworks/facets/blob/main/lib/standard/facets/rbconfig.rb # # @return [Bool] true if on windows def on_windows? - # Ruby only sets File::ALT_SEPARATOR on Windows and the Ruby standard - # library uses that to test what platform it's on. - !!File::ALT_SEPARATOR + host_os = RbConfig::CONFIG['host_os'] + !!(host_os =~ /mswin|mingw/) end # Verify paths specified are valid directories which exist. diff --git a/spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb b/spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb index 23089cc6..f5f42035 100644 --- a/spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb +++ b/spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb @@ -2110,21 +2110,44 @@ end describe '.ps_manager' do - before do - allow(Pwsh::Manager).to receive(:powershell_path).and_return('pwsh') - allow(Pwsh::Manager).to receive(:powershell_args).and_return('args') - end + describe '.ps_manager on non-Windows' do + before do + allow(Pwsh::Util).to receive(:on_windows?).and_return(false) + allow(Pwsh::Manager).to receive(:pwsh_path).and_return('pwsh') + allow(Pwsh::Manager).to receive(:pwsh_args).and_return('args') + end - it 'Initializes an instance of the Pwsh::Manager' do - expect(Puppet::Util::Log).to receive(:level).and_return(:normal) - expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: false) - expect { provider.ps_manager }.not_to raise_error + it 'Initializes an instance of the Pwsh::Manager' do + expect(Puppet::Util::Log).to receive(:level).and_return(:normal) + expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: false) + expect { provider.ps_manager }.not_to raise_error + end + + it 'passes debug as true if Puppet::Util::Log.level is debug' do + expect(Puppet::Util::Log).to receive(:level).and_return(:debug) + expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: true) + expect { provider.ps_manager }.not_to raise_error + end end - it 'passes debug as true if Puppet::Util::Log.level is debug' do - expect(Puppet::Util::Log).to receive(:level).and_return(:debug) - expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: true) - expect { provider.ps_manager }.not_to raise_error + describe '.ps_manager on Windows' do + before do + allow(Pwsh::Util).to receive(:on_windows?).and_return(true) + allow(Pwsh::Manager).to receive(:powershell_path).and_return('pwsh') + allow(Pwsh::Manager).to receive(:powershell_args).and_return('args') + end + + it 'Initializes an instance of the Pwsh::Manager' do + expect(Puppet::Util::Log).to receive(:level).and_return(:normal) + expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: false) + expect { provider.ps_manager }.not_to raise_error + end + + it 'passes debug as true if Puppet::Util::Log.level is debug' do + expect(Puppet::Util::Log).to receive(:level).and_return(:debug) + expect(Pwsh::Manager).to receive(:instance).with('pwsh', 'args', debug: true) + expect { provider.ps_manager }.not_to raise_error + end end end end