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

Print “cached” rather than “identical” when appropriate #1214

Merged
merged 1 commit into from Sep 7, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,13 +20,19 @@ def start
@acc_durations[rep] += Time.now - @start_times[rep]
end

cached_reps = Set.new
Nanoc::Int::NotificationCenter.on(:cached_content_used, self) do |rep|
cached_reps << rep
end

Nanoc::Int::NotificationCenter.on(:rep_written, self) do |rep, _binary, path, is_created, is_modified|
@acc_durations[rep] += Time.now - @start_times[rep]
duration = @acc_durations[rep]

action =
if is_created then :create
elsif is_modified then :update
elsif cached_reps.include?(rep) then :cached
else :identical
end
level =
Expand Down
5 changes: 3 additions & 2 deletions lib/nanoc/cli/logger.rb
Expand Up @@ -8,12 +8,13 @@ module Nanoc::CLI
#
# @api private
class Logger
# Maps actions (`:create`, `:update`, `:identical`, `:skip` and `:delete`)
# Maps actions (`:create`, `:update`, `:identical`, `:cached`, `:skip` and `:delete`)
# onto their ANSI color codes.
ACTION_COLORS = {
create: "\e[32m", # green
update: "\e[33m", # yellow
identical: '', # (nothing)
cached: '', # (nothing)
skip: '', # (nothing)
delete: "\e[31m" # red
}.freeze
Expand All @@ -35,7 +36,7 @@ def initialize
#
# @param [:high, :low] level The importance of this action
#
# @param [:create, :update, :identical, :skip, :delete] action The kind of file action
# @param [:create, :update, :identical, :cached, :skip, :delete] action The kind of file action
#
# @param [String] name The name of the file the action was performed on
#
Expand Down
38 changes: 36 additions & 2 deletions spec/nanoc/cli/commands/compile/file_action_printer_spec.rb
Expand Up @@ -60,19 +60,53 @@
before { listener.start }
before { Nanoc::CLI::Logger.instance.level = :high }

it 'prints skipped (uncompiled) reps' do
it 'does not print skipped (uncompiled) reps' do
expect { listener.stop }
.not_to output(/skip/).to_stdout
end

it 'prints nothing' do
Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))

expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, false, '/foo.html', false, false) }
.not_to output(/identical/).to_stdout
end

it 'prints nothing' do
Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
Nanoc::Int::NotificationCenter.post(:cached_content_used, rep)
Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))

expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, false, '/foo.html', false, false) }
.not_to output(/cached/).to_stdout
end
end

context 'log level = low' do
before { listener.start }
before { Nanoc::CLI::Logger.instance.level = :low }

it 'prints nothing' do
it 'prints skipped (uncompiled) reps' do
expect { listener.stop }
.to output(/skip.*\/hi\.html/).to_stdout
end

it 'prints “identical” if not cached' do
Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))

expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, false, '/foo.html', false, false) }
.to output(/identical/).to_stdout
end

it 'prints “cached” if cached' do
Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
Nanoc::Int::NotificationCenter.post(:cached_content_used, rep)
Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))

expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, false, '/foo.html', false, false) }
.to output(/cached/).to_stdout
end
end
end