Skip to content

Commit

Permalink
Merge pull request #93 from nevinera/nev-92--support-logging-normal
Browse files Browse the repository at this point in the history
Support `--logging normal` (and variants)
  • Loading branch information
nevinera authored Jun 4, 2023
2 parents e78ce15 + 7f03c71 commit 82ed4dd
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
4 changes: 4 additions & 0 deletions lib/quiet_quality/cli/arg_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def setup_filter_messages_options(parser)
end

def setup_logging_options(parser)
parser.on("-n", "--normal", "Print outcomes and messages") do
set_global_option(:logging, Config::Logging::NORMAL)
end

parser.on("-l", "--light", "Print aggregated results only") do
set_global_option(:logging, Config::Logging::LIGHT)
end
Expand Down
5 changes: 3 additions & 2 deletions lib/quiet_quality/config/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module Config
class Logging
LIGHT = :light
QUIET = :quiet
LEVELS = [LIGHT, QUIET].freeze
NORMAL = :normal
LEVELS = [LIGHT, QUIET, NORMAL].freeze

attr_accessor :level

def initialize(level: nil)
def initialize(level: NORMAL)
@level = level
end

Expand Down
10 changes: 9 additions & 1 deletion spec/quiet_quality/cli/arg_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def self.expect_usage_error(desc, arguments, matcher)
-B, --comparison-branch BRANCH Specify the branch to compare against
-f, --filter-messages [tool] Filter messages from tool(s) based on changed lines
-u, --unfiltered [tool] Don't filter messages from tool(s)
-n, --normal Print outcomes and messages
-l, --light Print aggregated results only
-q, --quiet Don't print results, only return a status code
-L, --logging LEVEL Specify logging mode that results will be returned in. Valid options: light, quiet
Expand Down Expand Up @@ -145,13 +146,20 @@ def self.expect_usage_error(desc, arguments, matcher)
expect_options("--light", ["--light"], global: {logging: :light})
expect_options("-q", ["-q"], global: {logging: :quiet})
expect_options("--quiet", ["--quiet"], global: {logging: :quiet})
expect_options("-n", ["-n"], global: {logging: :normal})
expect_options("--normal", ["--normal"], global: {logging: :normal})

expect_options("-lq", ["-lq"], global: {logging: :quiet})
expect_options("-ql", ["-ql"], global: {logging: :light})
expect_options("-nl", ["-nl"], global: {logging: :light})
expect_options("-qn", ["-qn"], global: {logging: :normal})

expect_options("no logging option passed", [], global: {logging: nil})
expect_options("--logging light", ["--logging", "light"], global: {logging: :light})
expect_options("-Llight", ["-Llight"], global: {logging: :light})
expect_options("--logging quiet", ["--logging", "quiet"], global: {logging: :quiet})
expect_options("-Lquiet", ["-Lquiet"], global: {logging: :quiet})
expect_options("--logging normal", ["--logging", "normal"], global: {logging: :normal})
expect_options("-Lnormal", ["-Lnormal"], global: {logging: :normal})
expect_usage_error("-Lshenanigans", ["-Lshenanigans"], /Unrecognized logging level/i)
end

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

context "when global_options[:logging] is unset" do
let(:global_options) { {} }
it { is_expected.to be_nil }
it { is_expected.to eq(:normal) }
end

context "when global_options[:logging] is specified" do
Expand Down
33 changes: 24 additions & 9 deletions spec/quiet_quality/config/logging_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
RSpec.describe QuietQuality::Config::Logging do
subject(:logging) { described_class.new(level: level) }

describe "#light?" do
subject { described_class.new(level: level).light? }
subject { logging.light? }

context "level is not supplied" do
let(:logging) { described_class.new }
it { is_expected.to be(false) }
end

context "level is nil" do
let(:level) { nil }
context "level is :normal" do
let(:level) { described_class::NORMAL }
it { is_expected.to be(false) }
end

Expand All @@ -19,10 +26,15 @@
end

describe "#quiet?" do
subject { described_class.new(level: level).quiet? }
subject { logging.quiet? }

context "level is nil" do
let(:level) { nil }
context "level is not supplied" do
let(:logging) { described_class.new }
it { is_expected.to be(false) }
end

context "level is :normal" do
let(:level) { described_class::NORMAL }
it { is_expected.to be(false) }
end

Expand All @@ -41,14 +53,17 @@
it "returns the level" do
expect(described_class.new(level: :light).level).to eq(:light)
expect(described_class.new(level: :quiet).level).to eq(:quiet)
expect(described_class.new.level).to be_nil
expect(described_class.new.level).to eq(:normal)
end
end

describe "#level=" do
let(:level) { described_class::NORMAL }

it "sets the level" do
logging = described_class.new
expect { logging.level = :light }.to change { logging.level }.from(nil).to(:light)
expect { logging.level = :light }
.to change { logging.level }
.from(:normal).to(:light)
end
end
end
1 change: 1 addition & 0 deletions spec/quiet_quality/config/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def self.expect_config(description, config, defaults: nil, globals: nil, tools:
expect_config "no logging", %({}), globals: {comparison_branch: nil}
expect_config "the valid 'light' logging option", %({logging: "light"}), globals: {logging: :light}
expect_config "the valid 'quiet' logging option", %({logging: "quiet"}), globals: {logging: :quiet}
expect_config "the valid 'normal' logging option", %({logging: "normal"}), globals: {logging: :normal}
expect_invalid "a numeric logging option", %({logging: 5}), /must be a string/
expect_invalid "an empty logging option", %({logging: ""}), /option logging must be one of the allowed values/
expect_invalid "an invalid logging option", %({logging: shecklackity}), /option logging must be one of the allowed values/
Expand Down

0 comments on commit 82ed4dd

Please sign in to comment.