reapack-index 1.0beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/README.md +167 -0
- data/Rakefile +7 -0
- data/bin/reapack-index +8 -0
- data/lib/reapack/index.rb +351 -0
- data/lib/reapack/index/cli.rb +437 -0
- data/lib/reapack/index/gem_version.rb +5 -0
- data/lib/reapack/index/metadata.rb +185 -0
- data/lib/reapack/index/named_node.rb +68 -0
- data/lib/reapack/index/package.rb +65 -0
- data/lib/reapack/index/parsers.rb +35 -0
- data/lib/reapack/index/version.rb +178 -0
- data/reapack-index.gemspec +33 -0
- data/setup/.gitignore +1 -0
- data/setup/reapack-index.nsi +148 -0
- data/test/data/index.xml +11 -0
- data/test/data/noindex.lua +1 -0
- data/test/helper.rb +25 -0
- data/test/test_changelog.rb +76 -0
- data/test/test_cli.rb +846 -0
- data/test/test_index.rb +817 -0
- data/test/test_metadata.rb +403 -0
- data/test/test_named_node.rb +100 -0
- data/test/test_package.rb +95 -0
- data/test/test_parsers.rb +35 -0
- data/test/test_version.rb +215 -0
- metadata +238 -0
data/test/data/index.xml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<index version="1" commit="399f5609cff3e6fd92b5542d444fbf86da0443c6">
|
3
|
+
<category name="Category Name">
|
4
|
+
<reapack name="Hello World.lua" type="script">
|
5
|
+
<version name="1.0" author="cfillion">
|
6
|
+
<changelog><![CDATA[Fixed a division by zero error.]]></changelog>
|
7
|
+
<source platform="all">https://google.com/Category%20Name/Hello%20World.lua</source>
|
8
|
+
</version>
|
9
|
+
</reapack>
|
10
|
+
</category>
|
11
|
+
</index>
|
@@ -0,0 +1 @@
|
|
1
|
+
-- @noindex
|
data/test/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
require 'simplecov'
|
3
|
+
|
4
|
+
Coveralls::Output.silent = true
|
5
|
+
|
6
|
+
SimpleCov.formatters = [
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter,
|
9
|
+
]
|
10
|
+
|
11
|
+
SimpleCov.start {
|
12
|
+
project_name 'reapack-index'
|
13
|
+
add_filter '/test/'
|
14
|
+
}
|
15
|
+
|
16
|
+
require 'reapack/index'
|
17
|
+
require 'minitest/autorun'
|
18
|
+
|
19
|
+
module XMLHelper
|
20
|
+
def make_node(markup)
|
21
|
+
Nokogiri::XML(markup, &:noblanks).root
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
String.disable_colorization = true
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.expand_path '../helper', __FILE__
|
2
|
+
|
3
|
+
class TestChangelog < MiniTest::Test
|
4
|
+
include XMLHelper
|
5
|
+
|
6
|
+
def test_create
|
7
|
+
before = make_node '<source/>'
|
8
|
+
after = <<-XML
|
9
|
+
<source>
|
10
|
+
<changelog><![CDATA[hello]]></changelog>
|
11
|
+
</source>
|
12
|
+
XML
|
13
|
+
|
14
|
+
cl = ReaPack::Index::Changelog.new before
|
15
|
+
assert_empty cl.text
|
16
|
+
assert_equal 0, before.children.size
|
17
|
+
refute cl.modified?, 'changelog modified'
|
18
|
+
|
19
|
+
cl.text = 'hello'
|
20
|
+
assert cl.modified?, 'changelog not modified'
|
21
|
+
assert_equal 'hello', cl.text
|
22
|
+
|
23
|
+
assert_equal after.chomp, before.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_replace
|
27
|
+
before = make_node <<-XML
|
28
|
+
<source>
|
29
|
+
<changelog><![CDATA[hello]]></changelog>
|
30
|
+
</source>
|
31
|
+
XML
|
32
|
+
|
33
|
+
after = <<-XML
|
34
|
+
<source>
|
35
|
+
<changelog><![CDATA[world]]></changelog>
|
36
|
+
</source>
|
37
|
+
XML
|
38
|
+
|
39
|
+
cl = ReaPack::Index::Changelog.new before
|
40
|
+
assert_equal 'hello', cl.text
|
41
|
+
|
42
|
+
cl.text = 'world'
|
43
|
+
assert cl.modified?, 'changelog not modified'
|
44
|
+
|
45
|
+
assert_equal after.chomp, before.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_replace_identical
|
49
|
+
before = make_node <<-XML
|
50
|
+
<source>
|
51
|
+
<changelog><![CDATA[test]]></changelog>
|
52
|
+
</source>
|
53
|
+
XML
|
54
|
+
|
55
|
+
cl = ReaPack::Index::Changelog.new before
|
56
|
+
|
57
|
+
cl.text = 'test'
|
58
|
+
refute cl.modified?, 'changelog is modified'
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_remove
|
62
|
+
before = make_node <<-XML
|
63
|
+
<source>
|
64
|
+
<changelog><![CDATA[hello]]></changelog>
|
65
|
+
</source>
|
66
|
+
XML
|
67
|
+
|
68
|
+
cl = ReaPack::Index::Changelog.new before
|
69
|
+
assert_equal 'hello', cl.text
|
70
|
+
|
71
|
+
cl.text = String.new
|
72
|
+
assert cl.modified?, 'changelog not modified'
|
73
|
+
|
74
|
+
refute_match /changelog/, before.to_s
|
75
|
+
end
|
76
|
+
end
|
data/test/test_cli.rb
ADDED
@@ -0,0 +1,846 @@
|
|
1
|
+
require File.expand_path '../helper', __FILE__
|
2
|
+
|
3
|
+
require 'git'
|
4
|
+
|
5
|
+
module CLIUtils
|
6
|
+
class FakeIO
|
7
|
+
def initialize
|
8
|
+
@getch = 'n'
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :getch
|
12
|
+
end
|
13
|
+
|
14
|
+
def fake_input
|
15
|
+
stdin = $stdin
|
16
|
+
$stdin = FakeIO.new
|
17
|
+
|
18
|
+
yield $stdin
|
19
|
+
ensure
|
20
|
+
$stdin = stdin
|
21
|
+
end
|
22
|
+
|
23
|
+
def wrapper(args = [], options = {})
|
24
|
+
Dir.mktmpdir('test-repository') do |path|
|
25
|
+
@git = Git.init path
|
26
|
+
@git.config('user.name', 'John Doe')
|
27
|
+
@git.config('user.email', 'john@doe.com')
|
28
|
+
|
29
|
+
if options[:remote] != false
|
30
|
+
@git.add_remote 'origin', 'git@github.com:cfillion/test-repository.git'
|
31
|
+
end
|
32
|
+
|
33
|
+
options[:setup].call if options.has_key? :setup
|
34
|
+
|
35
|
+
@indexer = ReaPack::Index::CLI.new \
|
36
|
+
['--no-progress', '--no-commit'] + args + ['--', path]
|
37
|
+
|
38
|
+
yield if block_given?
|
39
|
+
end
|
40
|
+
ensure
|
41
|
+
@git = @indexer = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def mkfile(file, content = String.new)
|
45
|
+
fn = File.join @git.dir.to_s, file
|
46
|
+
FileUtils.mkdir_p File.dirname(fn)
|
47
|
+
File.write fn, content
|
48
|
+
fn
|
49
|
+
end
|
50
|
+
|
51
|
+
def read_index(file = 'index.xml')
|
52
|
+
File.read File.expand_path(file, @git.dir.to_s)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class TestCLI < MiniTest::Test
|
57
|
+
include CLIUtils
|
58
|
+
|
59
|
+
def teardown
|
60
|
+
# who is changing the working directory without restoring it?!
|
61
|
+
Dir.chdir File.dirname(__FILE__)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_help
|
65
|
+
assert_output /--help/, '' do
|
66
|
+
i = ReaPack::Index::CLI.new ['--help']
|
67
|
+
assert_equal true, i.run # does nothing
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_version
|
72
|
+
assert_output /#{Regexp.escape ReaPack::Index::VERSION.to_s}/, '' do
|
73
|
+
i = ReaPack::Index::CLI.new ['--version']
|
74
|
+
assert_equal true, i.run # does nothing
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_invalid_option
|
79
|
+
assert_output '', /reapack-indexer: invalid option: --hello-world/i do
|
80
|
+
i = ReaPack::Index::CLI.new ['--hello-world']
|
81
|
+
assert_equal false, i.run # does nothing
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_empty_branch
|
86
|
+
wrapper do
|
87
|
+
assert_output nil, /the current branch does not contains any commit/i do
|
88
|
+
assert_equal true, @indexer.run
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_initial_commit
|
94
|
+
wrapper do
|
95
|
+
@git.add mkfile('test1.lua', '@version 1.0')
|
96
|
+
@git.add mkfile('Category/test2.lua', '@version 1.0')
|
97
|
+
@git.add mkfile('Category/Sub/test3.lua', '@version 1.0')
|
98
|
+
@git.commit 'initial commit'
|
99
|
+
|
100
|
+
assert_output /3 new packages/, '' do
|
101
|
+
assert_equal true, @indexer.run
|
102
|
+
end
|
103
|
+
|
104
|
+
assert_match 'Category/test2.lua', read_index
|
105
|
+
assert_match "raw/#{@git.log(1).last.sha}/test1.lua", read_index
|
106
|
+
|
107
|
+
assert_match @git.log(1).last.date.utc.iso8601, read_index
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_normal_commit
|
112
|
+
wrapper do
|
113
|
+
@git.add mkfile('README.md', '# Hello World')
|
114
|
+
@git.commit 'initial commit'
|
115
|
+
|
116
|
+
@git.add mkfile('test1.lua', '@version 1.0')
|
117
|
+
@git.add mkfile('Category/test2.lua', '@version 1.0')
|
118
|
+
@git.add mkfile('Category/Sub/test3.lua', '@version 1.0')
|
119
|
+
@git.commit 'second commit'
|
120
|
+
|
121
|
+
assert_output "3 new categories, 3 new packages, 3 new versions\n", '' do
|
122
|
+
assert_equal true, @indexer.run
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_match 'Category/test2.lua', read_index
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_pwd_is_subdirectory
|
130
|
+
wrapper do
|
131
|
+
@git.add mkfile('test1.lua', '@version 1.0')
|
132
|
+
@git.commit 'initial commit'
|
133
|
+
|
134
|
+
pwd = File.join(@git.dir.to_s, 'test')
|
135
|
+
Dir.mkdir pwd
|
136
|
+
Dir.chdir pwd
|
137
|
+
|
138
|
+
assert_output /1 new package/, '' do
|
139
|
+
assert_equal true, @indexer.run
|
140
|
+
end
|
141
|
+
|
142
|
+
assert_match 'test1.lua', read_index
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_verbose
|
147
|
+
stdout, stderr = capture_io do
|
148
|
+
wrapper ['--verbose'] do
|
149
|
+
@git.add mkfile('test.lua', '@version 1.0')
|
150
|
+
@git.add mkfile('test.png')
|
151
|
+
@git.commit 'initial commit'
|
152
|
+
|
153
|
+
assert_equal true, @indexer.run
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
assert_equal "1 new category, 1 new package, 1 new version\n", stdout
|
158
|
+
assert_match /reading configuration from .+\.reapack-index\.conf/i, stderr
|
159
|
+
assert_match /processing [a-f0-9]{7}: initial commit/i, stderr
|
160
|
+
assert_match /indexing new file test.lua/, stderr
|
161
|
+
refute_match /indexing new file test.png/, stderr
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_verbose_override
|
165
|
+
wrapper ['--verbose', '--no-verbose'] do
|
166
|
+
@git.add mkfile('README.md', '# Hello World')
|
167
|
+
@git.commit 'initial commit'
|
168
|
+
|
169
|
+
stdout, stderr = capture_io do
|
170
|
+
assert_equal true, @indexer.run
|
171
|
+
end
|
172
|
+
|
173
|
+
assert_equal "empty index\n", stdout
|
174
|
+
refute_match /processing [a-f0-9]{7}: initial commit/i, stderr
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_invalid_metadata
|
179
|
+
wrapper do
|
180
|
+
@git.add mkfile('test.lua', 'no version tag in this script!')
|
181
|
+
@git.commit 'initial commit'
|
182
|
+
|
183
|
+
assert_output nil, /Warning: test\.lua: Invalid metadata/i do
|
184
|
+
assert_equal true, @indexer.run
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_no_warnings
|
190
|
+
wrapper ['-w'] do
|
191
|
+
@git.add mkfile('test.lua', 'no version tag in this script!')
|
192
|
+
@git.commit 'initial commit'
|
193
|
+
|
194
|
+
stdout, stderr = capture_io do
|
195
|
+
assert_equal true, @indexer.run
|
196
|
+
end
|
197
|
+
|
198
|
+
refute_match /Warning: test\.lua: Invalid metadata/i, stderr
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_no_warnings_override
|
203
|
+
wrapper ['-w', '-W'] do
|
204
|
+
@git.add mkfile('test.lua', 'no version tag in this script!')
|
205
|
+
@git.commit 'initial commit'
|
206
|
+
|
207
|
+
assert_output nil, /Warning: test\.lua: Invalid metadata/i do
|
208
|
+
assert_equal true, @indexer.run
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_index_from_last
|
214
|
+
setup = proc {
|
215
|
+
@git.add mkfile('test1.lua', '@version 1.0')
|
216
|
+
@git.commit 'initial commit'
|
217
|
+
|
218
|
+
mkfile 'index.xml', <<-XML
|
219
|
+
<?xml version="1.0" encoding="utf-8"?>
|
220
|
+
<index version="1" commit="#{@git.log(1).last.sha}"/>
|
221
|
+
XML
|
222
|
+
}
|
223
|
+
|
224
|
+
wrapper [], setup: setup do
|
225
|
+
@git.add mkfile('test2.lua', '@version 1.0')
|
226
|
+
@git.commit 'second commit'
|
227
|
+
|
228
|
+
assert_output nil, '' do
|
229
|
+
assert_equal true, @indexer.run
|
230
|
+
end
|
231
|
+
|
232
|
+
refute_match 'test1.lua', read_index
|
233
|
+
assert_match 'test2.lua', read_index
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_index_from_invalid
|
238
|
+
setup = proc {
|
239
|
+
@git.add mkfile('test1.lua', '@version 1.0')
|
240
|
+
@git.commit 'initial commit'
|
241
|
+
|
242
|
+
mkfile 'index.xml', <<-XML
|
243
|
+
<?xml version="1.0" encoding="utf-8"?>
|
244
|
+
<index version="1" commit="hello world"/>
|
245
|
+
XML
|
246
|
+
}
|
247
|
+
|
248
|
+
wrapper [], setup: setup do
|
249
|
+
@git.add mkfile('test2.lua', '@version 1.0')
|
250
|
+
@git.commit 'second commit'
|
251
|
+
|
252
|
+
assert_output nil, '' do
|
253
|
+
assert_equal true, @indexer.run
|
254
|
+
end
|
255
|
+
|
256
|
+
assert_match 'test1.lua', read_index
|
257
|
+
assert_match 'test2.lua', read_index
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_index_from_invalid
|
262
|
+
setup = proc {
|
263
|
+
@git.add mkfile('test1.lua', '@version 1.0')
|
264
|
+
@git.commit 'initial commit'
|
265
|
+
|
266
|
+
mkfile 'index.xml', <<-XML
|
267
|
+
<?xml version="1.0" encoding="utf-8"?>
|
268
|
+
<index version="1" commit="hello world"/>
|
269
|
+
XML
|
270
|
+
}
|
271
|
+
|
272
|
+
wrapper [], setup: setup do
|
273
|
+
@git.add mkfile('test2.lua', '@version 1.0')
|
274
|
+
@git.commit 'second commit'
|
275
|
+
|
276
|
+
assert_output nil, '' do
|
277
|
+
assert_equal true, @indexer.run
|
278
|
+
end
|
279
|
+
|
280
|
+
assert_match 'test1.lua', read_index
|
281
|
+
assert_match 'test2.lua', read_index
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_index_from_inexistent
|
286
|
+
setup = proc {
|
287
|
+
@git.add mkfile('test.lua', '@version 1.0')
|
288
|
+
@git.commit 'initial commit'
|
289
|
+
|
290
|
+
mkfile 'index.xml', <<-XML
|
291
|
+
<?xml version="1.0" encoding="utf-8"?>
|
292
|
+
<index version="1" commit="0000000000000000000000000000000000000000"/>
|
293
|
+
XML
|
294
|
+
}
|
295
|
+
|
296
|
+
wrapper [], setup: setup do
|
297
|
+
assert_output nil, nil do
|
298
|
+
assert_equal true, @indexer.run
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_index_from_long_hash
|
304
|
+
setup = proc {
|
305
|
+
@git.add mkfile('test.lua', '@version 1.0')
|
306
|
+
@git.commit 'initial commit'
|
307
|
+
|
308
|
+
mkfile 'index.xml', <<-XML
|
309
|
+
<?xml version="1.0" encoding="utf-8"?>
|
310
|
+
<index version="1" commit="0000000000000000000000000000000000000deadbeef"/>
|
311
|
+
XML
|
312
|
+
}
|
313
|
+
|
314
|
+
wrapper [], setup: setup do
|
315
|
+
assert_output nil, nil do
|
316
|
+
assert_equal true, @indexer.run
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_no_amend
|
322
|
+
setup = proc {
|
323
|
+
@git.add mkfile('Test/test.lua', '@version 1.0')
|
324
|
+
@git.commit 'initial commit'
|
325
|
+
|
326
|
+
mkfile 'index.xml', <<-XML
|
327
|
+
<?xml version="1.0" encoding="utf-8"?>
|
328
|
+
<index version="1" commit="#{@git.log(1).last.sha}">
|
329
|
+
<category name="Test">
|
330
|
+
<reapack name="test.lua" type="script">
|
331
|
+
<version name="1.0"/>
|
332
|
+
</reapack>
|
333
|
+
</category>
|
334
|
+
</index>
|
335
|
+
XML
|
336
|
+
}
|
337
|
+
|
338
|
+
wrapper ['--no-amend'], setup: setup do
|
339
|
+
@git.add mkfile('Test/test.lua', "@version 1.0\n@author cfillion")
|
340
|
+
@git.commit 'second commit'
|
341
|
+
|
342
|
+
assert_output '', /nothing to do/i do
|
343
|
+
assert_equal true, @indexer.run
|
344
|
+
end
|
345
|
+
|
346
|
+
refute_match 'cfillion', read_index
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_amend
|
351
|
+
setup = proc {
|
352
|
+
@git.add mkfile('Test/test.lua', '@version 1.0')
|
353
|
+
@git.commit 'initial commit'
|
354
|
+
|
355
|
+
mkfile 'index.xml', <<-XML
|
356
|
+
<?xml version="1.0" encoding="utf-8"?>
|
357
|
+
<index version="1" commit="#{@git.log(1).last.sha}">
|
358
|
+
<category name="Test">
|
359
|
+
<reapack name="test.lua" type="script">
|
360
|
+
<version name="1.0"/>
|
361
|
+
</reapack>
|
362
|
+
</category>
|
363
|
+
</index>
|
364
|
+
XML
|
365
|
+
}
|
366
|
+
|
367
|
+
wrapper ['--amend'], setup: setup do
|
368
|
+
@git.add mkfile('Test/test.lua', "@version 1.0\n@author cfillion")
|
369
|
+
@git.commit 'second commit'
|
370
|
+
|
371
|
+
assert_output /1 modified package/i, '' do
|
372
|
+
assert_equal true, @indexer.run
|
373
|
+
end
|
374
|
+
|
375
|
+
assert_match 'cfillion', read_index
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
def test_remove
|
380
|
+
wrapper do
|
381
|
+
script = mkfile 'test.lua', '@version 1.0'
|
382
|
+
|
383
|
+
@git.add script
|
384
|
+
@git.commit 'initial commit'
|
385
|
+
|
386
|
+
@git.remove script
|
387
|
+
@git.commit 'second commit'
|
388
|
+
|
389
|
+
assert_output /1 removed package/i, '' do
|
390
|
+
assert_equal true, @indexer.run
|
391
|
+
end
|
392
|
+
|
393
|
+
refute_match 'test.lua', read_index
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
def test_output
|
398
|
+
wrapper ['-o output.xml'] do
|
399
|
+
@git.add mkfile('test.lua', '@version 1.0')
|
400
|
+
@git.commit 'initial commit'
|
401
|
+
|
402
|
+
assert_output nil, '' do
|
403
|
+
assert_equal true, @indexer.run
|
404
|
+
end
|
405
|
+
|
406
|
+
assert_match 'test.lua', read_index('output.xml')
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
def test_missing_argument
|
411
|
+
assert_output nil, /missing argument/ do
|
412
|
+
i = ReaPack::Index::CLI.new ['--output']
|
413
|
+
assert_equal false, i.run # does nothing
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_multibyte_filename
|
418
|
+
wrapper do
|
419
|
+
script = mkfile("\342\200\224.lua")
|
420
|
+
|
421
|
+
@git.add script
|
422
|
+
@git.commit 'initial commit'
|
423
|
+
|
424
|
+
@git.remove script
|
425
|
+
@git.commit 'remove test'
|
426
|
+
|
427
|
+
assert_output { @indexer.run }
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
def test_invalid_unicode_sequence
|
432
|
+
wrapper do
|
433
|
+
@git.add mkfile('.gitkeep')
|
434
|
+
@git.commit 'initial commit'
|
435
|
+
|
436
|
+
@git.add mkfile('test.lua', "@version 1.0\n\n\x97")
|
437
|
+
@git.commit 'second commit'
|
438
|
+
|
439
|
+
assert_output { @indexer.run }
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
def test_create_commit
|
444
|
+
wrapper ['--commit'] do
|
445
|
+
@git.add mkfile('.gitkeep')
|
446
|
+
@git.commit 'initial commit'
|
447
|
+
|
448
|
+
assert_output("empty index\n", "commit created\n") { @indexer.run }
|
449
|
+
|
450
|
+
commit = @git.log(1).last
|
451
|
+
assert_equal 'index: empty index', commit.message
|
452
|
+
assert_equal ['index.xml'], commit.diff_parent.map {|d| d.path }
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_create_commit_accept
|
457
|
+
wrapper ['--prompt-commit'] do
|
458
|
+
@git.add mkfile('.gitkeep')
|
459
|
+
@git.commit 'initial commit'
|
460
|
+
|
461
|
+
fake_input do |fio|
|
462
|
+
fio.getch = 'y'
|
463
|
+
stdin, stderr = capture_io { @indexer.run }
|
464
|
+
assert_match /commit created/i, stderr
|
465
|
+
end
|
466
|
+
|
467
|
+
commit = @git.log(1).last
|
468
|
+
assert_equal 'index: empty index', commit.message
|
469
|
+
assert_equal ['index.xml'], commit.diff_parent.map {|d| d.path }
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
def test_create_commit_decline
|
474
|
+
wrapper ['--prompt-commit'] do
|
475
|
+
@git.add mkfile('.gitkeep')
|
476
|
+
@git.commit 'initial commit'
|
477
|
+
|
478
|
+
fake_input do |fio|
|
479
|
+
fio.getch = 'n'
|
480
|
+
stdin, stderr = capture_io { @indexer.run }
|
481
|
+
refute_match /commit created/i, stderr
|
482
|
+
end
|
483
|
+
|
484
|
+
commit = @git.log(1).last
|
485
|
+
refute_equal 'index: empty index', commit.message
|
486
|
+
refute_equal ['index.xml'], commit.diff_parent.map {|d| d.path }
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
def test_config
|
491
|
+
assert_output /--help/, '' do
|
492
|
+
wrapper [], setup: proc {
|
493
|
+
mkfile '.reapack-index.conf', '--help'
|
494
|
+
}
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
def test_no_config
|
499
|
+
stdout, stderr = capture_io do
|
500
|
+
wrapper ['--no-config'], setup: proc {
|
501
|
+
mkfile '.reapack-index.conf', '--help'
|
502
|
+
}
|
503
|
+
end
|
504
|
+
|
505
|
+
refute_match /--help/, stdout
|
506
|
+
end
|
507
|
+
|
508
|
+
def test_config_priority
|
509
|
+
setup = proc {
|
510
|
+
mkfile '.reapack-index.conf', "--verbose\n--no-warnings"
|
511
|
+
}
|
512
|
+
|
513
|
+
stdout, stderr = capture_io do
|
514
|
+
wrapper ['--warnings'], setup: setup do
|
515
|
+
@git.add mkfile('test.lua', 'no version tag in this script!')
|
516
|
+
@git.commit 'initial commit'
|
517
|
+
|
518
|
+
assert_equal true, @indexer.run
|
519
|
+
end
|
520
|
+
end
|
521
|
+
|
522
|
+
assert_match /warning/i, stderr
|
523
|
+
assert_match /verbose/i, stderr
|
524
|
+
end
|
525
|
+
|
526
|
+
def test_config_subdirectory
|
527
|
+
pwd = Dir.pwd
|
528
|
+
|
529
|
+
wrapper do
|
530
|
+
mkfile '.reapack-index.conf', '--help'
|
531
|
+
mkfile 'Category/.gitkeep'
|
532
|
+
|
533
|
+
Dir.chdir File.join(@git.dir.to_s, 'Category')
|
534
|
+
|
535
|
+
assert_output /--help/ do
|
536
|
+
ReaPack::Index::CLI.new
|
537
|
+
end
|
538
|
+
end
|
539
|
+
ensure
|
540
|
+
Dir.chdir pwd
|
541
|
+
end
|
542
|
+
|
543
|
+
def test_working_directory_with_options
|
544
|
+
wrapper do
|
545
|
+
@git.add mkfile('README.md', '# Hello World')
|
546
|
+
@git.commit 'initial commit'
|
547
|
+
|
548
|
+
begin
|
549
|
+
pwd = Dir.pwd
|
550
|
+
Dir.chdir @git.dir.to_s
|
551
|
+
|
552
|
+
assert_output '', '' do
|
553
|
+
i2 = ReaPack::Index::CLI.new ['--no-commit', '--quiet']
|
554
|
+
i2.run
|
555
|
+
end
|
556
|
+
ensure
|
557
|
+
Dir.chdir pwd
|
558
|
+
end
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
def test_no_such_repository
|
563
|
+
assert_output '', /no such file or directory/i do
|
564
|
+
i = ReaPack::Index::CLI.new ['/hello/world']
|
565
|
+
assert_equal false, i.run
|
566
|
+
end
|
567
|
+
|
568
|
+
assert_output '', /could not find repository/i do
|
569
|
+
i = ReaPack::Index::CLI.new ['/']
|
570
|
+
assert_equal false, i.run
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
def test_progress
|
575
|
+
wrapper ['--progress'] do
|
576
|
+
@git.add mkfile('README.md', '# Hello World')
|
577
|
+
@git.commit 'initial commit'
|
578
|
+
|
579
|
+
stdout, stderr = capture_io do
|
580
|
+
assert_equal true, @indexer.run
|
581
|
+
end
|
582
|
+
|
583
|
+
assert_equal "empty index\n", stdout
|
584
|
+
assert_match "\rIndexing commit 1 of 1 (0%)..." \
|
585
|
+
"\rIndexing commit 1 of 1 (100%)...\n", stderr
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
def test_progress_no_new_commit
|
590
|
+
setup = proc {
|
591
|
+
@git.add mkfile('test1.lua', '@version 1.0')
|
592
|
+
@git.commit 'initial commit'
|
593
|
+
|
594
|
+
mkfile 'index.xml', <<-XML
|
595
|
+
<?xml version="1.0" encoding="utf-8"?>
|
596
|
+
<index version="1" commit="#{@git.log(1).last.sha}"/>
|
597
|
+
XML
|
598
|
+
}
|
599
|
+
|
600
|
+
wrapper ['--progress'], setup: setup do
|
601
|
+
assert_output '', "Nothing to do!\n" do
|
602
|
+
@indexer.run
|
603
|
+
end
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
607
|
+
def test_progress_warnings
|
608
|
+
wrapper ['--progress'] do
|
609
|
+
@git.add mkfile('test.lua', 'no version tag in this script!')
|
610
|
+
@git.commit 'initial commit'
|
611
|
+
|
612
|
+
assert_output nil, /\nWarning:/i do
|
613
|
+
assert_equal true, @indexer.run
|
614
|
+
end
|
615
|
+
end
|
616
|
+
end
|
617
|
+
|
618
|
+
def test_quiet_mode
|
619
|
+
wrapper ['--verbose', '--progress', '--quiet'] do
|
620
|
+
@git.add mkfile('test.lua', 'no version tag in this script!')
|
621
|
+
@git.commit 'initial commit'
|
622
|
+
|
623
|
+
assert_output '', '' do
|
624
|
+
assert_equal true, @indexer.run
|
625
|
+
end
|
626
|
+
end
|
627
|
+
end
|
628
|
+
|
629
|
+
def test_website_link
|
630
|
+
wrapper ['-l http://cfillion.tk'] do
|
631
|
+
assert_output "1 new website link, empty index\n", '' do
|
632
|
+
assert_equal true, @indexer.run
|
633
|
+
end
|
634
|
+
|
635
|
+
assert_match 'rel="website">http://cfillion.tk</link>', read_index
|
636
|
+
end
|
637
|
+
end
|
638
|
+
|
639
|
+
def test_website_link
|
640
|
+
wrapper ['--donation-link', 'Link Label=http://cfillion.tk'] do
|
641
|
+
assert_output "1 new donation link, empty index\n" do
|
642
|
+
assert_equal true, @indexer.run
|
643
|
+
end
|
644
|
+
|
645
|
+
assert_match 'rel="donation" href="http://cfillion.tk">Link Label</link>',
|
646
|
+
read_index
|
647
|
+
end
|
648
|
+
end
|
649
|
+
|
650
|
+
def test_invalid_link
|
651
|
+
wrapper ['--link', 'shinsekai yori', '--link', 'http://cfillion.tk'] do
|
652
|
+
assert_output "1 new website link, empty index\n",
|
653
|
+
/warning: invalid url: shinsekai yori/i do
|
654
|
+
assert_equal true, @indexer.run
|
655
|
+
end
|
656
|
+
|
657
|
+
assert_match 'rel="website">http://cfillion.tk</link>', read_index
|
658
|
+
end
|
659
|
+
end
|
660
|
+
|
661
|
+
def test_remove_link
|
662
|
+
wrapper ['--link', 'http://test.com', '--link', '-http://test.com'] do
|
663
|
+
assert_output "1 new website link, 1 removed website link, empty index\n" do
|
664
|
+
assert_equal true, @indexer.run
|
665
|
+
end
|
666
|
+
|
667
|
+
refute_match 'rel="website">http://test.com</link>', read_index
|
668
|
+
end
|
669
|
+
end
|
670
|
+
|
671
|
+
def test_list_links
|
672
|
+
setup = proc {
|
673
|
+
mkfile 'index.xml', <<-XML
|
674
|
+
<?xml version="1.0" encoding="utf-8"?>
|
675
|
+
<index version="1">
|
676
|
+
<metadata>
|
677
|
+
<link rel="website" href="http://anidb.net/a9002">Shinsekai Yori</link>
|
678
|
+
<link rel="donation" href="http://paypal.com">Donate!</link>
|
679
|
+
<link rel="website">http://cfillion.tk</link>
|
680
|
+
XML
|
681
|
+
}
|
682
|
+
|
683
|
+
wrapper ['--ls-links'], setup: setup do
|
684
|
+
stdin, stderr = capture_io do
|
685
|
+
assert_equal true, @indexer.run
|
686
|
+
end
|
687
|
+
|
688
|
+
expected = <<-OUT
|
689
|
+
[website] Shinsekai Yori (http://anidb.net/a9002)
|
690
|
+
[website] http://cfillion.tk
|
691
|
+
[donation] Donate! (http://paypal.com)
|
692
|
+
OUT
|
693
|
+
|
694
|
+
assert_equal expected, stdin
|
695
|
+
assert_empty stderr
|
696
|
+
end
|
697
|
+
end
|
698
|
+
|
699
|
+
def test_no_git_remote
|
700
|
+
wrapper [], remote: false do
|
701
|
+
assert_output { @indexer.run }
|
702
|
+
end
|
703
|
+
end
|
704
|
+
|
705
|
+
def test_about
|
706
|
+
opts = ['--about']
|
707
|
+
|
708
|
+
setup = proc {
|
709
|
+
opts << mkfile('README.md', '# Hello World')
|
710
|
+
}
|
711
|
+
|
712
|
+
wrapper opts, setup: setup do
|
713
|
+
assert_output "1 modified metadata, empty index\n" do
|
714
|
+
assert_equal true, @indexer.run
|
715
|
+
end
|
716
|
+
|
717
|
+
assert_match 'Hello World', read_index
|
718
|
+
end
|
719
|
+
end
|
720
|
+
|
721
|
+
def test_about_file_not_found
|
722
|
+
# 404.md is read in the working directory
|
723
|
+
wrapper ['--about=404.md'] do
|
724
|
+
assert_output "empty index\n",
|
725
|
+
/warning: --about: no such file or directory - 404.md/i do
|
726
|
+
assert_equal true, @indexer.run
|
727
|
+
end
|
728
|
+
end
|
729
|
+
end
|
730
|
+
|
731
|
+
def test_about_pandoc_not_found
|
732
|
+
old_path = ENV['PATH']
|
733
|
+
|
734
|
+
opts = ['--about']
|
735
|
+
|
736
|
+
setup = proc {
|
737
|
+
opts << mkfile('README.md', '# Hello World')
|
738
|
+
}
|
739
|
+
|
740
|
+
wrapper opts, setup: setup do
|
741
|
+
assert_output "empty index\n", /pandoc executable cannot be found/i do
|
742
|
+
ENV['PATH'] = String.new
|
743
|
+
assert_equal true, @indexer.run
|
744
|
+
end
|
745
|
+
end
|
746
|
+
ensure
|
747
|
+
ENV['PATH'] = old_path
|
748
|
+
end
|
749
|
+
|
750
|
+
def test_about_clear
|
751
|
+
setup = proc {
|
752
|
+
mkfile 'index.xml', <<-XML
|
753
|
+
<index>
|
754
|
+
<metadata>
|
755
|
+
<description><![CDATA[Hello World]]></description>
|
756
|
+
</metadata>
|
757
|
+
</index>
|
758
|
+
XML
|
759
|
+
}
|
760
|
+
|
761
|
+
wrapper ['--remove-about'], setup: setup do
|
762
|
+
assert_output "1 modified metadata\n" do
|
763
|
+
assert_equal true, @indexer.run
|
764
|
+
end
|
765
|
+
|
766
|
+
refute_match 'Hello World', read_index
|
767
|
+
end
|
768
|
+
end
|
769
|
+
|
770
|
+
def test_about_dump
|
771
|
+
setup = proc {
|
772
|
+
mkfile 'index.xml', <<-XML
|
773
|
+
<index>
|
774
|
+
<metadata>
|
775
|
+
<description><![CDATA[Hello World]]></description>
|
776
|
+
</metadata>
|
777
|
+
</index>
|
778
|
+
XML
|
779
|
+
}
|
780
|
+
|
781
|
+
wrapper ['--dump-about'], setup: setup do
|
782
|
+
assert_output 'Hello World' do
|
783
|
+
assert_equal true, @indexer.run
|
784
|
+
end
|
785
|
+
end
|
786
|
+
end
|
787
|
+
|
788
|
+
def test_check_pass
|
789
|
+
expected = <<-STDERR
|
790
|
+
..
|
791
|
+
|
792
|
+
Finished checks for 2 packages with 0 failures
|
793
|
+
STDERR
|
794
|
+
|
795
|
+
wrapper ['--check'] do
|
796
|
+
mkfile 'test1.lua', '@version 1.0'
|
797
|
+
mkfile 'test2.lua', '@version 1.0'
|
798
|
+
|
799
|
+
assert_output nil, expected do
|
800
|
+
assert_equal true, @indexer.run
|
801
|
+
end
|
802
|
+
end
|
803
|
+
end
|
804
|
+
|
805
|
+
def test_check_failure
|
806
|
+
expected = <<-STDERR
|
807
|
+
F.
|
808
|
+
|
809
|
+
test1.lua contains invalid metadata:
|
810
|
+
- missing tag "version"
|
811
|
+
- invalid value for tag "author"
|
812
|
+
|
813
|
+
Finished checks for 2 packages with 1 failure
|
814
|
+
STDERR
|
815
|
+
|
816
|
+
wrapper ['--check'] do
|
817
|
+
mkfile 'test1.lua', '@author'
|
818
|
+
mkfile 'test2.lua', '@version 1.0'
|
819
|
+
|
820
|
+
assert_output nil, expected do
|
821
|
+
assert_equal false, @indexer.run
|
822
|
+
end
|
823
|
+
end
|
824
|
+
end
|
825
|
+
|
826
|
+
def test_check_quiet
|
827
|
+
expected = <<-STDERR
|
828
|
+
test1.lua contains invalid metadata:
|
829
|
+
- missing tag "version"
|
830
|
+
- invalid value for tag "author"
|
831
|
+
|
832
|
+
test2.lua contains invalid metadata:
|
833
|
+
- missing tag "version"
|
834
|
+
STDERR
|
835
|
+
|
836
|
+
wrapper ['--check', '--quiet'] do
|
837
|
+
mkfile 'test1.lua', '@author'
|
838
|
+
mkfile 'test2.lua'
|
839
|
+
mkfile 'test3.lua', '@version 1.0'
|
840
|
+
|
841
|
+
assert_output nil, expected do
|
842
|
+
assert_equal false, @indexer.run
|
843
|
+
end
|
844
|
+
end
|
845
|
+
end
|
846
|
+
end
|