Skip to content

Commit

Permalink
Fix failure with tty::screen and no tty
Browse files Browse the repository at this point in the history
   If there was not a tty then a call to TTY::Screen.height would
   fail and dump a stack trace.  This was causing tests to not
   even run since the debugger also exits with a 1 when this occurs.

   This fix works around the lack of a tty and also no longer exists
   so that we don't miss this kind of error in the future.
  • Loading branch information
logicminds committed Aug 3, 2020
1 parent 9d98152 commit 84508ea
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
12 changes: 8 additions & 4 deletions lib/puppet-debugger/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class Cli
include PuppetDebugger::Support
extend Forwardable
attr_accessor :settings, :log_level, :in_buffer, :out_buffer, :html_mode, :extra_prompt, :bench
attr_reader :source_file, :source_line_num, :hooks
attr_reader :source_file, :source_line_num, :hooks, :options
def_delegators :hooks, :exec_hook, :add_hook, :delete_hook
OUT_SYMBOL = ' => '
def initialize(options = {})
do_initialize if Puppet[:codedir].nil?
Puppet.settings[:name] = :debugger
@options = options
Puppet[:static_catalogs] = false unless Puppet.settings[:static_catalogs].nil?
set_remote_node_name(options[:node_name])
initialize_from_scope(options[:scope])
Expand Down Expand Up @@ -130,7 +131,11 @@ def responder_list

# @return [TTY::Pager] the pager object, disable if CI or testing is present
def pager
@pager ||= TTY::Pager.new(output: out_buffer, enabled: ENV['CI'].nil?)
@pager ||= TTY::Pager.new(output: out_buffer, enabled: pager_enabled?)
end

def pager_enabled?
ENV['CI'].nil?
end

# @param output [String] - the content to output
Expand All @@ -140,8 +145,7 @@ def pager
# Disabled if CI or testing is being done
def handle_output(output)
return if output.nil?

if output.lines.count >= TTY::Screen.height && ENV['CI'].nil?
if pager_enabled? && output.lines.count >= TTY::Screen.height
output << "\n"
pager.page(output)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-debugger/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def puppet_eval(input, file: nil)
Puppet.override({ current_environment: puppet_environment, manifest: manifest_file,
global_scope: scope, loaders: scope.compiler.loaders }, 'For puppet-debugger') do
# because the debugger is not a module we leave the modname blank
scope.environment.known_resource_types.import_ast(ast, 'debugger')
scope.environment.known_resource_types.import_ast(ast, '')

exec_hook :before_eval, '', self, self
if bench
Expand Down
1 change: 0 additions & 1 deletion lib/puppet/application/debugger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ def main
else
puts e.message
puts e.backtrace
exit 1
end
end
end
Expand Down
29 changes: 13 additions & 16 deletions spec/puppet_debugger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
'class testfoo {}'
end
let(:debugger_output) do
"\n => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"Testfoo\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Class[Testfoo]\"\e[0m\n}\n"
" => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"Testfoo\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Class[Testfoo]\"\e[0m\n}\n"
end
it do
debugger.handle_input(input)
expect(output.string).to eq("\n")
expect(output.string).to eq('')
expect(debugger.known_resource_types[:hostclasses]).to include('testfoo')
end
it do
Expand All @@ -63,19 +63,17 @@
'define testfoodefine {}'
end
let(:debugger_output) do
"\n => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"some_name\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Testfoo[some_name]\"\e[0m\n}\n"
" => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"some_name\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Testfoo[some_name]\"\e[0m\n}\n"
end
it do
debugger.handle_input(input)
expect(debugger.scope.environment.known_resource_types.definitions.keys).to include('testfoodefine')
expect(output.string).to eq("\n")
expect(output.string).to eq('')
end
it do
debugger.handle_input(input)
debugger.handle_input("testfoodefine{'some_name':}")
expect(debugger.scope.compiler.resources.collect(&:name)).to include('some_name')
expect(debugger.scope.compiler.resources.collect(&:type)).to include('Testfoodefine')
expect(output.string).to include("\n => Puppet::Type::Component")
expect(output.string).to include(' => Puppet::Type::Component')
end
end
end
Expand Down Expand Up @@ -107,7 +105,7 @@
end
describe 'create' do
it 'shows function' do
expect(output.string).to eq("\n")
expect(output.string).to eq('')
end
end
describe 'run' do
Expand All @@ -134,7 +132,8 @@
''
end
it 'can run' do
debugger_output = "\n"
debugger_output = ''
debugger.handle_input(input)
debugger.handle_input(input)
expect(output.string).to eq(debugger_output)
end
Expand All @@ -143,7 +142,7 @@
' '
end
it 'can run' do
debugger_output = "\n"
debugger_output = ''
debugger.handle_input(input)
expect(output.string).to eq(debugger_output)
end
Expand Down Expand Up @@ -209,19 +208,17 @@
end
it 'shows type' do
debugger.handle_input(input)
expect(output.string).to eq("\n => String\n")
expect(output.string).to eq(" => String\n")
end
end
describe 'Array', type_function: true do
let(:input) do
'type([1,2,3,4])'
end
it 'shows type' do
if Gem::Version.new(Puppet.version) > Gem::Version.new('4.4')
debugger.handle_input(input)
out = "\n => Tuple[Integer[1, 1], Integer[2, 2], Integer[3, 3], Integer[4, 4]]\n"
expect(output.string).to eq(out)
end
debugger.handle_input(input)
out = " => Tuple[Integer[1, 1], Integer[2, 2], Integer[3, 3], Integer[4, 4]]\n"
expect(output.string).to eq(out)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/remote_node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

describe 'set' do
it 'sends message about resetting' do
expect(output.string).to eq("\nResetting to use node puppetdev.localdomain\n")
expect(output.string).to eq(" => Resetting to use node puppetdev.localdomain\n")
end

it 'return node name' do
Expand Down

0 comments on commit 84508ea

Please sign in to comment.