From 731a2b3a344764b5a5a709b2279a39c3682ceea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 4 Nov 2019 21:17:29 +0100 Subject: [PATCH] Fix uninitialized global variable warning In particular, ``` warning: global variable `$thor_runner' not initialized ``` --- lib/thor.rb | 1 + spec/fixtures/verbose.thor | 10 ++++++++++ spec/no_warnings_spec.rb | 10 ++++++++++ 3 files changed, 21 insertions(+) create mode 100644 spec/fixtures/verbose.thor create mode 100644 spec/no_warnings_spec.rb diff --git a/lib/thor.rb b/lib/thor.rb index e77f53857..19a245b84 100644 --- a/lib/thor.rb +++ b/lib/thor.rb @@ -398,6 +398,7 @@ def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable Me # the namespace should be displayed as arguments. # def banner(command, namespace = nil, subcommand = false) + $thor_runner ||= false command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |formatted_usage| "#{basename} #{formatted_usage}" end.join("\n") diff --git a/spec/fixtures/verbose.thor b/spec/fixtures/verbose.thor new file mode 100644 index 000000000..f7f1f367f --- /dev/null +++ b/spec/fixtures/verbose.thor @@ -0,0 +1,10 @@ +#!/usr/bin/ruby + +$VERBOSE = true + +require 'thor' + +class Test < Thor +end + +Test.start(ARGV) diff --git a/spec/no_warnings_spec.rb b/spec/no_warnings_spec.rb new file mode 100644 index 000000000..1ca6d6dfc --- /dev/null +++ b/spec/no_warnings_spec.rb @@ -0,0 +1,10 @@ +require "open3" + +context "when $VERBOSE is enabled" do + it "prints no warnings" do + root = File.expand_path("..", __dir__) + _, err, _ = Open3.capture3("ruby -I #{root}/lib #{root}/spec/fixtures/verbose.thor") + + expect(err).to be_empty + end +end