Skip to content

Commit

Permalink
Merge pull request #329 from nanoc/bug/dependency-tracker-stack-not-e…
Browse files Browse the repository at this point in the history
…mpty-after-error

Dependency tracker stack not empty after error
  • Loading branch information
bobthecow committed Aug 31, 2013
2 parents 5a8f79a + a790a40 commit f2c1fd7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/nanoc/base/compilation/compiler.rb
Expand Up @@ -389,13 +389,14 @@ def compile_rep(rep)
rep.compiled = true
compiled_content_cache[rep] = rep.content

Nanoc::NotificationCenter.post(:visit_ended, rep.item)
Nanoc::NotificationCenter.post(:processing_ended, rep)
Nanoc::NotificationCenter.post(:compilation_ended, rep)
rescue => e
rep.forget_progress
Nanoc::NotificationCenter.post(:compilation_failed, rep, e)
raise e
ensure
Nanoc::NotificationCenter.post(:visit_ended, rep.item)
end

# Clears the list of dependencies for items that will be recompiled.
Expand Down
5 changes: 5 additions & 0 deletions lib/nanoc/base/compilation/dependency_tracker.rb
Expand Up @@ -70,6 +70,11 @@ def start
#
# @return [void]
def stop
# Sanity check
if !@stack.empty?
raise "Internal inconsistency: dependency tracker stack not empty at end of compilation"
end

# Unregister
Nanoc::NotificationCenter.remove(:visit_started, self)
Nanoc::NotificationCenter.remove(:visit_ended, self)
Expand Down
34 changes: 34 additions & 0 deletions test/base/test_compiler.rb
Expand Up @@ -556,4 +556,38 @@ def test_tmp_text_items_are_removed_after_compilation
end
end

def test_compiler_dependency_on_unmet_dependency
with_site do
File.open('content/a.html', 'w') do |io|
io.write('<% @items["/b/"].compiled_content %>')
end
File.open('content/b.html', 'w') do |io|
io.write('I am feeling so dependent!')
end
File.open('Rules', 'w') do |io|
io.write "compile '*' do\n"
io.write " filter :erb\n"
io.write "end\n"
io.write "\n"
io.write "route '*' do\n"
io.write " item.identifier.chop + '.' + item[:extension]\n"
io.write "end\n"
io.write "\n"
io.write "layout '*', :erb\n"
end

site = Nanoc::Site.new('.')
rep = site.items['/a/'].reps[0]
dt = site.compiler.dependency_tracker
dt.start
assert_raises Nanoc::Errors::UnmetDependency do
site.compiler.send :compile_rep, rep
end
dt.stop

stack = dt.instance_eval { @stack }
assert_empty stack
end
end

end

0 comments on commit f2c1fd7

Please sign in to comment.