Skip to content

Commit

Permalink
♻️ Added additional deocrators
Browse files Browse the repository at this point in the history
- Broke out `decorate()` method in Loginator to support access to all decorators
- Updated banner and heading generation to calculate widths including Unicode characters
- Fixed logging statements.
  • Loading branch information
mkarlesky committed May 4, 2024
1 parent 7e3846c commit 815d02f
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 40 deletions.
8 changes: 4 additions & 4 deletions bin/cli_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setup
@actions = @actions_wrapper

# Automatic setting of console printing decorations
@loginator.decorate = !windows?()
@loginator.decorators = !windows?()
end


Expand Down Expand Up @@ -216,17 +216,17 @@ def process_decoration(env, config={})
decorate = true
end

@loginator.decorate = decorate
@loginator.decorators = decorate
end

# Otherwise inspect project configuration (could be blank and gets skipped)
walk = @config_walkinator.fetch_value( config, :project, :use_decorators )
if (!walk[:value].nil?)
case walk[:value]
when :all
@loginator.decorate = true
@loginator.decorators = true
when :none
@loginator.decorate = false
@loginator.decorators = false
else #:auto
# Retain what was set in `setup()` above based on platform
end
Expand Down
1 change: 1 addition & 0 deletions ceedling.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ceedling projects are created with a YAML configuration file. A variety of conve
s.add_dependency "rake", ">= 12", "< 14"
s.add_dependency "deep_merge", "~> 1.2"
s.add_dependency "constructor", "~> 2"
s.add_dependency "unicode-display_width", ">= 2.5.0"

# Files needed from submodules
s.files = []
Expand Down
2 changes: 1 addition & 1 deletion lib/ceedling/build_batchinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setup
# Neaten up a build step with progress message and some scope encapsulation
def build_step(msg, heading: true, &block)
if heading
msg = @reportinator.generate_heading(msg)
msg = @reportinator.generate_heading( @loginator.decorate( msg, LogLabels::RUN ) )
else # Progress message
msg = "\n" + @reportinator.generate_progress(msg)
end
Expand Down
22 changes: 12 additions & 10 deletions lib/ceedling/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ class Verbosity

# Label + decorator options for logging
class LogLabels
NONE = 0 # Override logic and settings with no label and no decoration
AUTO = 1 # Default labeling and decorators
NOTICE = 2 # 'NOTICE:'
WARNING = 3 # 'WARNING:'
ERROR = 4 # 'ERROR:'
EXCEPTION = 5 # 'EXCEPTION:'
CONSTRUCT = 6 # 🚧 decorator only
STOPWATCH = 7 # ⏱️ decorator only
SEGFAULT = 8 # ☠️ decorator only
TITLE = 9 # 🌱 decorator only
NONE = 0 # Override logic and settings with no label and no decoration
AUTO = 1 # Default labeling and decorators
NOTICE = 2 # decorator + 'NOTICE:'
WARNING = 3 # decorator + 'WARNING:'
ERROR = 4 # decorator + 'ERROR:'
EXCEPTION = 5 # decorator + 'EXCEPTION:'
CONSTRUCT = 6 # decorator only
RUN = 7 # decorator only
SEGFAULT = 8 # decorator only
PASS = 9 # decorator only
FAIL = 10 # decorator only
TITLE = 11 # decorator only

# Verbosity levels ERRORS – DEBUG default to certain labels or lack thereof
# The above label constants are available to override Loginator's default AUTO level as needed
Expand Down
59 changes: 39 additions & 20 deletions lib/ceedling/loginator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
class Loginator

attr_reader :project_logging
attr_writer :decorate
attr_writer :decorators

constructor :verbosinator, :stream_wrapper, :file_wrapper, :system_wrapper

def setup()
@decorate = false
@decorators = false

@replace = {
# Problematic characters pattern => Simple characters
Expand Down Expand Up @@ -91,10 +91,42 @@ def out(string, verbosity=Verbosity::NORMAL, label=LogLabels::AUTO, stream=nil)
return if !(@verbosinator.should_output?( verbosity ))

# Add labels and fun characters
console_str = format( string, verbosity, label, @decorate )
console_str = format( string, verbosity, label, @decorators )

# Write to output stream after optionally removing any problematic characters
stream.print( sanitize( console_str, @decorate ) )
stream.print( sanitize( console_str, @decorators ) )
end


def decorate(str, label=LogLabels::NONE)
return str if !@decorators

prepend = ''

case label
when LogLabels::NOTICE
prepend = 'ℹ️ '
when LogLabels::WARNING
prepend = '⚠️ '
when LogLabels::ERROR
prepend = '🪲 '
when LogLabels::EXCEPTION
prepend = '🧨 '
when LogLabels::CONSTRUCT
prepend = '🚧 '
when LogLabels::SEGFAULT
prepend = '☠️ '
when LogLabels::RUN
prepend = '👟 '
when LogLabels::PASS
prepend = '✅ '
when LogLabels::FAIL
prepend = '❌ '
when LogLabels::TITLE
prepend = '🌱 '
end

return prepend + str
end

### Private ###
Expand Down Expand Up @@ -130,22 +162,9 @@ def format(string, verbosity, label, decorate)
prepend = '⚠️ '
end
# Otherwise, no decorators for verbosity levels
when LogLabels::NOTICE
prepend = 'ℹ️ '
when LogLabels::WARNING
prepend = '⚠️ '
when LogLabels::ERROR
prepend = '🪲 '
when LogLabels::EXCEPTION
prepend = '🧨 '
when LogLabels::CONSTRUCT
prepend = '🚧 '
when LogLabels::STOPWATCH
prepend = '⏱️ '
when LogLabels::SEGFAULT
prepend = '☠️ '
when LogLabels::TITLE
prepend = '🌱 '
else
# If not auto, go get us a decorator
prepend = decorate('', label)
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/ceedling/rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def log_runtime(run, start_time_s, end_time_s, enabled)
return if duration.empty?

@ceedling[:loginator].out( "\n" )
@ceedling[:loginator].log( "Ceedling #{run} completed in #{duration}", Verbosity::NORMAL, LogLabels::STOPWATCH )
@ceedling[:loginator].log( "Ceedling #{run} completed in #{duration}", Verbosity::NORMAL)
end

start_time = nil # Outside scope of exception handling
Expand Down Expand Up @@ -133,7 +133,8 @@ def test_failures_handler()

exit(0)
else
@ceedling[:loginator].log( "Ceedling could not complete operations because of errors", Verbosity::ERRORS )
msg = "Ceedling could not complete operations because of errors"
@ceedling[:loginator].log( msg, Verbosity::ERRORS, LogLabels::TITLE )
begin
@ceedling[:plugin_manager].post_error
rescue => ex
Expand Down
6 changes: 4 additions & 2 deletions lib/ceedling/reportinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# SPDX-License-Identifier: MIT
# =========================================================================

require 'unicode/display_width'

##
# Pretifies reports
class Reportinator
Expand Down Expand Up @@ -87,14 +89,14 @@ def generate_banner(message, width=nil)
# ---------
# <Message>
# ---------
dash_count = ((width.nil?) ? message.strip.length : width)
dash_count = ((width.nil?) ? Unicode::DisplayWidth.of( message.strip ) : width)
return "#{'-' * dash_count}\n#{message}\n#{'-' * dash_count}\n"
end

def generate_heading(message)
# <Message>
# ---------
return "\n#{message}\n#{'-' * message.length}"
return "\n#{message}\n#{'-' * Unicode::DisplayWidth.of( message.strip )}"
end

def generate_progress(message)
Expand Down
3 changes: 2 additions & 1 deletion plugins/report_tests_pretty_stdout/assets/template.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
% end
% total_string = hash[:results][:counts][:total].to_s
% format_string = "%#{total_string.length}i"
<%=@ceedling[:plugin_reportinator].generate_banner(header_prepend + 'OVERALL TEST SUMMARY')%>
% decorator = (failed > 0) ? LogLabels::FAIL : LogLabels::PASS
<%=@ceedling[:plugin_reportinator].generate_banner(header_prepend + @loginator.decorate('OVERALL TEST SUMMARY', decorator))%>
% if (hash[:results][:counts][:total] > 0)
TESTED: <%=hash[:results][:counts][:total].to_s%>
PASSED: <%=sprintf(format_string, hash[:results][:counts][:passed])%>
Expand Down

0 comments on commit 815d02f

Please sign in to comment.