/
config_spec.rb
226 lines (184 loc) · 7.8 KB
/
config_spec.rb
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
require File.expand_path('../spec_helper', __FILE__)
describe Xcodeproj::Config do
describe "In general" do
extend SpecHelper::TemporaryDirectory
before do
@hash = { 'OTHER_LDFLAGS' => '-framework Foundation' }
@config = Xcodeproj::Config.new(@hash)
@config_fixture = fixture_path('oneline-key-value.xcconfig')
end
it "can be created with hash" do
config = Xcodeproj::Config.new(@hash)
config.should.be.equal @hash
end
it "can be created with file path" do
config = Xcodeproj::Config.new(@config_fixture)
config.should.be.equal @hash
end
it "can be created with File instance" do
xcconfig_file = File.new(@config_fixture)
xcconfig = Xcodeproj::Config.new(xcconfig_file)
xcconfig.should.be.equal @hash
end
it "does not modifies the hash used for initialization" do
original = @hash.dup
config = Xcodeproj::Config.new(@hash)
@hash.should.be.equal original
end
it "parses the frameworks and the libraries" do
hash = { 'OTHER_LDFLAGS' => '-framework Foundation -weak_framework Twitter -lxml2.2.7.3' }
config = Xcodeproj::Config.new(hash)
config.frameworks.to_a.should.be.equal %w[ Foundation ]
config.weak_frameworks.to_a.should.be.equal %w[ Twitter ]
config.libraries.to_a.should.be.equal %w[ xml2.2.7.3 ]
end
it "doesn't parse a libraries flags containing the -library substring" do
hash = { 'OTHER_LDFLAGS' => '-finalize -prefinalized-library"' }
config = Xcodeproj::Config.new(hash)
config.libraries.to_a.should == []
config.to_hash.should == hash
end
it "can handle libraries specified as a separate argument" do
# see http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
hash = { 'OTHER_LDFLAGS' => '-framework Foundation -l xml2.2.7.3' }
config = Xcodeproj::Config.new(hash)
config.libraries.to_a.should.be.equal %w[ xml2.2.7.3 ]
end
it "can be serialized with #to_s" do
@config.to_s.should.be.equal "OTHER_LDFLAGS = -framework Foundation"
end
it "sorts the internal data by setting name when serializing with #to_s" do
config = Xcodeproj::Config.new('Y' => '2', 'Z' => '3', 'X' => '1')
config.to_s.should == "X = 1\nY = 2\nZ = 3"
end
it "can be serialized with #to_hash" do
@config.to_hash.should.be.equal @hash
end
it "can prefix values during serialization" do
@prefix_hash = { 'PODS_PREFIX_OTHER_LDFLAGS' => @hash['OTHER_LDFLAGS'] }
@config.to_hash('PODS_PREFIX_').should.be.equal @prefix_hash
end
it "does not serialize with #to_s when inspecting the object" do
@config.inspect.should == @config.to_hash.inspect
end
it "can be compared with other instances" do
config_dupe = Xcodeproj::Config.new(@hash)
config_dupe.should.be.equal @config
end
it "merges another config hash in place" do
@config.merge!('HEADER_SEARCH_PATHS' => '/some/path')
@config.should == {
'OTHER_LDFLAGS' => '-framework Foundation',
'HEADER_SEARCH_PATHS' => '/some/path'
}
end
it "merges another config hash in place with the `<<` shortcut" do
@config << { 'HEADER_SEARCH_PATHS' => '/some/path' }
@config.should == {
'OTHER_LDFLAGS' => '-framework Foundation',
'HEADER_SEARCH_PATHS' => '/some/path'
}
end
it "merges another hash in a new one" do
new = @config.merge('HEADER_SEARCH_PATHS' => '/some/path')
new.object_id.should.not == @config.object_id
new.should == {
'OTHER_LDFLAGS' => '-framework Foundation',
'HEADER_SEARCH_PATHS' => '/some/path'
}
@config.should == { 'OTHER_LDFLAGS' => '-framework Foundation' }
end
it "appends a value for the same key when merging" do
@config.merge!('OTHER_LDFLAGS' => '-l xml2.2.7.3')
@config.should == {
'OTHER_LDFLAGS' => '-lxml2.2.7.3 -framework Foundation'
}
end
it "generates the config file with refs to all included xcconfigs" do
@config.includes = ['Somefile.xcconfig']
@config.to_s.split("\n").first.should == '#include "Somefile.xcconfig"'
end
it "appends the extensiono to the included files if needed" do
@config.includes = ['Somefile']
@config.to_s.split("\n").first.should == '#include "Somefile.xcconfig"'
end
it "creates the config file" do
@config.merge!('HEADER_SEARCH_PATHS' => '/some/path')
@config.merge!('OTHER_LDFLAGS' => '-l xml2.2.7.3')
@config.save_as(temporary_directory + 'Pods.xcconfig')
(temporary_directory + 'Pods.xcconfig').read.split("\n").sort.should == [
"OTHER_LDFLAGS = -lxml2.2.7.3 -framework Foundation",
"HEADER_SEARCH_PATHS = /some/path"
].sort
end
it "contains file path refs to all included xcconfigs" do
config = Xcodeproj::Config.new(fixture_path('include.xcconfig'))
config.includes.size.should.be.equal 1
config.includes.first.should.be.equal 'Somefile'
end
it 'can be created from multiline file' do
config = Xcodeproj::Config.new(fixture_path('sample.xcconfig'))
config.should == {
'Key1' => 'Value1 Value2',
'Key2' => 'Value3 Value4 Value5',
'Key3' => 'Value6',
'Key4' => ''
}
end
it 'can be created from file with comments inside' do
config = Xcodeproj::Config.new(fixture_path('with-comments.xcconfig'))
config.should == { 'Key' => 'Value' }
end
it "doesn't duplicate libraries and frameworks" do
hash = { 'OTHER_LDFLAGS' => '-framework Foundation -weak_framework Twitter -lxml2.2.7.3' }
config = Xcodeproj::Config.new(hash)
# merge the original hash again
config.merge!(hash)
config.frameworks.add 'Foundation'
config.weak_frameworks.add 'Twitter'
config.libraries.add 'xml2.2.7.3'
config.frameworks.to_a.should.be.equal %w[ Foundation ]
config.weak_frameworks.to_a.should.be.equal %w[ Twitter ]
config.libraries.to_a.should.be.equal %w[ xml2.2.7.3 ]
end
it "doesn't duplicate other attribute values" do
hash = { 'CLANG_CXX_LIBRARY' => 'libc++' }
config = Xcodeproj::Config.new(hash)
config.merge!(hash)
config.to_hash.should == hash
config.merge!(config)
config.to_hash.should == hash
end
it 'it preserves OTHER_LDFLAGS not related to libraries and frameworks' do
config1 = Xcodeproj::Config.new({ 'OTHER_LDFLAGS' => %w{-ObjC -fobjc-arc}.join(' ') })
config2 = Xcodeproj::Config.new({ 'OTHER_LDFLAGS' => '-framework SystemConfiguration' })
config1.merge! config2
config1.to_hash['OTHER_LDFLAGS'].should == '-ObjC -fobjc-arc -framework SystemConfiguration'
end
it "merges frameworks and libraries from another Config instance" do
hash = { 'OTHER_LDFLAGS' => '-framework Foundation -weak_framework Twitter -lxml2.2.7.3' }
config = Xcodeproj::Config.new
config.merge!(Xcodeproj::Config.new(hash))
config.frameworks.to_a.should.be.equal %w[ Foundation ]
config.weak_frameworks.to_a.should.be.equal %w[ Twitter ]
config.libraries.to_a.should.be.equal %w[ xml2.2.7.3 ]
end
end
#---------------------------------------------------------------------------#
describe "Private helpers" do
before do
@config = Xcodeproj::Config.new
end
describe "#normalized_xcconfig_path" do
it "appends the extension if needed" do
normalized_path = @config.send(:normalized_xcconfig_path, 'path/file')
normalized_path.should == 'path/file.xcconfig'
end
it "doesn't append the extension if not needed" do
normalized_path = @config.send(:normalized_xcconfig_path, 'path/file')
normalized_path.should == 'path/file.xcconfig'
end
end
end
#---------------------------------------------------------------------------#
end