@@ -61,20 +61,63 @@ def run_gcc(*args, **kwargs)
61
61
Host . run ( *full_args , **kwargs )
62
62
end
63
63
64
- def test_args
65
- [ "-I#{ UNITTEST_HEADER_DIR } " ] + build_args + cpp_files_arduino + cpp_files_unittest + cpp_files
64
+ # GCC command line arguments for including aux libraries
65
+ def include_args ( aux_libraries )
66
+ places = [ ARDUINO_HEADER_DIR , UNITTEST_HEADER_DIR ] + header_dirs + aux_libraries
67
+ places . map { |d | "-I#{ d } " }
66
68
end
67
69
68
- def test ( test_file )
70
+ # GCC command line arguments for features (e.g. -fno-weak)
71
+ def feature_args ( ci_gcc_config )
72
+ return [ ] if ci_gcc_config [ :features ] . nil?
73
+ ci_gcc_config [ :features ] . map { |f | "-f#{ f } " }
74
+ end
75
+
76
+ # GCC command line arguments for warning (e.g. -Wall)
77
+ def warning_args ( ci_gcc_config )
78
+ return [ ] if ci_gcc_config [ :warnings ] . nil?
79
+ ci_gcc_config [ :features ] . map { |w | "-W#{ w } " }
80
+ end
81
+
82
+ # GCC command line arguments for defines (e.g. -Dhave_something)
83
+ def define_args ( ci_gcc_config )
84
+ return [ ] if ci_gcc_config [ :defines ] . nil?
85
+ ci_gcc_config [ :defines ] . map { |d | "-D#{ d } " }
86
+ end
87
+
88
+ # GCC command line arguments as-is
89
+ def flag_args ( ci_gcc_config )
90
+ return [ ] if ci_gcc_config [ :flags ] . nil?
91
+ ci_gcc_config [ :flags ]
92
+ end
93
+
94
+ # All GCC command line args for building any unit test
95
+ def test_args ( aux_libraries , ci_gcc_config )
96
+ # TODO: something with libraries?
97
+ cgc = ci_gcc_config
98
+ ret = include_args ( aux_libraries ) + cpp_files_arduino + cpp_files_unittest + cpp_files
99
+ unless ci_gcc_config . nil?
100
+ ret = feature_args ( cgc ) + warning_args ( cgc ) + define_args ( cgc ) + flag_args ( cgc ) + ret
101
+ end
102
+ ret
103
+ end
104
+
105
+ # run a test of the given unit test file
106
+ def test_with_configuration ( test_file , aux_libraries , ci_gcc_config )
69
107
base = File . basename ( test_file )
70
108
executable = File . expand_path ( "unittest_#{ base } .bin" )
71
109
File . delete ( executable ) if File . exist? ( executable )
72
- args = [ "-o" , executable ] + test_args + [ test_file ]
110
+ args = [ "-o" , executable ] + test_args ( aux_libraries , ci_gcc_config ) + [ test_file ]
73
111
return false unless run_gcc ( *args )
74
112
artifacts << executable
75
113
Host . run ( executable )
76
114
end
77
115
116
+ # legacy shortcut for rspec
117
+ def test ( test_file )
118
+ test_with_configuration ( test_file , [ ] , nil )
119
+ end
120
+
78
121
end
79
122
80
123
end
0 commit comments