nanoc 3.2.4 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/ChangeLog +3 -0
- data/Gemfile +32 -0
- data/LICENSE +19 -0
- data/NEWS.md +470 -0
- data/README.md +114 -0
- data/Rakefile +14 -0
- data/bin/nanoc +7 -27
- data/bin/nanoc3 +3 -0
- data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
- data/lib/nanoc.rb +41 -0
- data/lib/nanoc/base.rb +49 -0
- data/lib/nanoc/base/compilation/checksum_store.rb +57 -0
- data/lib/nanoc/base/compilation/compiled_content_cache.rb +62 -0
- data/lib/nanoc/base/compilation/compiler.rb +458 -0
- data/lib/nanoc/base/compilation/compiler_dsl.rb +214 -0
- data/lib/nanoc/base/compilation/dependency_tracker.rb +200 -0
- data/lib/nanoc/base/compilation/filter.rb +165 -0
- data/lib/nanoc/base/compilation/item_rep_proxy.rb +103 -0
- data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +102 -0
- data/lib/nanoc/base/compilation/outdatedness_checker.rb +223 -0
- data/lib/nanoc/base/compilation/outdatedness_reasons.rb +46 -0
- data/lib/nanoc/base/compilation/rule.rb +73 -0
- data/lib/nanoc/base/compilation/rule_context.rb +84 -0
- data/lib/nanoc/base/compilation/rule_memory_calculator.rb +40 -0
- data/lib/nanoc/base/compilation/rule_memory_store.rb +53 -0
- data/lib/nanoc/base/compilation/rules_collection.rb +243 -0
- data/lib/nanoc/base/context.rb +47 -0
- data/lib/nanoc/base/core_ext.rb +6 -0
- data/lib/nanoc/base/core_ext/array.rb +62 -0
- data/lib/nanoc/base/core_ext/hash.rb +63 -0
- data/lib/nanoc/base/core_ext/pathname.rb +26 -0
- data/lib/nanoc/base/core_ext/string.rb +46 -0
- data/lib/nanoc/base/directed_graph.rb +275 -0
- data/lib/nanoc/base/errors.rb +211 -0
- data/lib/nanoc/base/memoization.rb +67 -0
- data/lib/nanoc/base/notification_center.rb +84 -0
- data/lib/nanoc/base/ordered_hash.rb +200 -0
- data/lib/nanoc/base/plugin_registry.rb +181 -0
- data/lib/nanoc/base/result_data/item_rep.rb +492 -0
- data/lib/nanoc/base/source_data/code_snippet.rb +58 -0
- data/lib/nanoc/base/source_data/configuration.rb +24 -0
- data/lib/nanoc/base/source_data/data_source.rb +234 -0
- data/lib/nanoc/base/source_data/item.rb +301 -0
- data/lib/nanoc/base/source_data/layout.rb +130 -0
- data/lib/nanoc/base/source_data/site.rb +361 -0
- data/lib/nanoc/base/store.rb +135 -0
- data/lib/nanoc/cli.rb +137 -0
- data/lib/nanoc/cli/command_runner.rb +104 -0
- data/lib/nanoc/cli/commands/autocompile.rb +58 -0
- data/lib/nanoc/cli/commands/compile.rb +297 -0
- data/lib/nanoc/cli/commands/create_item.rb +60 -0
- data/lib/nanoc/cli/commands/create_layout.rb +73 -0
- data/lib/nanoc/cli/commands/create_site.rb +411 -0
- data/lib/nanoc/cli/commands/debug.rb +117 -0
- data/lib/nanoc/cli/commands/deploy.rb +79 -0
- data/lib/nanoc/cli/commands/info.rb +98 -0
- data/lib/nanoc/cli/commands/nanoc.rb +38 -0
- data/lib/nanoc/cli/commands/prune.rb +50 -0
- data/lib/nanoc/cli/commands/update.rb +70 -0
- data/lib/nanoc/cli/commands/view.rb +82 -0
- data/lib/nanoc/cli/commands/watch.rb +124 -0
- data/lib/nanoc/cli/error_handler.rb +199 -0
- data/lib/nanoc/cli/logger.rb +92 -0
- data/lib/nanoc/data_sources.rb +29 -0
- data/lib/nanoc/data_sources/deprecated/delicious.rb +42 -0
- data/lib/nanoc/data_sources/deprecated/last_fm.rb +87 -0
- data/lib/nanoc/data_sources/deprecated/twitter.rb +38 -0
- data/lib/nanoc/data_sources/filesystem.rb +299 -0
- data/lib/nanoc/data_sources/filesystem_unified.rb +121 -0
- data/lib/nanoc/data_sources/filesystem_verbose.rb +91 -0
- data/lib/nanoc/extra.rb +24 -0
- data/lib/nanoc/extra/auto_compiler.rb +103 -0
- data/lib/nanoc/extra/chick.rb +125 -0
- data/lib/nanoc/extra/core_ext.rb +6 -0
- data/lib/nanoc/extra/core_ext/enumerable.rb +33 -0
- data/lib/nanoc/extra/core_ext/pathname.rb +30 -0
- data/lib/nanoc/extra/core_ext/time.rb +19 -0
- data/lib/nanoc/extra/deployer.rb +47 -0
- data/lib/nanoc/extra/deployers.rb +15 -0
- data/lib/nanoc/extra/deployers/fog.rb +98 -0
- data/lib/nanoc/extra/deployers/rsync.rb +70 -0
- data/lib/nanoc/extra/file_proxy.rb +40 -0
- data/lib/nanoc/extra/pruner.rb +86 -0
- data/lib/nanoc/extra/validators.rb +12 -0
- data/lib/nanoc/extra/validators/links.rb +268 -0
- data/lib/nanoc/extra/validators/w3c.rb +95 -0
- data/lib/nanoc/extra/vcs.rb +66 -0
- data/lib/nanoc/extra/vcses.rb +17 -0
- data/lib/nanoc/extra/vcses/bazaar.rb +25 -0
- data/lib/nanoc/extra/vcses/dummy.rb +24 -0
- data/lib/nanoc/extra/vcses/git.rb +25 -0
- data/lib/nanoc/extra/vcses/mercurial.rb +25 -0
- data/lib/nanoc/extra/vcses/subversion.rb +25 -0
- data/lib/nanoc/filters.rb +59 -0
- data/lib/nanoc/filters/asciidoc.rb +38 -0
- data/lib/nanoc/filters/bluecloth.rb +19 -0
- data/lib/nanoc/filters/coderay.rb +21 -0
- data/lib/nanoc/filters/coffeescript.rb +20 -0
- data/lib/nanoc/filters/colorize_syntax.rb +298 -0
- data/lib/nanoc/filters/erb.rb +38 -0
- data/lib/nanoc/filters/erubis.rb +34 -0
- data/lib/nanoc/filters/haml.rb +27 -0
- data/lib/nanoc/filters/kramdown.rb +20 -0
- data/lib/nanoc/filters/less.rb +53 -0
- data/lib/nanoc/filters/markaby.rb +20 -0
- data/lib/nanoc/filters/maruku.rb +20 -0
- data/lib/nanoc/filters/mustache.rb +24 -0
- data/lib/nanoc/filters/rainpress.rb +19 -0
- data/lib/nanoc/filters/rdiscount.rb +22 -0
- data/lib/nanoc/filters/rdoc.rb +33 -0
- data/lib/nanoc/filters/redcarpet.rb +62 -0
- data/lib/nanoc/filters/redcloth.rb +47 -0
- data/lib/nanoc/filters/relativize_paths.rb +94 -0
- data/lib/nanoc/filters/rubypants.rb +20 -0
- data/lib/nanoc/filters/sass.rb +74 -0
- data/lib/nanoc/filters/slim.rb +25 -0
- data/lib/nanoc/filters/typogruby.rb +23 -0
- data/lib/nanoc/filters/uglify_js.rb +42 -0
- data/lib/nanoc/filters/xsl.rb +46 -0
- data/lib/nanoc/filters/yui_compressor.rb +23 -0
- data/lib/nanoc/helpers.rb +16 -0
- data/lib/nanoc/helpers/blogging.rb +319 -0
- data/lib/nanoc/helpers/breadcrumbs.rb +40 -0
- data/lib/nanoc/helpers/capturing.rb +138 -0
- data/lib/nanoc/helpers/filtering.rb +50 -0
- data/lib/nanoc/helpers/html_escape.rb +55 -0
- data/lib/nanoc/helpers/link_to.rb +151 -0
- data/lib/nanoc/helpers/rendering.rb +140 -0
- data/lib/nanoc/helpers/tagging.rb +71 -0
- data/lib/nanoc/helpers/text.rb +44 -0
- data/lib/nanoc/helpers/xml_sitemap.rb +76 -0
- data/lib/nanoc/tasks.rb +10 -0
- data/lib/nanoc/tasks/clean.rake +16 -0
- data/lib/nanoc/tasks/clean.rb +29 -0
- data/lib/nanoc/tasks/deploy/rsync.rake +16 -0
- data/lib/nanoc/tasks/validate.rake +92 -0
- data/nanoc.gemspec +49 -0
- data/tasks/doc.rake +16 -0
- data/tasks/test.rake +46 -0
- data/test/base/core_ext/array_spec.rb +73 -0
- data/test/base/core_ext/hash_spec.rb +98 -0
- data/test/base/core_ext/pathname_spec.rb +27 -0
- data/test/base/core_ext/string_spec.rb +37 -0
- data/test/base/test_checksum_store.rb +35 -0
- data/test/base/test_code_snippet.rb +31 -0
- data/test/base/test_compiler.rb +403 -0
- data/test/base/test_compiler_dsl.rb +161 -0
- data/test/base/test_context.rb +31 -0
- data/test/base/test_data_source.rb +46 -0
- data/test/base/test_dependency_tracker.rb +262 -0
- data/test/base/test_directed_graph.rb +288 -0
- data/test/base/test_filter.rb +83 -0
- data/test/base/test_item.rb +179 -0
- data/test/base/test_item_rep.rb +579 -0
- data/test/base/test_layout.rb +59 -0
- data/test/base/test_memoization.rb +90 -0
- data/test/base/test_notification_center.rb +34 -0
- data/test/base/test_outdatedness_checker.rb +394 -0
- data/test/base/test_plugin.rb +30 -0
- data/test/base/test_rule.rb +19 -0
- data/test/base/test_rule_context.rb +65 -0
- data/test/base/test_site.rb +190 -0
- data/test/cli/commands/test_compile.rb +33 -0
- data/test/cli/commands/test_create_item.rb +14 -0
- data/test/cli/commands/test_create_layout.rb +28 -0
- data/test/cli/commands/test_create_site.rb +24 -0
- data/test/cli/commands/test_deploy.rb +74 -0
- data/test/cli/commands/test_help.rb +12 -0
- data/test/cli/commands/test_info.rb +11 -0
- data/test/cli/commands/test_prune.rb +98 -0
- data/test/cli/commands/test_update.rb +10 -0
- data/test/cli/test_cli.rb +102 -0
- data/test/cli/test_error_handler.rb +29 -0
- data/test/cli/test_logger.rb +10 -0
- data/test/data_sources/test_filesystem.rb +433 -0
- data/test/data_sources/test_filesystem_unified.rb +536 -0
- data/test/data_sources/test_filesystem_verbose.rb +357 -0
- data/test/extra/core_ext/test_enumerable.rb +30 -0
- data/test/extra/core_ext/test_pathname.rb +17 -0
- data/test/extra/core_ext/test_time.rb +15 -0
- data/test/extra/deployers/test_fog.rb +67 -0
- data/test/extra/deployers/test_rsync.rb +100 -0
- data/test/extra/test_auto_compiler.rb +417 -0
- data/test/extra/test_file_proxy.rb +19 -0
- data/test/extra/test_vcs.rb +22 -0
- data/test/extra/validators/test_links.rb +62 -0
- data/test/extra/validators/test_w3c.rb +47 -0
- data/test/filters/test_asciidoc.rb +22 -0
- data/test/filters/test_bluecloth.rb +18 -0
- data/test/filters/test_coderay.rb +44 -0
- data/test/filters/test_coffeescript.rb +18 -0
- data/test/filters/test_colorize_syntax.rb +379 -0
- data/test/filters/test_erb.rb +105 -0
- data/test/filters/test_erubis.rb +78 -0
- data/test/filters/test_haml.rb +96 -0
- data/test/filters/test_kramdown.rb +18 -0
- data/test/filters/test_less.rb +113 -0
- data/test/filters/test_markaby.rb +24 -0
- data/test/filters/test_maruku.rb +18 -0
- data/test/filters/test_mustache.rb +25 -0
- data/test/filters/test_rainpress.rb +29 -0
- data/test/filters/test_rdiscount.rb +31 -0
- data/test/filters/test_rdoc.rb +18 -0
- data/test/filters/test_redcarpet.rb +73 -0
- data/test/filters/test_redcloth.rb +33 -0
- data/test/filters/test_relativize_paths.rb +533 -0
- data/test/filters/test_rubypants.rb +18 -0
- data/test/filters/test_sass.rb +229 -0
- data/test/filters/test_slim.rb +35 -0
- data/test/filters/test_typogruby.rb +21 -0
- data/test/filters/test_uglify_js.rb +30 -0
- data/test/filters/test_xsl.rb +105 -0
- data/test/filters/test_yui_compressor.rb +44 -0
- data/test/gem_loader.rb +11 -0
- data/test/helper.rb +207 -0
- data/test/helpers/test_blogging.rb +754 -0
- data/test/helpers/test_breadcrumbs.rb +81 -0
- data/test/helpers/test_capturing.rb +41 -0
- data/test/helpers/test_filtering.rb +106 -0
- data/test/helpers/test_html_escape.rb +32 -0
- data/test/helpers/test_link_to.rb +249 -0
- data/test/helpers/test_rendering.rb +89 -0
- data/test/helpers/test_tagging.rb +87 -0
- data/test/helpers/test_text.rb +24 -0
- data/test/helpers/test_xml_sitemap.rb +103 -0
- data/test/tasks/test_clean.rb +67 -0
- metadata +327 -15
- data/bin/nanoc-select +0 -86
- data/lib/nanoc-select.rb +0 -11
@@ -0,0 +1,161 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Nanoc::CompilerDSLTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
include Nanoc::TestHelpers
|
6
|
+
|
7
|
+
def test_compile
|
8
|
+
# TODO implement
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_route
|
12
|
+
# TODO implement
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_layout
|
16
|
+
# TODO implement
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_passthrough
|
20
|
+
# Create site
|
21
|
+
Nanoc::CLI.run %w( create_site bar)
|
22
|
+
FileUtils.cd('bar') do
|
23
|
+
# Create rep
|
24
|
+
item = Nanoc::Item.new('foo', { :extension => 'bar' }, '/foo/')
|
25
|
+
rep = Nanoc::ItemRep.new(item, :default)
|
26
|
+
|
27
|
+
# Create other necessary stuff
|
28
|
+
site = Nanoc::Site.new('.')
|
29
|
+
site.items << item
|
30
|
+
compiler = site.compiler
|
31
|
+
dsl = site.compiler.rules_collection.dsl
|
32
|
+
|
33
|
+
# Create rule
|
34
|
+
dsl.passthrough '/foo/'
|
35
|
+
|
36
|
+
# Route and compile
|
37
|
+
rule = compiler.rules_collection.routing_rule_for(rep)
|
38
|
+
path = rule.apply_to(rep, :compiler => compiler)
|
39
|
+
compiler.send :compile_rep, rep
|
40
|
+
|
41
|
+
# Check result
|
42
|
+
assert_equal 'foo', rep.compiled_content
|
43
|
+
assert_equal '/foo.bar', path
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_identifier_to_regex_without_wildcards
|
48
|
+
# Create compiler DSL
|
49
|
+
compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
|
50
|
+
|
51
|
+
actual = compiler_dsl.instance_eval { identifier_to_regex('foo') }
|
52
|
+
expected = %r{^/foo/$}
|
53
|
+
|
54
|
+
assert_equal(expected.to_s, actual.to_s)
|
55
|
+
assert_equal(expected.source, actual.source)
|
56
|
+
assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
|
57
|
+
assert_equal(expected.casefold?, actual.casefold?)
|
58
|
+
assert_equal(expected.options, actual.options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_identifier_to_regex_with_one_wildcard
|
62
|
+
# Create compiler DSL
|
63
|
+
compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
|
64
|
+
|
65
|
+
actual = compiler_dsl.instance_eval { identifier_to_regex('foo/*/bar') }
|
66
|
+
expected = %r{^/foo/(.*?)/bar/$}
|
67
|
+
|
68
|
+
assert_equal(expected.to_s, actual.to_s)
|
69
|
+
assert_equal(expected.source, actual.source)
|
70
|
+
assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
|
71
|
+
assert_equal(expected.casefold?, actual.casefold?)
|
72
|
+
assert_equal(expected.options, actual.options)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_identifier_to_regex_with_two_wildcards
|
76
|
+
# Create compiler DSL
|
77
|
+
compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
|
78
|
+
|
79
|
+
actual = compiler_dsl.instance_eval { identifier_to_regex('foo/*/bar/*/qux') }
|
80
|
+
expected = %r{^/foo/(.*?)/bar/(.*?)/qux/$}
|
81
|
+
|
82
|
+
assert_equal(expected.to_s, actual.to_s)
|
83
|
+
assert_equal(expected.source, actual.source)
|
84
|
+
assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
|
85
|
+
assert_equal(expected.casefold?, actual.casefold?)
|
86
|
+
assert_equal(expected.options, actual.options)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_identifier_to_regex_with_just_one_wildcard
|
90
|
+
# Create compiler DSL
|
91
|
+
compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
|
92
|
+
|
93
|
+
actual = compiler_dsl.instance_eval { identifier_to_regex('*') }
|
94
|
+
expected = %r{^/(.*?)$}
|
95
|
+
|
96
|
+
assert_equal(expected.to_s, actual.to_s)
|
97
|
+
assert_equal(expected.source, actual.source)
|
98
|
+
assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
|
99
|
+
assert_equal(expected.casefold?, actual.casefold?)
|
100
|
+
assert_equal(expected.options, actual.options)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_identifier_to_regex_with_root
|
104
|
+
# Create compiler DSL
|
105
|
+
compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
|
106
|
+
|
107
|
+
actual = compiler_dsl.instance_eval { identifier_to_regex('/') }
|
108
|
+
expected = %r{^/$}
|
109
|
+
|
110
|
+
assert_equal(expected.to_s, actual.to_s)
|
111
|
+
assert_equal(expected.source, actual.source)
|
112
|
+
assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
|
113
|
+
assert_equal(expected.casefold?, actual.casefold?)
|
114
|
+
assert_equal(expected.options, actual.options)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_identifier_to_regex_with_only_children
|
118
|
+
# Create compiler DSL
|
119
|
+
compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
|
120
|
+
|
121
|
+
actual = compiler_dsl.instance_eval { identifier_to_regex('/foo/*/') }
|
122
|
+
expected = %r{^/foo/(.*?)/$}
|
123
|
+
|
124
|
+
assert_equal(expected.to_s, actual.to_s)
|
125
|
+
assert_equal(expected.source, actual.source)
|
126
|
+
assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
|
127
|
+
assert_equal(expected.casefold?, actual.casefold?)
|
128
|
+
assert_equal(expected.options, actual.options)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_identifier_to_regex_with_plus_wildcard
|
132
|
+
# Create compiler DSL
|
133
|
+
compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
|
134
|
+
|
135
|
+
actual = compiler_dsl.instance_eval { identifier_to_regex('/foo/+') }
|
136
|
+
expected = %r{^/foo/(.+?)/$}
|
137
|
+
|
138
|
+
assert_equal(expected.to_s, actual.to_s)
|
139
|
+
assert_equal(expected.source, actual.source)
|
140
|
+
assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
|
141
|
+
assert_equal(expected.casefold?, actual.casefold?)
|
142
|
+
assert_equal(expected.options, actual.options)
|
143
|
+
assert('/foo/bar/' =~ actual)
|
144
|
+
refute('/foo/' =~ actual)
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_dsl_has_no_access_to_compiler
|
148
|
+
compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
|
149
|
+
assert_raises(NameError) do
|
150
|
+
compiler_dsl.instance_eval { compiler }
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_config
|
155
|
+
$venetian = 'unsnares'
|
156
|
+
compiler_dsl = Nanoc::CompilerDSL.new(nil, { :venetian => 'snares' })
|
157
|
+
compiler_dsl.instance_eval { $venetian = @config[:venetian] }
|
158
|
+
assert_equal 'snares', $venetian
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Nanoc::ContextTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
include Nanoc::TestHelpers
|
6
|
+
|
7
|
+
def test_context_with_instance_variable
|
8
|
+
# Create context
|
9
|
+
context = Nanoc::Context.new({ :foo => 'bar', :baz => 'quux' })
|
10
|
+
|
11
|
+
# Ensure correct evaluation
|
12
|
+
assert_equal('bar', eval("@foo", context.get_binding))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_context_with_instance_method
|
16
|
+
# Create context
|
17
|
+
context = Nanoc::Context.new({ :foo => 'bar', :baz => 'quux' })
|
18
|
+
|
19
|
+
# Ensure correct evaluation
|
20
|
+
assert_equal('bar', eval("foo", context.get_binding))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_example
|
24
|
+
# Parse
|
25
|
+
YARD.parse('../lib/nanoc/base/context.rb')
|
26
|
+
|
27
|
+
# Run
|
28
|
+
assert_examples_correct 'Nanoc::Context#initialize'
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Nanoc::DataSourceTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
include Nanoc::TestHelpers
|
6
|
+
|
7
|
+
def test_loading
|
8
|
+
# Create data source
|
9
|
+
data_source = Nanoc::DataSource.new(nil, nil, nil, nil)
|
10
|
+
data_source.expects(:up).times(1)
|
11
|
+
data_source.expects(:down).times(1)
|
12
|
+
|
13
|
+
# Test nested loading
|
14
|
+
assert_equal(0, data_source.instance_eval { @references })
|
15
|
+
data_source.loading do
|
16
|
+
assert_equal(1, data_source.instance_eval { @references })
|
17
|
+
data_source.loading do
|
18
|
+
assert_equal(2, data_source.instance_eval { @references })
|
19
|
+
end
|
20
|
+
assert_equal(1, data_source.instance_eval { @references })
|
21
|
+
end
|
22
|
+
assert_equal(0, data_source.instance_eval { @references })
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_not_implemented
|
26
|
+
# Create data source
|
27
|
+
data_source = Nanoc::DataSource.new(nil, nil, nil, nil)
|
28
|
+
|
29
|
+
# Test optional methods
|
30
|
+
data_source.up
|
31
|
+
data_source.down
|
32
|
+
data_source.update
|
33
|
+
|
34
|
+
# Test required methods - general
|
35
|
+
assert_raises(NotImplementedError) { data_source.setup }
|
36
|
+
|
37
|
+
# Test methods - loading data
|
38
|
+
assert_equal [], data_source.items
|
39
|
+
assert_equal [], data_source.layouts
|
40
|
+
|
41
|
+
# Test required method - creating data
|
42
|
+
assert_raises(NotImplementedError) { data_source.create_item(nil, nil, nil) }
|
43
|
+
assert_raises(NotImplementedError) { data_source.create_layout(nil, nil, nil) }
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,262 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Nanoc::DependencyTrackerTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
include Nanoc::TestHelpers
|
6
|
+
|
7
|
+
def test_initialize
|
8
|
+
# Mock items
|
9
|
+
items = [ mock, mock ]
|
10
|
+
|
11
|
+
# Create
|
12
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
13
|
+
|
14
|
+
# Verify no dependencies yet
|
15
|
+
assert_empty tracker.objects_causing_outdatedness_of(items[0])
|
16
|
+
assert_empty tracker.objects_causing_outdatedness_of(items[1])
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_record_dependency
|
20
|
+
# Mock items
|
21
|
+
items = [ mock, mock ]
|
22
|
+
|
23
|
+
# Create
|
24
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
25
|
+
|
26
|
+
# Record some dependencies
|
27
|
+
tracker.record_dependency(items[0], items[1])
|
28
|
+
|
29
|
+
# Verify dependencies
|
30
|
+
assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_record_dependency_no_self
|
34
|
+
# Mock items
|
35
|
+
items = [ mock, mock ]
|
36
|
+
|
37
|
+
# Create
|
38
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
39
|
+
|
40
|
+
# Record some dependencies
|
41
|
+
tracker.record_dependency(items[0], items[0])
|
42
|
+
tracker.record_dependency(items[0], items[1])
|
43
|
+
|
44
|
+
# Verify dependencies
|
45
|
+
assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_record_dependency_no_doubles
|
49
|
+
# Mock items
|
50
|
+
items = [ mock, mock ]
|
51
|
+
|
52
|
+
# Create
|
53
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
54
|
+
|
55
|
+
# Record some dependencies
|
56
|
+
tracker.record_dependency(items[0], items[1])
|
57
|
+
tracker.record_dependency(items[0], items[1])
|
58
|
+
tracker.record_dependency(items[0], items[1])
|
59
|
+
|
60
|
+
# Verify dependencies
|
61
|
+
assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_objects_causing_outdatedness_of
|
65
|
+
# Mock items
|
66
|
+
items = [ mock, mock, mock ]
|
67
|
+
|
68
|
+
# Create
|
69
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
70
|
+
|
71
|
+
# Record some dependencies
|
72
|
+
tracker.record_dependency(items[0], items[1])
|
73
|
+
tracker.record_dependency(items[1], items[2])
|
74
|
+
|
75
|
+
# Verify dependencies
|
76
|
+
assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_objects_outdated_due_to
|
80
|
+
# Mock items
|
81
|
+
items = [ mock, mock, mock ]
|
82
|
+
|
83
|
+
# Create
|
84
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
85
|
+
|
86
|
+
# Record some dependencies
|
87
|
+
tracker.record_dependency(items[0], items[1])
|
88
|
+
tracker.record_dependency(items[1], items[2])
|
89
|
+
|
90
|
+
# Verify dependencies
|
91
|
+
assert_contains_exactly [ items[0] ], tracker.objects_outdated_due_to(items[1])
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_start_and_stop
|
95
|
+
# Mock items
|
96
|
+
items = [ mock, mock ]
|
97
|
+
|
98
|
+
# Create
|
99
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
100
|
+
|
101
|
+
# Start, do something and stop
|
102
|
+
tracker.start
|
103
|
+
Nanoc::NotificationCenter.post(:visit_started, items[0])
|
104
|
+
Nanoc::NotificationCenter.post(:visit_started, items[1])
|
105
|
+
Nanoc::NotificationCenter.post(:visit_ended, items[1])
|
106
|
+
Nanoc::NotificationCenter.post(:visit_ended, items[0])
|
107
|
+
tracker.stop
|
108
|
+
|
109
|
+
# Verify dependencies
|
110
|
+
assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
|
111
|
+
assert_empty tracker.objects_causing_outdatedness_of(items[1])
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_store_graph_and_load_graph_simple
|
115
|
+
# Mock items
|
116
|
+
items = [ mock('0'), mock('1'), mock('2'), mock('3') ]
|
117
|
+
items.each { |i| i.stubs(:type).returns(:item) }
|
118
|
+
items[0].stubs(:reference).returns([ :item, '/aaa/' ])
|
119
|
+
items[1].stubs(:reference).returns([ :item, '/bbb/' ])
|
120
|
+
items[2].stubs(:reference).returns([ :item, '/ccc/' ])
|
121
|
+
items[3].stubs(:reference).returns([ :item, '/ddd/' ])
|
122
|
+
|
123
|
+
# Create
|
124
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
125
|
+
|
126
|
+
# Record some dependencies
|
127
|
+
tracker.record_dependency(items[0], items[1])
|
128
|
+
tracker.record_dependency(items[1], items[2])
|
129
|
+
tracker.record_dependency(items[1], items[3])
|
130
|
+
|
131
|
+
# Store
|
132
|
+
tracker.store_graph
|
133
|
+
assert File.file?(tracker.filename)
|
134
|
+
|
135
|
+
# Re-create
|
136
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
137
|
+
|
138
|
+
# Load
|
139
|
+
tracker.load_graph
|
140
|
+
|
141
|
+
# Check loaded graph
|
142
|
+
assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
|
143
|
+
assert_contains_exactly [ items[2], items[3] ], tracker.objects_causing_outdatedness_of(items[1])
|
144
|
+
assert_empty tracker.objects_causing_outdatedness_of(items[2])
|
145
|
+
assert_empty tracker.objects_causing_outdatedness_of(items[3])
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_store_graph_and_load_graph_with_removed_items
|
149
|
+
# Mock items
|
150
|
+
items = [ mock('0'), mock('1'), mock('2'), mock('3') ]
|
151
|
+
items.each { |i| i.stubs(:type).returns(:item) }
|
152
|
+
items[0].stubs(:reference).returns([ :item, '/aaa/' ])
|
153
|
+
items[1].stubs(:reference).returns([ :item, '/bbb/' ])
|
154
|
+
items[2].stubs(:reference).returns([ :item, '/ccc/' ])
|
155
|
+
items[3].stubs(:reference).returns([ :item, '/ddd/' ])
|
156
|
+
|
157
|
+
# Create new and old lists
|
158
|
+
old_items = [ items[0], items[1], items[2], items[3] ]
|
159
|
+
new_items = [ items[0], items[1], items[2] ]
|
160
|
+
|
161
|
+
# Create
|
162
|
+
tracker = Nanoc::DependencyTracker.new(old_items)
|
163
|
+
|
164
|
+
# Record some dependencies
|
165
|
+
tracker.record_dependency(old_items[0], old_items[1])
|
166
|
+
tracker.record_dependency(old_items[1], old_items[2])
|
167
|
+
tracker.record_dependency(old_items[1], old_items[3])
|
168
|
+
|
169
|
+
# Store
|
170
|
+
tracker.store_graph
|
171
|
+
assert File.file?(tracker.filename)
|
172
|
+
|
173
|
+
# Re-create
|
174
|
+
tracker = Nanoc::DependencyTracker.new(new_items)
|
175
|
+
|
176
|
+
# Load
|
177
|
+
tracker.load_graph
|
178
|
+
|
179
|
+
# Check loaded graph
|
180
|
+
assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
|
181
|
+
assert_contains_exactly [ items[2], nil ], tracker.objects_causing_outdatedness_of(items[1])
|
182
|
+
assert_empty tracker.objects_causing_outdatedness_of(items[2])
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_store_graph_with_nils_in_dst
|
186
|
+
# Mock items
|
187
|
+
items = [ mock('0'), mock('1'), mock('2') ]
|
188
|
+
items.each { |i| i.stubs(:type).returns(:item) }
|
189
|
+
items[0].stubs(:reference).returns([ :item, '/aaa/' ])
|
190
|
+
items[1].stubs(:reference).returns([ :item, '/bbb/' ])
|
191
|
+
items[2].stubs(:reference).returns([ :item, '/ccc/' ])
|
192
|
+
|
193
|
+
# Create
|
194
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
195
|
+
|
196
|
+
# Record some dependencies
|
197
|
+
tracker.record_dependency(items[0], items[1])
|
198
|
+
tracker.record_dependency(items[1], nil)
|
199
|
+
|
200
|
+
# Store
|
201
|
+
tracker.store_graph
|
202
|
+
assert File.file?(tracker.filename)
|
203
|
+
|
204
|
+
# Re-create
|
205
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
206
|
+
|
207
|
+
# Load
|
208
|
+
tracker.load_graph
|
209
|
+
|
210
|
+
# Check loaded graph
|
211
|
+
assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
|
212
|
+
assert_contains_exactly [ nil ], tracker.objects_causing_outdatedness_of(items[1])
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_store_graph_with_nils_in_src
|
216
|
+
# Mock items
|
217
|
+
items = [ mock('0'), mock('1'), mock('2') ]
|
218
|
+
items.each { |i| i.stubs(:type).returns(:item) }
|
219
|
+
items[0].stubs(:reference).returns([ :item, '/aaa/' ])
|
220
|
+
items[1].stubs(:reference).returns([ :item, '/bbb/' ])
|
221
|
+
items[2].stubs(:reference).returns([ :item, '/ccc/' ])
|
222
|
+
|
223
|
+
# Create
|
224
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
225
|
+
|
226
|
+
# Record some dependencies
|
227
|
+
tracker.record_dependency(items[0], items[1])
|
228
|
+
tracker.record_dependency(nil, items[2])
|
229
|
+
|
230
|
+
# Store
|
231
|
+
tracker.store_graph
|
232
|
+
assert File.file?(tracker.filename)
|
233
|
+
|
234
|
+
# Re-create
|
235
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
236
|
+
|
237
|
+
# Load
|
238
|
+
tracker.load_graph
|
239
|
+
|
240
|
+
# Check loaded graph
|
241
|
+
assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
|
242
|
+
assert_empty tracker.objects_causing_outdatedness_of(items[1])
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_forget_dependencies_for
|
246
|
+
# Mock items
|
247
|
+
items = [ mock, mock, mock ]
|
248
|
+
|
249
|
+
# Create
|
250
|
+
tracker = Nanoc::DependencyTracker.new(items)
|
251
|
+
|
252
|
+
# Record some dependencies
|
253
|
+
tracker.record_dependency(items[0], items[1])
|
254
|
+
tracker.record_dependency(items[1], items[2])
|
255
|
+
assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
|
256
|
+
|
257
|
+
# Forget dependencies
|
258
|
+
tracker.forget_dependencies_for(items[0])
|
259
|
+
assert_empty tracker.objects_causing_outdatedness_of(items[0])
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|