reapack-index 1.0beta3 → 1.0beta4

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.
@@ -0,0 +1,302 @@
1
+ require File.expand_path '../../helper', __FILE__
2
+
3
+ TestIndex ||= Class.new MiniTest::Test
4
+
5
+ class TestIndex::Provides < MiniTest::Test
6
+ include IndexHelper
7
+
8
+ def test_simple
9
+ index = ReaPack::Index.new @dummy_path
10
+ index.url_template = 'http://host/$path'
11
+
12
+ index.files = [
13
+ 'Category/script.lua',
14
+ 'Resources/unicode.dat',
15
+ 'Category/test.png',
16
+ ]
17
+
18
+ index.scan index.files.first, <<-IN
19
+ @version 1.0
20
+ @provides
21
+ [windows] ../Resources/unicode.dat
22
+ test.png
23
+ IN
24
+
25
+ expected = <<-XML
26
+ <?xml version="1.0" encoding="utf-8"?>
27
+ <index version="1">
28
+ <category name="Category">
29
+ <reapack name="script.lua" type="script">
30
+ <version name="1.0">
31
+ <source platform="all">http://host/Category/script.lua</source>
32
+ <source platform="windows" file="../Resources/unicode.dat">http://host/Resources/unicode.dat</source>
33
+ <source platform="all" file="test.png">http://host/Category/test.png</source>
34
+ </version>
35
+ </reapack>
36
+ </category>
37
+ </index>
38
+ XML
39
+
40
+ index.write!
41
+ assert_equal expected, File.read(index.path)
42
+ end
43
+
44
+ def test_not_found
45
+ index = ReaPack::Index.new @dummy_path
46
+ index.url_template = 'http://host/$path'
47
+ index.files = ['Category/script.lua']
48
+
49
+ error = assert_raises ReaPack::Index::Error do
50
+ index.scan index.files.first, <<-IN
51
+ @version 1.0
52
+ @provides
53
+ test.png
54
+ IN
55
+ end
56
+
57
+ assert_equal "file not found 'test.png'", error.message
58
+ end
59
+
60
+ def test_mainfile_platform
61
+ index = ReaPack::Index.new @dummy_path
62
+ index.url_template = 'http://host/$path'
63
+ index.files = ['Category/script.lua']
64
+
65
+ index.scan index.files.first, <<-IN
66
+ @version 1.0
67
+ @provides
68
+ [darwin] .
69
+ [win64] script.lua
70
+ IN
71
+
72
+ expected = <<-XML
73
+ <?xml version="1.0" encoding="utf-8"?>
74
+ <index version="1">
75
+ <category name="Category">
76
+ <reapack name="script.lua" type="script">
77
+ <version name="1.0">
78
+ <source platform="darwin">http://host/Category/script.lua</source>
79
+ <source platform="win64">http://host/Category/script.lua</source>
80
+ </version>
81
+ </reapack>
82
+ </category>
83
+ </index>
84
+ XML
85
+
86
+ index.write!
87
+ assert_equal expected, File.read(index.path)
88
+ end
89
+
90
+ def test_invalid_options
91
+ index = ReaPack::Index.new @dummy_path
92
+ index.url_template = 'http://host/$path'
93
+
94
+ error = assert_raises ReaPack::Index::Error do
95
+ index.scan 'cat/test.lua', <<-IN
96
+ @version 1.0
97
+ @provides
98
+ [hello] test.png
99
+ IN
100
+ end
101
+ end
102
+
103
+ def test_custom_url
104
+ index = ReaPack::Index.new @dummy_path
105
+ index.files = ['Category/script.lua']
106
+
107
+ index.scan index.files.first, <<-IN
108
+ @version 1.0
109
+ @provides
110
+ script.lua http://google.com/download/$commit/$version/$path
111
+ IN
112
+
113
+ index.write!
114
+ assert_match 'http://google.com/download/master/1.0/Category/script.lua',
115
+ File.read(index.path)
116
+ end
117
+
118
+ def test_empty_tag
119
+ index = ReaPack::Index.new @dummy_path
120
+ index.url_template = 'http://host/$path'
121
+ index.files = ['Category/hello.lua']
122
+
123
+ error = assert_raises ReaPack::Index::Error do
124
+ index.scan index.files.first, <<-IN
125
+ @version 1.0
126
+ @provides
127
+ IN
128
+ end
129
+ end
130
+
131
+ def test_glob
132
+ index = ReaPack::Index.new @dummy_path
133
+ index.url_template = 'http://host/$path'
134
+ index.files = [
135
+ 'Category/script.lua',
136
+ 'Category/Data/a.dat',
137
+ 'Category/Data/b.dat',
138
+ 'Category/test.txt',
139
+ 'Category/test/d.dat', # should not be matched by test*
140
+ ]
141
+
142
+ index.scan index.files.first, <<-IN
143
+ @version 1.0
144
+ @provides
145
+ [windows] Data/*
146
+ test*
147
+ IN
148
+
149
+ expected = <<-XML
150
+ <?xml version="1.0" encoding="utf-8"?>
151
+ <index version="1">
152
+ <category name="Category">
153
+ <reapack name="script.lua" type="script">
154
+ <version name="1.0">
155
+ <source platform="all">http://host/Category/script.lua</source>
156
+ <source platform="windows" file="Data/a.dat">http://host/Category/Data/a.dat</source>
157
+ <source platform="windows" file="Data/b.dat">http://host/Category/Data/b.dat</source>
158
+ <source platform="all" file="test.txt">http://host/Category/test.txt</source>
159
+ </version>
160
+ </reapack>
161
+ </category>
162
+ </index>
163
+ XML
164
+
165
+ index.write!
166
+ assert_equal expected, File.read(index.path)
167
+ end
168
+
169
+ def test_duplicate
170
+ index = ReaPack::Index.new @dummy_path
171
+ index.url_template = 'http://host/$path'
172
+ index.files = ['cat/script.lua', 'cat/test.png']
173
+
174
+ error = assert_raises ReaPack::Index::Error do
175
+ index.scan index.files.first, <<-IN
176
+ @version 1.0
177
+ @provides
178
+ test.png
179
+ test.png http://url.com
180
+ IN
181
+ end
182
+
183
+ assert_equal "duplicate file 'cat/test.png'", error.message
184
+ end
185
+
186
+ def test_conflicts
187
+ index = ReaPack::Index.new @dummy_path
188
+ index.url_template = 'http://host/$path'
189
+ index.files = ['cat/script1.lua', 'cat/script2.lua', 'cat/script3.lua',
190
+ 'cat/file1', 'cat/file2']
191
+
192
+ index.scan index.files[0], <<-IN
193
+ @version 1.0
194
+ @provides file1
195
+ IN
196
+
197
+ error = assert_raises ReaPack::Index::Error do
198
+ index.scan index.files[1], <<-IN
199
+ @version 1.0
200
+ @provides
201
+ file1
202
+ file2
203
+ IN
204
+ end
205
+
206
+ assert_equal "'cat/file1' conflicts with 'cat/script1.lua'",
207
+ error.message
208
+
209
+ # did script2.lua did leave any trace behind?
210
+ index.scan index.files[2], <<-IN
211
+ @version 1.0
212
+ @provides file2
213
+ IN
214
+ end
215
+
216
+ def test_duplicate_other_package
217
+ index = ReaPack::Index.new @dummy_path
218
+ index.url_template = 'http://host/$path'
219
+ index.files = ['cat/script1.lua', 'cat/script2.lua']
220
+
221
+ index.scan index.files.first, <<-IN
222
+ @version 1.0
223
+ IN
224
+
225
+ error = assert_raises ReaPack::Index::Error do
226
+ index.scan index.files.last, <<-IN
227
+ @version 1.0
228
+ @provides script1.lua
229
+ IN
230
+ end
231
+
232
+ assert_equal "'cat/script1.lua' conflicts with 'cat/script1.lua'",
233
+ error.message
234
+ end
235
+
236
+ def test_duplicate_cross_directory
237
+ index = ReaPack::Index.new @dummy_path
238
+ index.url_template = 'http://host/$path'
239
+ index.files = ['Category1/script1.lua', 'Category2/script2.lua',
240
+ 'Category1/file']
241
+
242
+ index.scan index.files[0], <<-IN
243
+ @version 1.0
244
+ @provides file
245
+ IN
246
+
247
+ error = assert_raises ReaPack::Index::Error do
248
+ index.scan index.files[1], <<-IN
249
+ @version 1.0
250
+ @provides ../Category1/file
251
+ IN
252
+ end
253
+
254
+ assert_equal "'Category1/file' conflicts with 'Category1/script1.lua'",
255
+ error.message
256
+ end
257
+
258
+ def test_conflict_with_existing
259
+ File.write @dummy_path, <<-XML
260
+ <?xml version="1.0" encoding="utf-8"?>
261
+ <index version="1">
262
+ <category name="Other">
263
+ <reapack name="test1.lua" type="script">
264
+ <version name="1.0">
265
+ <source platform="all" file="background.png">http://irrelevant</source>
266
+ </version>
267
+ </reapack>
268
+ </category>
269
+ </index>
270
+ XML
271
+
272
+ index = ReaPack::Index.new @dummy_path
273
+ index.url_template = 'http://host/$path'
274
+ index.files = ['Other/test2.lua', 'Other/background.png']
275
+
276
+ error = assert_raises ReaPack::Index::Error do
277
+ index.scan index.files.first, <<-IN
278
+ @version 1.0
279
+ @provides background.png
280
+ IN
281
+ end
282
+
283
+ assert_equal "'Other/background.png' conflicts with 'Other/test1.lua'",
284
+ error.message
285
+ end
286
+
287
+ def test_same_file_cross_type
288
+ index = ReaPack::Index.new @dummy_path
289
+ index.url_template = 'http://host/$path'
290
+ index.files = ['script.lua', 'file', 'effect.jsfx']
291
+
292
+ index.scan index.files.first, <<-IN
293
+ @version 1.0
294
+ @provides file
295
+ IN
296
+
297
+ index.scan index.files.last, <<-IN
298
+ @version 1.0
299
+ @provides file
300
+ IN
301
+ end
302
+ end
@@ -0,0 +1,333 @@
1
+ require File.expand_path '../../helper', __FILE__
2
+
3
+ TestIndex ||= Class.new MiniTest::Test
4
+
5
+ class TestIndex::Scan < MiniTest::Test
6
+ include IndexHelper
7
+
8
+ def test_ignore_unknown_type
9
+ index = ReaPack::Index.new @dummy_path
10
+
11
+ index.scan 'src/main.cpp', String.new
12
+ index.write!
13
+
14
+ expected = <<-XML
15
+ <?xml version="1.0" encoding="utf-8"?>
16
+ <index version="1"/>
17
+ XML
18
+
19
+ assert_equal expected, File.read(index.path)
20
+ end
21
+
22
+ def test_new_package
23
+ index = ReaPack::Index.new @dummy_path
24
+ index.files = ['Category/Path/Instrument Track.lua']
25
+ index.url_template = 'http://host/$path'
26
+
27
+ index.scan index.files.first, <<-IN
28
+ @version 1.0
29
+ @changelog Hello World
30
+ IN
31
+
32
+ assert_equal true, index.modified?
33
+ assert_equal '1 new category, 1 new package, 1 new version', index.changelog
34
+
35
+ index.write!
36
+
37
+ assert_equal false, index.modified?
38
+ assert_empty index.changelog
39
+
40
+ expected = <<-XML
41
+ <?xml version="1.0" encoding="utf-8"?>
42
+ <index version="1">
43
+ <category name="Category/Path">
44
+ <reapack name="Instrument Track.lua" type="script">
45
+ <version name="1.0">
46
+ <changelog><![CDATA[Hello World]]></changelog>
47
+ <source platform="all">http://host/Category/Path/Instrument%20Track.lua</source>
48
+ </version>
49
+ </reapack>
50
+ </category>
51
+ </index>
52
+ XML
53
+
54
+ assert_equal expected, File.read(index.path)
55
+ end
56
+
57
+ def test_package_in_root
58
+ index = ReaPack::Index.new @dummy_path
59
+ index.files = ['script.lua', 'Hello/World']
60
+ index.url_template = 'http://host/$path'
61
+
62
+ index.scan index.files.first, <<-IN
63
+ @version 1.0
64
+ @provides Hello/World
65
+ IN
66
+
67
+ index.write!
68
+ refute_match '<reapack', File.read(index.path)
69
+ end
70
+
71
+ def test_edit_version_amend_off
72
+ index = ReaPack::Index.new @real_path
73
+ assert_equal false, index.amend
74
+
75
+ index.url_template = 'http://google.com/$path'
76
+ index.files = ['Category Name/Hello World.lua']
77
+
78
+ index.scan index.files.first, <<-IN
79
+ @version 1.0
80
+ @changelog New Changelog!
81
+ IN
82
+
83
+ assert_equal false, index.modified?
84
+ assert_empty index.changelog
85
+ end
86
+
87
+ def test_edit_version_amend_on
88
+ index = ReaPack::Index.new @real_path
89
+ index.commit = @commit
90
+ index.files = ['Category Name/Hello World.lua']
91
+ index.time = Time.now # must not be added to the index in amend mode
92
+ index.url_template = 'http://google.com/$path'
93
+
94
+ index.amend = true
95
+ assert_equal true, index.amend
96
+
97
+ index.scan index.files.first, <<-IN
98
+ @version 1.0
99
+ @changelog Intermediate Changelog!
100
+ IN
101
+
102
+ # when reindexing the same file a second time,
103
+ # the changelog is expected to only have been bumped a single time
104
+ index.scan index.files.first, <<-IN
105
+ @version 1.0
106
+ @changelog New Changelog!
107
+ IN
108
+
109
+ assert index.modified?, 'index is not modified'
110
+ assert_equal '1 modified package, 1 modified version', index.changelog
111
+
112
+ expected = <<-XML
113
+ <?xml version="1.0" encoding="utf-8"?>
114
+ <index version="1" commit="#{@commit}">
115
+ <category name="Category Name">
116
+ <reapack name="Hello World.lua" type="script">
117
+ <version name="1.0">
118
+ <changelog><![CDATA[New Changelog!]]></changelog>
119
+ <source platform="all">http://google.com/Category%20Name/Hello%20World.lua</source>
120
+ </version>
121
+ </reapack>
122
+ </category>
123
+ </index>
124
+ XML
125
+
126
+ index.write @dummy_path
127
+ assert_equal expected, File.read(@dummy_path)
128
+ end
129
+
130
+ def test_edit_version_amend_unmodified
131
+ index = ReaPack::Index.new @real_path
132
+ index.amend = true
133
+
134
+ index.url_template = 'https://google.com/$path'
135
+ index.files = ['Category Name/Hello World.lua']
136
+
137
+ index.scan index.files.first, <<-IN
138
+ @version 1.0
139
+ @author cfillion
140
+ @changelog Fixed a division by zero error.
141
+ IN
142
+
143
+ assert_equal false, index.modified?
144
+ assert_empty index.changelog
145
+ end
146
+
147
+ def test_missing_version
148
+ index = ReaPack::Index.new @dummy_path
149
+ index.url_template = 'http://host/$path'
150
+ index.files = ['cat/test.lua']
151
+
152
+ error = assert_raises ReaPack::Index::Error do
153
+ index.scan index.files.first, 'no version tag here'
154
+ end
155
+
156
+ assert_equal "missing tag 'version'", error.message
157
+ end
158
+
159
+ def test_empty_changelog
160
+ index = ReaPack::Index.new @dummy_path
161
+ index.url_template = 'http://host/$path'
162
+ index.files = ['cat/test.lua']
163
+
164
+ error = assert_raises ReaPack::Index::Error do
165
+ index.scan index.files.first, <<-IN
166
+ @version 1.0
167
+ @changelog
168
+ IN
169
+ end
170
+
171
+ assert_equal "missing value for tag 'changelog'", error.message
172
+ end
173
+
174
+ def test_author
175
+ index = ReaPack::Index.new @dummy_path
176
+ index.url_template = 'http://host/$path'
177
+ index.files = ['Category/script.lua']
178
+
179
+ index.scan index.files.first, <<-IN
180
+ @version 1.0
181
+ @author cfillion
182
+ IN
183
+
184
+ index.write!
185
+ assert_match '<version name="1.0" author="cfillion">', File.read(index.path)
186
+ end
187
+
188
+ def test_author_boolean
189
+ index = ReaPack::Index.new @dummy_path
190
+ index.url_template = 'http://host/$path'
191
+ index.files = ['cat/test.lua']
192
+
193
+ error = assert_raises ReaPack::Index::Error do
194
+ index.scan index.files.first, <<-IN
195
+ @version 1.0
196
+ @author
197
+ IN
198
+ end
199
+
200
+ assert_equal "missing value for tag 'author'", error.message
201
+ end
202
+
203
+ def test_author_multiline
204
+ index = ReaPack::Index.new @dummy_path
205
+ index.url_template = 'http://host/$path'
206
+ index.files = ['cat/test.lua']
207
+
208
+ error = assert_raises ReaPack::Index::Error do
209
+ index.scan index.files.first, <<-IN
210
+ @version 1.0
211
+ @author
212
+ hello
213
+ world
214
+ IN
215
+ end
216
+
217
+ assert_equal "tag 'author' must be singleline", error.message
218
+ end
219
+
220
+ def test_noindex
221
+ index = ReaPack::Index.new @real_path
222
+
223
+ index.scan 'script.lua', '@noindex'
224
+
225
+ assert_equal false, index.modified?
226
+ end
227
+
228
+ def test_noindex_autoremove
229
+ index = ReaPack::Index.new @real_path
230
+ index.commit = @commit
231
+
232
+ index.scan 'Category Name/Hello World.lua', '@noindex'
233
+
234
+ assert_equal true, index.modified?
235
+ assert_equal '1 removed package', index.changelog
236
+
237
+ expected = <<-XML
238
+ <?xml version="1.0" encoding="utf-8"?>
239
+ <index version="1" commit="#{@commit}"/>
240
+ XML
241
+
242
+ index.write @dummy_path
243
+ assert_equal expected, File.read(@dummy_path)
244
+ end
245
+
246
+ def test_version_time
247
+ index = ReaPack::Index.new @dummy_path
248
+ index.url_template = 'http://host/$path'
249
+ index.files = ['Category/script.lua']
250
+ index.time = Time.new 2016, 2, 11, 20, 16, 40, -5 * 3600
251
+
252
+ index.scan index.files.first, '@version 1.0'
253
+
254
+ index.write!
255
+ assert_match '<version name="1.0" time="2016-02-12T01:16:40Z">',
256
+ File.read(index.path)
257
+ end
258
+
259
+ def test_extension
260
+ index = ReaPack::Index.new @dummy_path
261
+ index.files = ['Extensions/reapack.ext']
262
+
263
+ index.scan index.files.first, <<-IN
264
+ @version 1.0
265
+ @provides
266
+ reaper_reapack.so http://example.com/$path
267
+ IN
268
+
269
+ expected = <<-XML
270
+ <?xml version="1.0" encoding="utf-8"?>
271
+ <index version="1">
272
+ <category name="Extensions">
273
+ <reapack name="reapack.ext" type="extension">
274
+ <version name="1.0">
275
+ <source platform="all" file="reaper_reapack.so">http://example.com/reaper_reapack.so</source>
276
+ </version>
277
+ </reapack>
278
+ </category>
279
+ </index>
280
+ XML
281
+
282
+ index.write!
283
+ assert_equal expected, File.read(index.path)
284
+ end
285
+
286
+ def test_effect
287
+ index = ReaPack::Index.new @dummy_path
288
+ index.url_template = 'http://host/$path'
289
+ index.files = ['Dynamics/super_compressor.jsfx']
290
+
291
+ index.scan index.files.first, '@version 1.0'
292
+
293
+ expected = <<-XML
294
+ <?xml version="1.0" encoding="utf-8"?>
295
+ <index version="1">
296
+ <category name="Dynamics">
297
+ <reapack name="super_compressor.jsfx" type="effect">
298
+ <version name="1.0">
299
+ <source platform="all">http://host/Dynamics/super_compressor.jsfx</source>
300
+ </version>
301
+ </reapack>
302
+ </category>
303
+ </index>
304
+ XML
305
+
306
+ index.write!
307
+ assert_equal expected, File.read(index.path)
308
+ end
309
+
310
+ def test_data
311
+ index = ReaPack::Index.new @dummy_path
312
+ index.url_template = 'http://host/$path'
313
+ index.files = ['Grooves/sws.data', 'Grooves/sws/test.mid']
314
+
315
+ index.scan index.files.first, "@version 1.0\n@provides sws/*.mid"
316
+
317
+ expected = <<-XML
318
+ <?xml version="1.0" encoding="utf-8"?>
319
+ <index version="1">
320
+ <category name="Grooves">
321
+ <reapack name="sws.data" type="data">
322
+ <version name="1.0">
323
+ <source platform="all" file="sws/test.mid">http://host/Grooves/sws/test.mid</source>
324
+ </version>
325
+ </reapack>
326
+ </category>
327
+ </index>
328
+ XML
329
+
330
+ index.write!
331
+ assert_equal expected, File.read(index.path)
332
+ end
333
+ end