@@ -117,7 +117,7 @@ func TestCompilerErrOutput(t *testing.T) {
117
117
require .Error (t , err )
118
118
outJson := requirejson .Parse (t , out )
119
119
outJson .Query (`.compiler_err` ).MustContain (`"error"` )
120
- outJson .Query (`.diagnostics` ).MustContain (`
120
+ outJson .Query (`.builder_result. diagnostics` ).MustContain (`
121
121
[
122
122
{
123
123
"severity": "ERROR",
@@ -128,6 +128,54 @@ func TestCompilerErrOutput(t *testing.T) {
128
128
]` )
129
129
}
130
130
131
+ // Test the preprocessor errors are present in the diagnostics
132
+ {
133
+ // prepare sketch
134
+ sketch , err := paths .New ("testdata" , "blink_with_wrong_include" ).Abs ()
135
+ require .NoError (t , err )
136
+
137
+ // Run compile and catch err stream
138
+ out , _ , err := cli .Run ("compile" , "-b" , "arduino:avr:uno" , "-v" , "--format" , "json" , sketch .String ())
139
+ require .Error (t , err )
140
+ outJson := requirejson .Parse (t , out )
141
+ outJson .Query (`.success` ).MustContain (`false` )
142
+ outJson .Query (`.builder_result.diagnostics` ).MustContain (`
143
+ [
144
+ {
145
+ "severity": "ERROR",
146
+ "line": 1,
147
+ "column": 2,
148
+ "message": "invalid preprocessing directive #wrong\n #wrong\n ^~~~~",
149
+ }
150
+ ]` )
151
+ }
152
+
153
+ // Test the preprocessor errors are present in the diagnostics.
154
+ // In case we have 2 libraries:
155
+ // 1. one is missing
156
+ // 2. the other one is missing only from the first GCC run
157
+ // The diagnostics should report only 1 missing library.
158
+ {
159
+ // prepare sketch
160
+ sketch , err := paths .New ("testdata" , "using_Wire_with_missing_lib" ).Abs ()
161
+ require .NoError (t , err )
162
+
163
+ // Run compile and catch err stream
164
+ out , _ , err := cli .Run ("compile" , "-b" , "arduino:avr:uno" , "-v" , "--format" , "json" , sketch .String ())
165
+ require .Error (t , err )
166
+ outJson := requirejson .Parse (t , out )
167
+ outJson .Query (`.success` ).MustContain (`false` )
168
+ outJson .Query (`.builder_result.diagnostics` ).MustContain (`
169
+ [
170
+ {
171
+ "severity": "FATAL",
172
+ "line": 2,
173
+ "column": 10,
174
+ "message": "MissingWire.h: No such file or directory\n #include \u003cMissingWire.h\u003e\n ^~~~~~~~~~~~~~~",
175
+ }
176
+ ]` )
177
+ }
178
+
131
179
// Check that library discover do not generate false errors
132
180
// https://github.com/arduino/arduino-cli/issues/2263
133
181
{
0 commit comments