Skip to content

Commit

Permalink
Merge pull request #217 from scotje/354_logger_stderr
Browse files Browse the repository at this point in the history
(PDK-354) Change PDK::Logger to write to STDERR
  • Loading branch information
scotje committed Aug 2, 2017
2 parents 48741a5 + 13dad13 commit 5eb7f56
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 24 deletions.
3 changes: 1 addition & 2 deletions lib/pdk/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ def self.logger

class Logger < ::Logger
def initialize
# TODO: Decide where log output goes, probably stderr?
super(STDOUT)
super(STDERR)

# TODO: Decide on output format.
self.formatter = proc do |severity, _datetime, _progname, msg|
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/bundle_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

describe command('pdk test unit --debug') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match(%r{Checking for missing Gemfile dependencies}i) }
its(:stderr) { is_expected.to match(%r{Checking for missing Gemfile dependencies}i) }

describe file('Gemfile.lock') do
it { is_expected.to be_file }
Expand Down
18 changes: 9 additions & 9 deletions spec/acceptance/new_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
context 'when creating the main class' do
describe command('pdk new class new_class') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match(%r{Creating .* from template}) }
its(:stdout) { is_expected.not_to match(%r{WARN|ERR}) }
its(:stderr) { is_expected.to match(%r{Creating .* from template}) }
its(:stderr) { is_expected.not_to match(%r{WARN|ERR}) }
# use this weird regex to match for empty string to get proper diff output on failure
its(:stderr) { is_expected.to match(%r{\A\Z}) }
its(:stdout) { is_expected.to match(%r{\A\Z}) }
end

describe file('manifests') do
Expand All @@ -35,10 +35,10 @@
context 'when creating an ancillary class' do
describe command('pdk new class new_class::bar') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match(%r{Creating .* from template}) }
its(:stdout) { is_expected.not_to match(%r{WARN|ERR}) }
its(:stderr) { is_expected.to match(%r{Creating .* from template}) }
its(:stderr) { is_expected.not_to match(%r{WARN|ERR}) }
# use this weird regex to match for empty string to get proper diff output on failure
its(:stderr) { is_expected.to match(%r{\A\Z}) }
its(:stdout) { is_expected.to match(%r{\A\Z}) }
end

describe file('manifests') do
Expand All @@ -63,10 +63,10 @@
context 'when creating a deeply nested class' do
describe command('pdk new class new_class::bar::baz') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match(%r{Creating .* from template}) }
its(:stdout) { is_expected.not_to match(%r{WARN|ERR}) }
its(:stderr) { is_expected.to match(%r{Creating .* from template}) }
its(:stderr) { is_expected.not_to match(%r{WARN|ERR}) }
# use this weird regex to match for empty string to get proper diff output on failure
its(:stderr) { is_expected.to match(%r{\A\Z}) }
its(:stdout) { is_expected.to match(%r{\A\Z}) }
end

describe file('manifests') do
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/new_module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

describe command('pdk new module foo --skip-interview') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match(%r{Creating new module: foo}) }
its(:stdout) { is_expected.not_to match(%r{WARN|ERR}) }
its(:stderr) { is_expected.to match(%r{Creating new module: foo}) }
its(:stderr) { is_expected.not_to match(%r{WARN|ERR}) }
# use this weird regex to match for empty string to get proper diff output on failure
its(:stderr) { is_expected.to match(%r{\A\Z}) }
its(:stdout) { is_expected.to match(%r{\A\Z}) }
end

describe file('foo') do
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/support/it_requires_running_in_a_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

describe command(top_level_description) do
its(:exit_status) { is_expected.not_to eq(0) }
its(:stdout) { is_expected.to match(%r{must be run from inside a module}i) }
its(:stderr) { is_expected.to match(%r{\A\Z}) }
its(:stderr) { is_expected.to match(%r{must be run from inside a module}i) }
its(:stdout) { is_expected.to match(%r{\A\Z}) }
end
end
end
2 changes: 1 addition & 1 deletion spec/acceptance/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

describe command('pdk test unit') do
its(:exit_status) { is_expected.not_to eq(0) }
its(:stdout) { is_expected.to match(%r{no metadata\.json found}i) }
its(:stderr) { is_expected.to match(%r{no metadata\.json found}i) }
end
end
end
2 changes: 1 addition & 1 deletion spec/acceptance/test_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@

describe command('pdk test unit --list') do
its(:exit_status) { is_expected.not_to eq(0) }
its(:stdout) { is_expected.to match(%r{Unable to enumerate examples.*SyntaxError}m) }
its(:stderr) { is_expected.to match(%r{Unable to enumerate examples.*SyntaxError}m) }
end

describe command('pdk test unit') do
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/validate_all_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class validate_all { }

describe command('pdk validate --list') do
its(:exit_status) { is_expected.to eq(0) }
its(:stdout) { is_expected.to match(%r{Available validators: metadata, puppet, ruby}i) }
its(:stderr) { is_expected.to match(%r{Available validators: metadata, puppet, ruby}i) }
end

describe command('pdk validate') do
its(:exit_status) { is_expected.to eq(0) }
its(:stdout) { is_expected.to match(%r{Running all available validators}i) }
its(:stderr) { is_expected.to match(%r{Running all available validators}i) }
its(:stderr) { is_expected.to match(%r{Checking metadata \(metadata\.json\)}i) }
its(:stderr) { is_expected.to match(%r{Checking Puppet manifest syntax}i) }
its(:stderr) { is_expected.to match(%r{Checking Puppet manifest style}i) }
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/pdk/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@

context 'by default' do
it 'prints info messages to stdout' do
expect(STDOUT).to receive(:write).with(a_string_matching(%r{test message}))
expect(STDERR).to receive(:write).with(a_string_matching(%r{test message}))

pdk_logger.info('test message')
end

it 'does not print debug messages to stdout' do
expect(STDOUT).not_to receive(:write).with(anything)
expect(STDERR).not_to receive(:write).with(anything)

pdk_logger.debug('test message')
end
end

context 'with debug output enabled' do
it 'prints debug messages to stdout' do
expect(STDOUT).to receive(:write).with(a_string_matching(%r{test debug message}))
expect(STDERR).to receive(:write).with(a_string_matching(%r{test debug message}))

pdk_logger.enable_debug_output
pdk_logger.debug('test debug message')
Expand Down

0 comments on commit 5eb7f56

Please sign in to comment.