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

Log module loading warning to stderr #385

Merged
merged 1 commit into from
Jul 3, 2024
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
2 changes: 1 addition & 1 deletion lib/hammer_cli/modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def self.load!(name)
require_module(name)
rescue Exception => e
logger.error "Error while loading module #{name}."
puts _("Warning: An error occured while loading module %s.") % name
$stderr.puts _("Warning: An error occurred while loading module %s.") % name
# with ModuleLoadingError we assume the error is already logged by the issuer
logger.error e unless e.is_a?(HammerCLI::ModuleLoadingError)
raise e
Expand Down
9 changes: 4 additions & 5 deletions test/unit/modules_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,25 @@ def self.version
before :each do
HammerCLI::Modules.stubs(:require_module).raises(RuntimeError)
@error_msg = "ERROR Modules : Error while loading module hammer_cli_tom."
@warning_msg = "Warning: An error occured while loading module hammer_cli_tom."
@warning_msg = "Warning: An error occurred while loading module hammer_cli_tom."
end

it "must log an error if the load! fails" do
out, _ = capture_io do
assert_output("", "#{@warning_msg}\n") do
assert_raises(RuntimeError) { HammerCLI::Modules.load!('hammer_cli_tom') }
end
_(out).must_equal "#{@warning_msg}\n"
_(@log_output.readline.strip).must_equal @error_msg
end

it "must log an error if the load fails" do
assert_output("#{@warning_msg}\n", "") do
assert_output("", "#{@warning_msg}\n") do
HammerCLI::Modules.load("hammer_cli_tom")
end
_(@log_output.readline.strip).must_equal @error_msg
end

it "must return false when load fails" do
assert_output("#{@warning_msg}\n", "") do
assert_output("", "#{@warning_msg}\n") do
_(HammerCLI::Modules.load("hammer_cli_tom")).must_equal false
end
end
Expand Down
Loading