Skip to content

Commit 24799f3

Browse files
authored
fix: Sketch preprocessing errors were displayed on stdout instead of stderr (#2806)
* Slightly refactored integration test * Added integration test * Fixed output channel for stderr in sketch preprocessing
1 parent f08b2d3 commit 24799f3

File tree

3 files changed

+46
-17
lines changed

3 files changed

+46
-17
lines changed

internal/arduino/builder/preprocess_sketch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (b *Builder) preprocessSketch(includes paths.PathList) error {
3232
if b.logger.Verbose() {
3333
b.logger.WriteStdout(result.Stdout())
3434
}
35-
b.logger.WriteStdout(result.Stderr())
35+
b.logger.WriteStderr(result.Stderr())
3636
b.diagnosticStore.Parse(result.Args(), result.Stderr())
3737
}
3838

internal/integrationtest/compile_3/compile_test.go

+44-16
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestCompilerErrOutput(t *testing.T) {
107107
_, _, err := cli.Run("core", "install", "arduino:[email protected]")
108108
require.NoError(t, err)
109109

110-
{
110+
t.Run("Diagnostics", func(t *testing.T) {
111111
// prepare sketch
112112
sketch, err := paths.New("testdata", "blink_with_wrong_cpp").Abs()
113113
require.NoError(t, err)
@@ -126,10 +126,11 @@ func TestCompilerErrOutput(t *testing.T) {
126126
"context": [ { "message": "In function 'void wrong()':" } ]
127127
}
128128
]`)
129-
}
129+
})
130+
131+
t.Run("PreprocessorDiagnostics", func(t *testing.T) {
132+
// Test the preprocessor errors are present in the diagnostics
130133

131-
// Test the preprocessor errors are present in the diagnostics
132-
{
133134
// prepare sketch
134135
sketch, err := paths.New("testdata", "blink_with_wrong_include").Abs()
135136
require.NoError(t, err)
@@ -148,14 +149,15 @@ func TestCompilerErrOutput(t *testing.T) {
148149
"message": "invalid preprocessing directive #wrong\n #wrong\n ^~~~~",
149150
}
150151
]`)
151-
}
152+
})
153+
154+
t.Run("PreprocessorDiagnosticsWithLibErrors", func(t *testing.T) {
155+
// Test the preprocessor errors are present in the diagnostics.
156+
// In case we have 2 libraries:
157+
// 1. one is missing
158+
// 2. the other one is missing only from the first GCC run
159+
// The diagnostics should report only 1 missing library.
152160

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-
{
159161
// prepare sketch
160162
sketch, err := paths.New("testdata", "using_Wire_with_missing_lib").Abs()
161163
require.NoError(t, err)
@@ -175,11 +177,12 @@ func TestCompilerErrOutput(t *testing.T) {
175177
"column": 10,
176178
}
177179
]`)
178-
}
180+
})
181+
182+
t.Run("LibraryDiscoverFalseErrors", func(t *testing.T) {
183+
// Check that library discover do not generate false errors
184+
// https://github.com/arduino/arduino-cli/issues/2263
179185

180-
// Check that library discover do not generate false errors
181-
// https://github.com/arduino/arduino-cli/issues/2263
182-
{
183186
// prepare sketch
184187
sketch, err := paths.New("testdata", "using_Wire").Abs()
185188
require.NoError(t, err)
@@ -191,7 +194,32 @@ func TestCompilerErrOutput(t *testing.T) {
191194
jsonOut.Query(".compiler_out").MustNotContain(`"fatal error"`)
192195
jsonOut.Query(".compiler_err").MustNotContain(`"fatal error"`)
193196
jsonOut.MustNotContain(`{ "diagnostics" : [] }`)
194-
}
197+
})
198+
199+
t.Run("PreprocessorErrorsOnStderr", func(t *testing.T) {
200+
// Test the preprocessor errors are present in the diagnostics
201+
// when they are printed on stderr
202+
203+
// prepare sketch
204+
sketch, err := paths.New("testdata", "blink_with_error_directive").Abs()
205+
require.NoError(t, err)
206+
207+
// Run compile and catch err stream
208+
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", "-v", "--json", sketch.String())
209+
require.Error(t, err)
210+
jsonOut := requirejson.Parse(t, out)
211+
jsonOut.Query(".compiler_out").MustNotContain(`"error:"`)
212+
jsonOut.Query(".compiler_err").MustContain(`"error:"`)
213+
jsonOut.Query(`.builder_result.diagnostics`).MustContain(`
214+
[
215+
{
216+
"severity": "ERROR",
217+
"message": "#error void setup(){} void loop(){}\n #error void setup(){} void loop(){}\n ^~~~~",
218+
"line": 1,
219+
"column": 2
220+
}
221+
]`)
222+
})
195223
}
196224

197225
func TestCompileRelativeLibraryPath(t *testing.T) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#error void setup(){} void loop(){}

0 commit comments

Comments
 (0)