File: gemspec_artifacts_spec.rb

package info (click to toggle)
ruby-jar-dependencies 0.5.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,172 kB
  • sloc: ruby: 2,407; sh: 137; xml: 117; java: 20; makefile: 9
file content (238 lines) | stat: -rw-r--r-- 9,341 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# frozen_string_literal: true

require File.expand_path('setup', File.dirname(__FILE__))

require 'jars/gemspec_artifacts'

describe Jars::GemspecArtifacts::Exclusion do
  it 'parse and to_s of exclusion' do
    expected = 'group:artifact'
    line = ' group:artifact '
    ex = Jars::GemspecArtifacts::Exclusion.new(line)
    _(ex.to_s).must_equal expected
    line = ' "group:artifact" '
    ex = Jars::GemspecArtifacts::Exclusion.new(line)
    _(ex.to_s).must_equal expected
    line = "'group:artifact'"
    ex = Jars::GemspecArtifacts::Exclusion.new(line)
    _(ex.to_s).must_equal expected
    line = ' group:artifact '
    ex = Jars::GemspecArtifacts::Exclusion.new("#{line} :extra:asd")
    _(ex.to_s).must_equal expected
  end
end

describe Jars::GemspecArtifacts::Exclusions do
  it 'parse and to_s of single exclusion' do
    expected = '[group:artifact]'
    line = ' [group:artifact] '
    ex = Jars::GemspecArtifacts::Exclusions.new(line)
    _(ex.to_s).must_equal expected
    line = " [' group:artifact'] "
    ex = Jars::GemspecArtifacts::Exclusions.new(line)
    _(ex.to_s).must_equal expected
    line = ' [ "group:artifact "] '
    ex = Jars::GemspecArtifacts::Exclusions.new(line)
    _(ex.to_s).must_equal expected
    expected = '[group-id:artifact-id]'
    line = ' [ "group-id:artifact-id "] '
    ex = Jars::GemspecArtifacts::Exclusions.new(line)
    _(ex.to_s).must_equal expected
  end

  it 'parse and to_s of list of exclusions' do
    expected = '[group1:artifact1, group2:artifact2]'
    line = ' [group1:artifact1, group2:artifact2] '
    ex = Jars::GemspecArtifacts::Exclusions.new(line)
    _(ex.to_s).must_equal expected
    line = " ['group1:artifact1', ' group2:artifact2'] "
    ex = Jars::GemspecArtifacts::Exclusions.new(line)
    _(ex.to_s).must_equal expected
    line = ' [ "group1:artifact1", " group2:artifact2"] '
    ex = Jars::GemspecArtifacts::Exclusions.new(line)
    _(ex.to_s).must_equal expected
  end
end

describe Jars::GemspecArtifacts::Artifact do
  it 'ignore unknow type' do
    _(Jars::GemspecArtifacts::Artifact.new('bla')).must_be_nil
    _(Jars::GemspecArtifacts::Artifact.new(' _(bla')).must_be_nil
    _(Jars::GemspecArtifacts::Artifact.new('bla bla _(bla')).must_be_nil
  end

  %i[jar pom].each do |type|
    it "parse and to_s of simple GAV #{type}" do
      expected = "#{type} g:a, 1"
      a = Jars::GemspecArtifacts::Artifact.new(expected)
      _(a.to_s).must_equal expected
      line = "#{type} 'g:a', '1'"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} g,a,1"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} 'g',\"a\", 1"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} g:a:1"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} 'g:a:1'"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
    end

    it "parse and to_s of simple GAV #{type} with range" do
      expected = "#{type} g:a, [1, 2)"
      a = Jars::GemspecArtifacts::Artifact.new(expected)
      _(a.to_s).must_equal expected
      line = "#{type} g:a:[1, 2)"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} g:a,'[1, 2)'"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} 'g', \"a\", ' [1, 2) '"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
    end

    it "parse and to_s of simple GAV #{type} with one exclusion" do
      expected = "#{type} g:a, 1, [a:b]"
      a = Jars::GemspecArtifacts::Artifact.new(expected)
      _(a.to_s).must_equal expected
      line = "#{type} 'g:a', '1', '[a:b]'"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} 'g:a', '1', ['a:b']"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} g,a,1,[a:b]"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
    end

    it "parse and to_s of simple GAV #{type} with exclusions" do
      expected = "#{type} g:a, 1, [a:b, c:d]"
      a = Jars::GemspecArtifacts::Artifact.new(expected)
      _(a.to_s).must_equal expected
      line = "#{type} 'g:a', '1', ['a:b', 'c:d']'"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} g,a,1,[a:b,c:d]"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
    end

    it "parse and to_s of simple GAV #{type} with exclusions and range" do
      expected = "#{type} g:a, (1, 2], [a:b, c:d]"
      a = Jars::GemspecArtifacts::Artifact.new(expected)
      _(a.to_s).must_equal expected
      line = "#{type} 'g:a', '(1,2]', ['a:b', 'c:d']'"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} g,a,(1,2],[a:b,c:d]"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} g,a,(1,2],  :exclusions : [a:b,c:d]"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
    end

    it "parse and to_s of simple GACV #{type}" do
      expected = "#{type} g:a, c, 1"
      a = Jars::GemspecArtifacts::Artifact.new(expected)
      _(a.to_s).must_equal expected
      line = "#{type} 'g:a', 'c', '1'"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} g,a,\"c\",1"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type}  g,a, 1  ,:classifier : c"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
    end

    it "parse and to_s of simple GACV #{type} with range" do
      expected = "#{type} g:a, c, [1, 2)"
      a = Jars::GemspecArtifacts::Artifact.new(expected)
      _(a.to_s).must_equal expected
      _(a.scope).must_be_nil
      line = "#{type} g:a:c:[1, 2),:scope=>:runtime"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      _(a.scope).must_equal 'runtime'
      line = "#{type} g:a:c,'[1, 2)'"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type} 'g', \"a\", 'c', ' [1, 2) '"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      line = "#{type}  g,a,[1,  2),:classifier => c"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
    end

    it "parse and to_s of simple GACV #{type} with exclusions and range" do
      expected = "#{type} g:a, c, (1, 2], [a:b, c:d]"
      a = Jars::GemspecArtifacts::Artifact.new(expected)
      _(a.to_s).must_equal expected
      _(a.scope).must_be_nil
      line = "#{type} 'g:a:c', '(1,2]', ['a:b', 'c:d']'"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      _(a.scope).must_be_nil
      line = "#{type} g,a,c,(1,2],[a:b,c:d], :scope => :compile"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
      _(a.scope).must_equal 'compile'
      line = "#{type}  g,a,(1,2],:classifier => c,:exclusions => [a:b,c:d]"
      a = Jars::GemspecArtifacts::Artifact.new(line)
      _(a.to_s).must_equal expected
    end
  end
end

describe Jars::GemspecArtifacts do
  let(:pwd) { File.dirname(File.expand_path(__FILE__)) }

  let(:example_spec) { File.join(pwd, '..', 'example', 'example.gemspec') }

  it 'retrieves artifacts from gemspec' do
    spec = Dir.chdir(File.dirname(example_spec)) do
      eval(File.read(example_spec)) # rubocop:disable Security/Eval
    end
    artifacts = Jars::GemspecArtifacts.new(spec)
    _(artifacts[0].to_s).must_equal('jar org.bouncycastle:bcpkix-jdk15on, 1.49')
    _(artifacts[1].to_s).must_equal('jar org.bouncycastle:bcprov-jdk15on, 1.49')
    _(artifacts[3].to_s).must_equal('jar io.dropwizard:dropwizard-logging, 0.8.0-rc5, [joda-time:joda-time]')
    _(artifacts[4].to_s).must_equal('jar com.google.protobuf:protobuf-java, lite, 2.2.0')
    _(artifacts[5].to_s).must_equal('jar junit:junit, 4.12')
    _(artifacts[0].scope).must_be_nil
    _(artifacts[1].scope).must_be_nil
    _(artifacts[2].scope).must_be_nil
    _(artifacts[3].scope).must_be_nil
    _(artifacts[4].scope).must_be_nil
    _(artifacts[5].scope).must_equal('test')
    _(artifacts[0].classifier).must_be_nil
    _(artifacts[1].classifier).must_be_nil
    _(artifacts[2].classifier).must_be_nil
    _(artifacts[3].classifier).must_be_nil
    _(artifacts[4].classifier).must_equal('lite')
    _(artifacts[5].classifier).must_be_nil
    _(artifacts[0].exclusions).must_be_nil
    _(artifacts[1].exclusions).must_be_nil
    _(artifacts[2].exclusions).must_be_nil
    _(artifacts[3].exclusions.to_s).must_equal('[joda-time:joda-time]')
    _(artifacts[4].exclusions).must_be_nil
    _(artifacts[5].exclusions).must_be_nil

    artifacts.each do |a|
      _(a.to_s).must_equal Jars::GemspecArtifacts::Artifact.new(a.to_s).to_s
    end

    _(artifacts.size).must_equal 7
  end
end