reapack-index 1.0beta4 → 1.0rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/reapack/index.rb +31 -130
- data/lib/reapack/index/cdetector.rb +33 -19
- data/lib/reapack/index/cli.rb +12 -6
- data/lib/reapack/index/cli/options.rb +7 -1
- data/lib/reapack/index/gem_version.rb +1 -1
- data/lib/reapack/index/git.rb +5 -1
- data/lib/reapack/index/provides.rb +8 -4
- data/lib/reapack/index/scanner.rb +129 -0
- data/lib/reapack/index/source.rb +9 -3
- data/lib/reapack/index/version.rb +1 -1
- data/reapack-index.gemspec +2 -1
- data/setup/reapack-index.nsi +15 -2
- data/test/cli/test_check.rb +25 -19
- data/test/cli/test_scan.rb +59 -1
- data/test/data/index.xml +5 -2
- data/test/index/test_provides.rb +64 -10
- data/test/index/test_scan.rb +24 -84
- data/test/test_cdetector.rb +121 -72
- data/test/test_cli.rb +6 -0
- data/test/test_git.rb +6 -0
- data/test/test_index.rb +89 -57
- data/test/test_provides.rb +21 -10
- data/test/test_scanner.rb +191 -0
- data/test/test_source.rb +37 -8
- data/test/test_version.rb +3 -4
- metadata +21 -6
- data/test/data/noindex.lua +0 -1
data/test/test_cli.rb
CHANGED
@@ -280,5 +280,11 @@ class TestCLI < MiniTest::Test
|
|
280
280
|
assert_match /finished checks/i, stderr
|
281
281
|
assert_raises(Errno::ENOENT) { read_index }
|
282
282
|
end
|
283
|
+
|
284
|
+
wrapper ['--check', '--rebuild'] do
|
285
|
+
_, stderr = capture_io { @cli.run }
|
286
|
+
refute_match /finished checks/i, stderr
|
287
|
+
read_index # index exists
|
288
|
+
end
|
283
289
|
end
|
284
290
|
end
|
data/test/test_git.rb
CHANGED
@@ -31,6 +31,10 @@ class TestGit < MiniTest::Test
|
|
31
31
|
assert_match "https://github.com/User/Repo/raw/$commit/$path",
|
32
32
|
@git.guess_url_template
|
33
33
|
|
34
|
+
@repo.remotes.set_url 'origin', 'https://github.com/User/Repo'
|
35
|
+
assert_match "https://github.com/User/Repo/raw/$commit/$path",
|
36
|
+
@git.guess_url_template
|
37
|
+
|
34
38
|
@repo.remotes.set_url 'origin', 'scp://weird/url'
|
35
39
|
assert_nil @git.guess_url_template
|
36
40
|
end
|
@@ -100,6 +104,7 @@ class TestGit < MiniTest::Test
|
|
100
104
|
|
101
105
|
def test_commits_since
|
102
106
|
assert_equal [], @git.commits_since(nil)
|
107
|
+
assert_equal [], @git.commits
|
103
108
|
c1 = @git.create_commit 'first', []
|
104
109
|
|
105
110
|
assert_equal [c1], @git.commits_since(nil)
|
@@ -107,6 +112,7 @@ class TestGit < MiniTest::Test
|
|
107
112
|
|
108
113
|
c2 = @git.create_commit 'second', []
|
109
114
|
assert_equal [c1, c2], @git.commits_since(nil)
|
115
|
+
assert_equal [c1, c2], @git.commits
|
110
116
|
assert_equal [c2], @git.commits_since(c1.id)
|
111
117
|
|
112
118
|
INVALID_HASHES.each {|hash|
|
data/test/test_index.rb
CHANGED
@@ -56,6 +56,9 @@ class TestIndex < MiniTest::Test
|
|
56
56
|
assert_match "missing $path placeholder in 'test'", error.message
|
57
57
|
assert_equal 'https://google.com/$path', index.url_template
|
58
58
|
|
59
|
+
index.url_template = 'https://google.com/sp ace/$path'
|
60
|
+
assert_equal 'https://google.com/sp ace/$path', index.url_template
|
61
|
+
|
59
62
|
index.url_template = nil
|
60
63
|
assert_nil index.url_template
|
61
64
|
end
|
@@ -82,7 +85,7 @@ class TestIndex < MiniTest::Test
|
|
82
85
|
index = ReaPack::Index.new @real_path
|
83
86
|
|
84
87
|
assert_equal 1, index.version
|
85
|
-
assert_equal 'f572d396fae9206628714fb2ce00f72e94f2258f', index.
|
88
|
+
assert_equal 'f572d396fae9206628714fb2ce00f72e94f2258f', index.last_commit
|
86
89
|
end
|
87
90
|
|
88
91
|
def test_read_invalid
|
@@ -117,7 +120,7 @@ class TestIndex < MiniTest::Test
|
|
117
120
|
index = ReaPack::Index.new @real_path
|
118
121
|
|
119
122
|
index.write @dummy_path
|
120
|
-
assert_equal File.read(@real_path), File.
|
123
|
+
assert_equal File.read(@real_path), File.binread(@dummy_path)
|
121
124
|
end
|
122
125
|
|
123
126
|
def test_mkdir
|
@@ -134,55 +137,7 @@ class TestIndex < MiniTest::Test
|
|
134
137
|
FileUtils.rm_r dirname if File.exist? dirname
|
135
138
|
end
|
136
139
|
|
137
|
-
def
|
138
|
-
index = ReaPack::Index.new @dummy_path
|
139
|
-
index.files = ['Category/script.lua']
|
140
|
-
index.url_template = 'http://host/$commit/$path'
|
141
|
-
index.commit = nil
|
142
|
-
|
143
|
-
assert_match 'http://host/master/Category/script.lua',
|
144
|
-
index.make_url('Category/script.lua')
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_make_url_without_template
|
148
|
-
index = ReaPack::Index.new @dummy_path
|
149
|
-
index.files = ['script.lua']
|
150
|
-
|
151
|
-
assert_equal nil, index.url_template
|
152
|
-
index.make_url 'script.lua', 'ok if explicit template'
|
153
|
-
|
154
|
-
error = assert_raises ReaPack::Index::Error do
|
155
|
-
index.make_url 'script.lua'
|
156
|
-
end
|
157
|
-
|
158
|
-
assert_match /url template/i, error.message
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_make_url_commit
|
162
|
-
index = ReaPack::Index.new @dummy_path
|
163
|
-
index.files = ['Category/script.lua']
|
164
|
-
index.url_template = 'http://host/$commit/$path'
|
165
|
-
index.commit = @commit
|
166
|
-
|
167
|
-
assert_equal "http://host/#{@commit}/Category/script.lua",
|
168
|
-
index.make_url('Category/script.lua')
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_make_url_unlisted
|
172
|
-
index = ReaPack::Index.new @dummy_path
|
173
|
-
index.commit = @commit
|
174
|
-
index.url_template = 'http://google.com/$path'
|
175
|
-
|
176
|
-
index.make_url 'unlisted.lua', 'ok with url template'
|
177
|
-
|
178
|
-
error = assert_raises ReaPack::Index::Error do
|
179
|
-
index.make_url 'unlisted.lua'
|
180
|
-
end
|
181
|
-
|
182
|
-
assert_equal "file not found 'unlisted.lua'", error.message
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_reset_index_after_error
|
140
|
+
def test_reset_after_error
|
186
141
|
index = ReaPack::Index.new @dummy_path
|
187
142
|
index.commit = @commit
|
188
143
|
index.url_template = 'http://host/$path'
|
@@ -207,13 +162,22 @@ class TestIndex < MiniTest::Test
|
|
207
162
|
assert_equal true, index.modified?
|
208
163
|
assert_equal '1 removed package', index.changelog
|
209
164
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
165
|
+
index.write @dummy_path
|
166
|
+
contents = File.read @dummy_path
|
167
|
+
|
168
|
+
assert_match @commit, contents
|
169
|
+
refute_match '<category', contents
|
170
|
+
end
|
214
171
|
|
172
|
+
def test_retain_last_commit
|
173
|
+
index = ReaPack::Index.new @real_path
|
174
|
+
assert_nil index.commit
|
175
|
+
|
176
|
+
index.remove 'Category Name/Hello World.lua'
|
215
177
|
index.write @dummy_path
|
216
|
-
|
178
|
+
|
179
|
+
refute_nil index.last_commit
|
180
|
+
assert_match index.last_commit, File.read(@dummy_path)
|
217
181
|
end
|
218
182
|
|
219
183
|
def test_remove_inexistant
|
@@ -252,13 +216,14 @@ class TestIndex < MiniTest::Test
|
|
252
216
|
<index>
|
253
217
|
<category name="zebra"/>
|
254
218
|
<category name="bee"/>
|
219
|
+
<category name="Cat"/>
|
255
220
|
</index>
|
256
221
|
XML
|
257
222
|
|
258
223
|
index = ReaPack::Index.new @dummy_path
|
259
224
|
index.write!
|
260
225
|
|
261
|
-
assert_match /bee.+zebra/m, File.read(index.path)
|
226
|
+
assert_match /bee.+Cat.+zebra/m, File.read(index.path)
|
262
227
|
end
|
263
228
|
|
264
229
|
def test_sort_packages
|
@@ -296,4 +261,71 @@ class TestIndex < MiniTest::Test
|
|
296
261
|
|
297
262
|
assert_equal original, File.read(index.path)
|
298
263
|
end
|
264
|
+
|
265
|
+
def test_dont_mess_with_link_ordering
|
266
|
+
# https://bugs.ruby-lang.org/issues/11907
|
267
|
+
original = <<-XML
|
268
|
+
<?xml version="1.0" encoding="utf-8"?>
|
269
|
+
<index version="1">
|
270
|
+
<metadata>
|
271
|
+
<link>1</link>
|
272
|
+
<link>2</link>
|
273
|
+
<link>3</link>
|
274
|
+
<link>4</link>
|
275
|
+
<link>5</link>
|
276
|
+
<link>6</link>
|
277
|
+
<description><![CDATA[
|
278
|
+
]]></description>
|
279
|
+
</metadata>
|
280
|
+
</index>
|
281
|
+
XML
|
282
|
+
|
283
|
+
File.write @dummy_path, original
|
284
|
+
index = ReaPack::Index.new @dummy_path
|
285
|
+
assert_output '' do
|
286
|
+
index.write!
|
287
|
+
end
|
288
|
+
|
289
|
+
expected = original.sub /(<link.+?)(\s+?)(<description.+?<\/description>)/m, "\\3\\2\\1"
|
290
|
+
assert_equal expected, File.read(index.path)
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_clear
|
294
|
+
index = ReaPack::Index.new @real_path
|
295
|
+
index.commit = @commit
|
296
|
+
|
297
|
+
index.clear
|
298
|
+
|
299
|
+
index.write @dummy_path
|
300
|
+
contents = File.read @dummy_path
|
301
|
+
|
302
|
+
refute_match @commit, contents
|
303
|
+
refute_match '<category', contents
|
304
|
+
assert_match 'name="Test"', contents
|
305
|
+
assert_match '<description', contents
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_clear_reset_cdetector
|
309
|
+
index = ReaPack::Index.new @real_path
|
310
|
+
index.commit = @commit
|
311
|
+
index.files = ['Category Name/test.lua', 'Category Name/Hello World.lua']
|
312
|
+
index.url_template = 'http://host/$path'
|
313
|
+
|
314
|
+
index.clear
|
315
|
+
|
316
|
+
# no error because of fake conflict:
|
317
|
+
index.scan index.files.first, "@version 1.0\n@provides Hello World.lua"
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_move_no_conflicts
|
321
|
+
index = ReaPack::Index.new @dummy_path
|
322
|
+
index.files = ['cat/testz.lua', 'cat/testa.lua', 'cat/file1', 'cat/file2']
|
323
|
+
index.url_template = 'http://host/$path'
|
324
|
+
|
325
|
+
contents = "@version 1.0\n@provides\n\tfile1\n\t[effect] file2"
|
326
|
+
|
327
|
+
index.scan 'cat/testz.lua', contents
|
328
|
+
index.remove 'cat/testz.lua'
|
329
|
+
index.scan 'cat/testa.lua', contents
|
330
|
+
end
|
299
331
|
end
|
data/test/test_provides.rb
CHANGED
@@ -42,12 +42,6 @@ class TestProvides < MiniTest::Test
|
|
42
42
|
' [ darwin32 ] file',
|
43
43
|
'[win32, darwin64] file',
|
44
44
|
].map {|l| ReaPack::Index::Provides.parse(l).platform }
|
45
|
-
|
46
|
-
error = assert_raises ReaPack::Index::Error do
|
47
|
-
ReaPack::Index::Provides.parse '[HeLlO] file'
|
48
|
-
end
|
49
|
-
|
50
|
-
assert_equal "unknown option (platform or type) 'HeLlO'", error.message
|
51
45
|
end
|
52
46
|
|
53
47
|
def test_types
|
@@ -59,10 +53,27 @@ class TestProvides < MiniTest::Test
|
|
59
53
|
'[,windows,,] file',
|
60
54
|
].map {|l| ReaPack::Index::Provides.parse(l).type }
|
61
55
|
|
62
|
-
|
63
|
-
ReaPack::Index::Provides.parse '[, Test] file'
|
64
|
-
end
|
56
|
+
end
|
65
57
|
|
66
|
-
|
58
|
+
def test_main
|
59
|
+
assert_equal [true, false, nil, false],
|
60
|
+
[
|
61
|
+
'[main] file',
|
62
|
+
'[nomain] file',
|
63
|
+
'file',
|
64
|
+
'[main, nomain] file',
|
65
|
+
].map {|l| ReaPack::Index::Provides.parse(l).main? }
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_invalid_options
|
69
|
+
assert_equal ["unknown option 'HeLlO'", "unknown option 'Test'"],
|
70
|
+
[
|
71
|
+
'[HeLlO] file',
|
72
|
+
'[, Test] file',
|
73
|
+
].map {|l|
|
74
|
+
assert_raises ReaPack::Index::Error do
|
75
|
+
ReaPack::Index::Provides.parse l
|
76
|
+
end.message
|
77
|
+
}
|
67
78
|
end
|
68
79
|
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require File.expand_path '../helper', __FILE__
|
2
|
+
|
3
|
+
class TestScanner < MiniTest::Test
|
4
|
+
class TestMakeUrl < MiniTest::Test
|
5
|
+
def setup
|
6
|
+
@cat = MiniTest::Mock.new
|
7
|
+
|
8
|
+
@pkg = MiniTest::Mock.new
|
9
|
+
@pkg.expect :type, :script
|
10
|
+
@pkg.expect :path, 'Hello/World.lua'
|
11
|
+
@pkg.expect :path, 'Hello/World.lua'
|
12
|
+
|
13
|
+
@ver = MiniTest::Mock.new
|
14
|
+
@ver.expect :name, '1.0'
|
15
|
+
|
16
|
+
@mh = MiniTest::Mock.new
|
17
|
+
@mh.expect :[], nil, [:metapackage]
|
18
|
+
|
19
|
+
@cdetector = MiniTest::Mock.new
|
20
|
+
@cdetector.expect :[], nil, ['Hello/World.lua']
|
21
|
+
|
22
|
+
@index = MiniTest::Mock.new
|
23
|
+
@index.expect :cdetector, @cdetector
|
24
|
+
|
25
|
+
@scanner = ReaPack::Index::Scanner.new @cat, @pkg, @mh, @index
|
26
|
+
@scanner.instance_variable_set :@ver, @ver
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
[@cat, @pkg, @ver, @mh, @index, @cdetector].each {|mock| mock.verify }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_path
|
34
|
+
@index.expect :files, ['Category/script.lua']
|
35
|
+
@index.expect :url_template, '$path'
|
36
|
+
@index.expect :commit, 'C0FF33'
|
37
|
+
|
38
|
+
assert_equal 'Category/script.lua', @scanner.make_url('Category/script.lua')
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_commit
|
42
|
+
@index.expect :files, ['Hello/World.lua']
|
43
|
+
@index.expect :url_template, '$commit'
|
44
|
+
@index.expect :commit, 'C0FF33'
|
45
|
+
|
46
|
+
assert_equal 'C0FF33', @scanner.make_url('Hello/World.lua')
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_defaut_branch
|
50
|
+
@index.expect :commit, nil
|
51
|
+
|
52
|
+
assert_match 'master', @scanner.make_url('Category/script.lua', '$commit')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_version
|
56
|
+
@index.expect :files, ['Category/script.lua']
|
57
|
+
@index.expect :url_template, '$version'
|
58
|
+
@index.expect :commit, 'C0FF33'
|
59
|
+
|
60
|
+
assert_equal '1.0', @scanner.make_url('Category/script.lua')
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_package
|
64
|
+
@index.expect :files, ['Category/script.lua']
|
65
|
+
@index.expect :url_template, '$package'
|
66
|
+
@index.expect :commit, 'C0FF33'
|
67
|
+
|
68
|
+
assert_equal 'Hello/World.lua', @scanner.make_url('Category/script.lua')
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_without_template
|
72
|
+
@index.expect :commit, nil
|
73
|
+
@scanner.make_url 'script.lua', 'ok if explicit template'
|
74
|
+
|
75
|
+
@index.expect :url_template, nil
|
76
|
+
error = assert_raises ReaPack::Index::Error do
|
77
|
+
@scanner.make_url 'script.lua'
|
78
|
+
end
|
79
|
+
|
80
|
+
assert_match /url template/i, error.message
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_unlisted
|
84
|
+
@index.expect :commit, nil
|
85
|
+
@index.expect :files, []
|
86
|
+
@index.expect :url_template, 'http://implicit/url/template'
|
87
|
+
|
88
|
+
@scanner.make_url 'unlisted.lua', 'ok with explicit url template'
|
89
|
+
|
90
|
+
error = assert_raises ReaPack::Index::Error do
|
91
|
+
@scanner.make_url 'unlisted.lua'
|
92
|
+
end
|
93
|
+
|
94
|
+
assert_equal "file not found 'unlisted.lua'", error.message
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_repeat
|
98
|
+
@index.expect :files, ['Category/script.lua']
|
99
|
+
@index.expect :url_template, '$path $path'
|
100
|
+
@index.expect :commit, 'C0FF33'
|
101
|
+
|
102
|
+
assert_equal 'Category/script.lua Category/script.lua',
|
103
|
+
@scanner.make_url('Category/script.lua')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class TestValidation < MiniTest::Test
|
108
|
+
def setup
|
109
|
+
@pkg = MiniTest::Mock.new
|
110
|
+
@pkg.expect :type, :script
|
111
|
+
@pkg.expect :path, 'cat/test'
|
112
|
+
|
113
|
+
@mh = MetaHeader.new String.new
|
114
|
+
@mh[:version] = '1.0'
|
115
|
+
|
116
|
+
@index = MiniTest::Mock.new
|
117
|
+
@index.expect :cdetector, ReaPack::Index::ConflictDetector.new
|
118
|
+
|
119
|
+
@scanner = ReaPack::Index::Scanner.new nil, @pkg, @mh, @index
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_validation
|
123
|
+
mh_mock = MiniTest::Mock.new
|
124
|
+
mh_mock.expect :validate, ['first', 'second'], [Hash]
|
125
|
+
|
126
|
+
@scanner.instance_variable_set :@mh, mh_mock
|
127
|
+
|
128
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
129
|
+
|
130
|
+
assert_equal "first\nsecond", error.message
|
131
|
+
mh_mock.verify
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_version
|
135
|
+
@mh.delete :version
|
136
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
137
|
+
assert_equal "missing tag 'version'", error.message
|
138
|
+
|
139
|
+
@mh[:version] = 'no.numbers'
|
140
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
141
|
+
assert_equal "invalid value for tag 'version'", error.message
|
142
|
+
|
143
|
+
@mh[:version] = true
|
144
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
145
|
+
assert_equal "missing value for tag 'version'", error.message
|
146
|
+
|
147
|
+
@mh[:version] = "hello\nworld"
|
148
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
149
|
+
assert_equal "tag 'version' must be singleline", error.message
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_author
|
153
|
+
@mh[:author] = true
|
154
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
155
|
+
assert_equal "missing value for tag 'author'", error.message
|
156
|
+
|
157
|
+
@mh[:author] = "hello\nworld"
|
158
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
159
|
+
assert_equal "tag 'author' must be singleline", error.message
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_changelog
|
163
|
+
@mh[:changelog] = true
|
164
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
165
|
+
assert_equal "missing value for tag 'changelog'", error.message
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_provides
|
169
|
+
@mh[:provides] = true
|
170
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
171
|
+
assert_equal "missing value for tag 'provides'", error.message
|
172
|
+
|
173
|
+
@mh[:provides] = '[hello] world'
|
174
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
175
|
+
assert_equal "invalid value for tag 'provides': unknown option 'hello'",
|
176
|
+
error.message
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_index
|
180
|
+
@mh[:noindex] = 'value'
|
181
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
182
|
+
assert_equal "tag 'noindex' cannot have a value", error.message
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_metapackage
|
186
|
+
@mh[:metapackage] = 'value'
|
187
|
+
error = assert_raises(ReaPack::Index::Error) { @scanner.run }
|
188
|
+
assert_equal "tag 'metapackage' cannot have a value", error.message
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|