@@ -76,170 +76,199 @@ def verified_install(backend, path)
76
76
RSpec . describe ArduinoCI ::CppLibrary do
77
77
next if skip_ruby_tests
78
78
79
- answers = {
80
- DoSomething : {
81
- one_five : false ,
82
- library_properties : true ,
83
- cpp_files : [ Pathname . new ( "DoSomething" ) + "do-something.cpp" ] ,
84
- cpp_files_libraries : [ ] ,
85
- header_dirs : [ Pathname . new ( "DoSomething" ) ] ,
86
- arduino_library_src_dirs : [ ] ,
87
- test_files : [
88
- "DoSomething/test/bad-errormessages.cpp" ,
89
- "DoSomething/test/bad-null.cpp" ,
90
- "DoSomething/test/good-assert.cpp" ,
91
- "DoSomething/test/good-library.cpp" ,
92
- "DoSomething/test/good-null.cpp" ,
93
- ] . map { |f | Pathname . new ( f ) }
94
- } ,
95
- OnePointOhDummy : {
96
- one_five : false ,
97
- library_properties : false ,
98
- cpp_files : [
99
- "OnePointOhDummy/YesBase.cpp" ,
100
- "OnePointOhDummy/utility/YesUtil.cpp" ,
101
- ] . map { |f | Pathname . new ( f ) } ,
102
- cpp_files_libraries : [ ] ,
103
- header_dirs : [
104
- "OnePointOhDummy" ,
105
- "OnePointOhDummy/utility"
106
- ] . map { |f | Pathname . new ( f ) } ,
107
- arduino_library_src_dirs : [ ] ,
108
- test_files : [
109
- "OnePointOhDummy/test/null.cpp" ,
110
- ] . map { |f | Pathname . new ( f ) }
111
- } ,
112
- OnePointFiveMalformed : {
113
- one_five : false ,
114
- library_properties : false ,
115
- cpp_files : [
116
- "OnePointFiveMalformed/YesBase.cpp" ,
117
- "OnePointFiveMalformed/utility/YesUtil.cpp" ,
118
- ] . map { |f | Pathname . new ( f ) } ,
119
- cpp_files_libraries : [ ] ,
120
- header_dirs : [
121
- "OnePointFiveMalformed" ,
122
- "OnePointFiveMalformed/utility"
123
- ] . map { |f | Pathname . new ( f ) } ,
124
- arduino_library_src_dirs : [ ] ,
125
- test_files : [ ]
126
- } ,
127
- OnePointFiveDummy : {
79
+ context "compiler flags" do
80
+ config = ArduinoCI ::CIConfig . new
81
+ config . load_yaml ( File . join ( File . dirname ( __FILE__ ) , "yaml" , "o1.yaml" ) )
82
+ bogo_config = config . gcc_config ( "bogo" )
83
+ fld = FakeLibDir . new
84
+ backend = fld . backend
85
+ cpp_lib_path = sampleproj_path + "DoSomething"
86
+ cpp_library = verified_install ( backend , cpp_lib_path )
87
+
88
+ # the keys are the methods of cpp_library to call
89
+ # the results are what we expect to see based on the config we loaded
90
+ methods_and_results = {
91
+ feature_args : [ "-fa" , "-fb" ] ,
92
+ warning_args : [ "-We" , "-Wf" ] ,
93
+ define_args : [ "-Dc" , "-Dd" ] ,
94
+ flag_args : [ "g" , "h" ]
95
+ }
96
+
97
+ methods_and_results . each do |m , expected |
98
+ it "Creates #{ m } from config" do
99
+ expect ( expected ) . to eq ( cpp_library . send ( m , bogo_config ) )
100
+ end
101
+ end
102
+
103
+ end
104
+
105
+ context "arduino-library-specification detection" do
106
+
107
+ answers = {
108
+ DoSomething : {
109
+ one_five : false ,
110
+ library_properties : true ,
111
+ cpp_files : [ Pathname . new ( "DoSomething" ) + "do-something.cpp" ] ,
112
+ cpp_files_libraries : [ ] ,
113
+ header_dirs : [ Pathname . new ( "DoSomething" ) ] ,
114
+ arduino_library_src_dirs : [ ] ,
115
+ test_files : [
116
+ "DoSomething/test/bad-errormessages.cpp" ,
117
+ "DoSomething/test/bad-null.cpp" ,
118
+ "DoSomething/test/good-assert.cpp" ,
119
+ "DoSomething/test/good-library.cpp" ,
120
+ "DoSomething/test/good-null.cpp" ,
121
+ ] . map { |f | Pathname . new ( f ) }
122
+ } ,
123
+ OnePointOhDummy : {
124
+ one_five : false ,
125
+ library_properties : false ,
126
+ cpp_files : [
127
+ "OnePointOhDummy/YesBase.cpp" ,
128
+ "OnePointOhDummy/utility/YesUtil.cpp" ,
129
+ ] . map { |f | Pathname . new ( f ) } ,
130
+ cpp_files_libraries : [ ] ,
131
+ header_dirs : [
132
+ "OnePointOhDummy" ,
133
+ "OnePointOhDummy/utility"
134
+ ] . map { |f | Pathname . new ( f ) } ,
135
+ arduino_library_src_dirs : [ ] ,
136
+ test_files : [
137
+ "OnePointOhDummy/test/null.cpp" ,
138
+ ] . map { |f | Pathname . new ( f ) }
139
+ } ,
140
+ OnePointFiveMalformed : {
141
+ one_five : false ,
142
+ library_properties : false ,
143
+ cpp_files : [
144
+ "OnePointFiveMalformed/YesBase.cpp" ,
145
+ "OnePointFiveMalformed/utility/YesUtil.cpp" ,
146
+ ] . map { |f | Pathname . new ( f ) } ,
147
+ cpp_files_libraries : [ ] ,
148
+ header_dirs : [
149
+ "OnePointFiveMalformed" ,
150
+ "OnePointFiveMalformed/utility"
151
+ ] . map { |f | Pathname . new ( f ) } ,
152
+ arduino_library_src_dirs : [ ] ,
153
+ test_files : [ ]
154
+ } ,
155
+ OnePointFiveDummy : {
156
+ one_five : true ,
157
+ library_properties : true ,
158
+ cpp_files : [
159
+ "OnePointFiveDummy/src/YesSrc.cpp" ,
160
+ "OnePointFiveDummy/src/subdir/YesSubdir.cpp" ,
161
+ ] . map { |f | Pathname . new ( f ) } ,
162
+ cpp_files_libraries : [ ] ,
163
+ header_dirs : [
164
+ "OnePointFiveDummy/src" ,
165
+ "OnePointFiveDummy/src/subdir" ,
166
+ ] . map { |f | Pathname . new ( f ) } ,
167
+ arduino_library_src_dirs : [ ] ,
168
+ test_files : [
169
+ "OnePointFiveDummy/test/null.cpp" ,
170
+ ] . map { |f | Pathname . new ( f ) }
171
+ }
172
+ }
173
+
174
+ # easier to construct this one from the other test cases
175
+ answers [ :DependOnSomething ] = {
128
176
one_five : true ,
129
177
library_properties : true ,
130
- cpp_files : [
131
- "OnePointFiveDummy/src/YesSrc.cpp" ,
132
- "OnePointFiveDummy/src/subdir/YesSubdir.cpp" ,
133
- ] . map { |f | Pathname . new ( f ) } ,
134
- cpp_files_libraries : [ ] ,
135
- header_dirs : [
136
- "OnePointFiveDummy/src" ,
137
- "OnePointFiveDummy/src/subdir" ,
138
- ] . map { |f | Pathname . new ( f ) } ,
139
- arduino_library_src_dirs : [ ] ,
178
+ cpp_files : [ "DependOnSomething/src/YesDeps.cpp" ] . map { |f | Pathname . new ( f ) } ,
179
+ cpp_files_libraries : answers [ :OnePointOhDummy ] [ :cpp_files ] + answers [ :OnePointFiveDummy ] [ :cpp_files ] ,
180
+ header_dirs : [ "DependOnSomething/src" ] . map { |f | Pathname . new ( f ) } , # this is not recursive!
181
+ arduino_library_src_dirs : answers [ :OnePointOhDummy ] [ :header_dirs ] + answers [ :OnePointFiveDummy ] [ :header_dirs ] ,
140
182
test_files : [
141
- "OnePointFiveDummy /test/null.cpp",
142
- ] . map { |f | Pathname . new ( f ) }
183
+ "DependOnSomething /test/null.cpp",
184
+ ] . map { |f | Pathname . new ( f ) }
143
185
}
144
- }
145
186
146
- # easier to construct this one from the other test cases
147
- answers [ :DependOnSomething ] = {
148
- one_five : true ,
149
- library_properties : true ,
150
- cpp_files : [ "DependOnSomething/src/YesDeps.cpp" ] . map { |f | Pathname . new ( f ) } ,
151
- cpp_files_libraries : answers [ :OnePointOhDummy ] [ :cpp_files ] + answers [ :OnePointFiveDummy ] [ :cpp_files ] ,
152
- header_dirs : [ "DependOnSomething/src" ] . map { |f | Pathname . new ( f ) } , # this is not recursive!
153
- arduino_library_src_dirs : answers [ :OnePointOhDummy ] [ :header_dirs ] + answers [ :OnePointFiveDummy ] [ :header_dirs ] ,
154
- test_files : [
155
- "DependOnSomething/test/null.cpp" ,
156
- ] . map { |f | Pathname . new ( f ) }
157
- }
187
+ answers . freeze
158
188
159
- answers . freeze
189
+ answers . each do | sampleproject , expected |
160
190
161
- answers . each do |sampleproject , expected |
162
-
163
- # we will need to install some dummy libraries into a fake location, so do that on demand
164
- fld = FakeLibDir . new
165
- backend = fld . backend
191
+ # we will need to install some dummy libraries into a fake location, so do that on demand
192
+ fld = FakeLibDir . new
193
+ backend = fld . backend
166
194
167
- context "#{ sampleproject } " do
168
- cpp_lib_path = sampleproj_path + sampleproject . to_s
169
- around ( :example ) { |example | fld . in_pristine_fake_libraries_dir ( example ) }
170
- before ( :each ) do
171
- @base_dir = fld . libraries_dir
172
- @cpp_library = verified_install ( backend , cpp_lib_path )
173
- end
195
+ context "#{ sampleproject } " do
196
+ cpp_lib_path = sampleproj_path + sampleproject . to_s
197
+ around ( :example ) { |example | fld . in_pristine_fake_libraries_dir ( example ) }
198
+ before ( :each ) do
199
+ @base_dir = fld . libraries_dir
200
+ @cpp_library = verified_install ( backend , cpp_lib_path )
201
+ end
174
202
175
- it "is a sane test env" do
176
- expect ( sampleproject . to_s ) . to eq ( @cpp_library . name )
177
- end
203
+ it "is a sane test env" do
204
+ expect ( sampleproject . to_s ) . to eq ( @cpp_library . name )
205
+ end
178
206
179
- it "detects 1.5 format" do
180
- expect ( @cpp_library . one_point_five? ) . to eq ( expected [ :one_five ] )
181
- end
207
+ it "detects 1.5 format" do
208
+ expect ( @cpp_library . one_point_five? ) . to eq ( expected [ :one_five ] )
209
+ end
182
210
183
- it "detects library.properties" do
184
- expect ( @cpp_library . library_properties? ) . to eq ( expected [ :library_properties ] )
185
- end
211
+ it "detects library.properties" do
212
+ expect ( @cpp_library . library_properties? ) . to eq ( expected [ :library_properties ] )
213
+ end
186
214
187
215
188
- context "cpp_files" do
189
- it "finds cpp files in directory" do
190
- relative_paths = @cpp_library . cpp_files . map { |f | f . relative_path_from ( @base_dir ) }
191
- expect ( relative_paths . map ( &:to_s ) ) . to match_array ( expected [ :cpp_files ] . map ( &:to_s ) )
216
+ context "cpp_files" do
217
+ it "finds cpp files in directory" do
218
+ relative_paths = @cpp_library . cpp_files . map { |f | f . relative_path_from ( @base_dir ) }
219
+ expect ( relative_paths . map ( &:to_s ) ) . to match_array ( expected [ :cpp_files ] . map ( &:to_s ) )
220
+ end
192
221
end
193
- end
194
222
195
- context "cpp_files_libraries" do
196
- it "finds cpp files in directories of dependencies" do
197
- @cpp_library . all_arduino_library_dependencies! # side effect: installs them
198
- dependencies = @cpp_library . arduino_library_dependencies . nil? ? [ ] : @cpp_library . arduino_library_dependencies
199
- dependencies . each { |d | verified_install ( backend , sampleproj_path + d ) }
200
- relative_paths = @cpp_library . cpp_files_libraries ( dependencies ) . map { |f | f . relative_path_from ( @base_dir ) }
201
- expect ( relative_paths . map ( &:to_s ) ) . to match_array ( expected [ :cpp_files_libraries ] . map ( &:to_s ) )
223
+ context "cpp_files_libraries" do
224
+ it "finds cpp files in directories of dependencies" do
225
+ @cpp_library . all_arduino_library_dependencies! # side effect: installs them
226
+ dependencies = @cpp_library . arduino_library_dependencies . nil? ? [ ] : @cpp_library . arduino_library_dependencies
227
+ dependencies . each { |d | verified_install ( backend , sampleproj_path + d ) }
228
+ relative_paths = @cpp_library . cpp_files_libraries ( dependencies ) . map { |f | f . relative_path_from ( @base_dir ) }
229
+ expect ( relative_paths . map ( &:to_s ) ) . to match_array ( expected [ :cpp_files_libraries ] . map ( &:to_s ) )
230
+ end
202
231
end
203
- end
204
232
205
- context "header_dirs" do
206
- it "finds directories containing h files" do
207
- relative_paths = @cpp_library . header_dirs . map { |f | f . relative_path_from ( @base_dir ) }
208
- expect ( relative_paths . map ( &:to_s ) ) . to match_array ( expected [ :header_dirs ] . map ( &:to_s ) )
233
+ context "header_dirs" do
234
+ it "finds directories containing h files" do
235
+ relative_paths = @cpp_library . header_dirs . map { |f | f . relative_path_from ( @base_dir ) }
236
+ expect ( relative_paths . map ( &:to_s ) ) . to match_array ( expected [ :header_dirs ] . map ( &:to_s ) )
237
+ end
209
238
end
210
- end
211
239
212
- context "tests_dir" do
213
- it "locates the tests directory" do
214
- # since we don't know where the CI system will install this stuff,
215
- # we need to go looking for a relative path to the SampleProjects directory
216
- # just to get our "expected" value
217
- relative_path = @cpp_library . tests_dir . relative_path_from ( @base_dir )
218
- expect ( relative_path . to_s ) . to eq ( "#{ sampleproject } /test" )
240
+ context "tests_dir" do
241
+ it "locates the tests directory" do
242
+ # since we don't know where the CI system will install this stuff,
243
+ # we need to go looking for a relative path to the SampleProjects directory
244
+ # just to get our "expected" value
245
+ relative_path = @cpp_library . tests_dir . relative_path_from ( @base_dir )
246
+ expect ( relative_path . to_s ) . to eq ( "#{ sampleproject } /test" )
247
+ end
219
248
end
220
- end
221
249
222
- context "examples_dir" do
223
- it "locates the examples directory" do
224
- relative_path = @cpp_library . examples_dir . relative_path_from ( @base_dir )
225
- expect ( relative_path . to_s ) . to eq ( "#{ sampleproject } /examples" )
250
+ context "examples_dir" do
251
+ it "locates the examples directory" do
252
+ relative_path = @cpp_library . examples_dir . relative_path_from ( @base_dir )
253
+ expect ( relative_path . to_s ) . to eq ( "#{ sampleproject } /examples" )
254
+ end
226
255
end
227
- end
228
256
229
- context "test_files" do
230
- it "finds cpp files in directory" do
231
- relative_paths = @cpp_library . test_files . map { |f | f . relative_path_from ( @base_dir ) }
232
- expect ( relative_paths . map ( &:to_s ) ) . to match_array ( expected [ :test_files ] . map ( &:to_s ) )
257
+ context "test_files" do
258
+ it "finds cpp files in directory" do
259
+ relative_paths = @cpp_library . test_files . map { |f | f . relative_path_from ( @base_dir ) }
260
+ expect ( relative_paths . map ( &:to_s ) ) . to match_array ( expected [ :test_files ] . map ( &:to_s ) )
261
+ end
233
262
end
234
- end
235
263
236
- context "arduino_library_src_dirs" do
237
- it "finds src dirs from dependent libraries" do
238
- # we explicitly feed in the internal dependencies
239
- dependencies = @cpp_library . arduino_library_dependencies . nil? ? [ ] : @cpp_library . arduino_library_dependencies
240
- dependencies . each { |d | verified_install ( backend , sampleproj_path + d ) }
241
- relative_paths = @cpp_library . arduino_library_src_dirs ( dependencies ) . map { |f | f . relative_path_from ( @base_dir ) }
242
- expect ( relative_paths . map ( &:to_s ) ) . to match_array ( expected [ :arduino_library_src_dirs ] . map ( &:to_s ) )
264
+ context "arduino_library_src_dirs" do
265
+ it "finds src dirs from dependent libraries" do
266
+ # we explicitly feed in the internal dependencies
267
+ dependencies = @cpp_library . arduino_library_dependencies . nil? ? [ ] : @cpp_library . arduino_library_dependencies
268
+ dependencies . each { |d | verified_install ( backend , sampleproj_path + d ) }
269
+ relative_paths = @cpp_library . arduino_library_src_dirs ( dependencies ) . map { |f | f . relative_path_from ( @base_dir ) }
270
+ expect ( relative_paths . map ( &:to_s ) ) . to match_array ( expected [ :arduino_library_src_dirs ] . map ( &:to_s ) )
271
+ end
243
272
end
244
273
end
245
274
end
0 commit comments