Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PDK-354) Change PDK::Logger to write to STDERR #217

Merged
merged 1 commit into from
Aug 2, 2017
Merged
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
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