diff --git a/internal/arduino/builder/preprocess_sketch.go b/internal/arduino/builder/preprocess_sketch.go index 86d7bd7e7e9..b7fe178db02 100644 --- a/internal/arduino/builder/preprocess_sketch.go +++ b/internal/arduino/builder/preprocess_sketch.go @@ -32,7 +32,7 @@ func (b *Builder) preprocessSketch(includes paths.PathList) error { if b.logger.Verbose() { b.logger.WriteStdout(result.Stdout()) } - b.logger.WriteStdout(result.Stderr()) + b.logger.WriteStderr(result.Stderr()) b.diagnosticStore.Parse(result.Args(), result.Stderr()) } diff --git a/internal/integrationtest/compile_3/compile_test.go b/internal/integrationtest/compile_3/compile_test.go index aabd30445d0..8e15b901c6d 100644 --- a/internal/integrationtest/compile_3/compile_test.go +++ b/internal/integrationtest/compile_3/compile_test.go @@ -107,7 +107,7 @@ func TestCompilerErrOutput(t *testing.T) { _, _, err := cli.Run("core", "install", "arduino:avr@1.8.5") require.NoError(t, err) - { + t.Run("Diagnostics", func(t *testing.T) { // prepare sketch sketch, err := paths.New("testdata", "blink_with_wrong_cpp").Abs() require.NoError(t, err) @@ -126,10 +126,11 @@ func TestCompilerErrOutput(t *testing.T) { "context": [ { "message": "In function 'void wrong()':" } ] } ]`) - } + }) + + t.Run("PreprocessorDiagnostics", func(t *testing.T) { + // Test the preprocessor errors are present in the diagnostics - // Test the preprocessor errors are present in the diagnostics - { // prepare sketch sketch, err := paths.New("testdata", "blink_with_wrong_include").Abs() require.NoError(t, err) @@ -148,14 +149,15 @@ func TestCompilerErrOutput(t *testing.T) { "message": "invalid preprocessing directive #wrong\n #wrong\n ^~~~~", } ]`) - } + }) + + t.Run("PreprocessorDiagnosticsWithLibErrors", func(t *testing.T) { + // Test the preprocessor errors are present in the diagnostics. + // In case we have 2 libraries: + // 1. one is missing + // 2. the other one is missing only from the first GCC run + // The diagnostics should report only 1 missing library. - // Test the preprocessor errors are present in the diagnostics. - // In case we have 2 libraries: - // 1. one is missing - // 2. the other one is missing only from the first GCC run - // The diagnostics should report only 1 missing library. - { // prepare sketch sketch, err := paths.New("testdata", "using_Wire_with_missing_lib").Abs() require.NoError(t, err) @@ -175,11 +177,12 @@ func TestCompilerErrOutput(t *testing.T) { "column": 10, } ]`) - } + }) + + t.Run("LibraryDiscoverFalseErrors", func(t *testing.T) { + // Check that library discover do not generate false errors + // https://github.com/arduino/arduino-cli/issues/2263 - // Check that library discover do not generate false errors - // https://github.com/arduino/arduino-cli/issues/2263 - { // prepare sketch sketch, err := paths.New("testdata", "using_Wire").Abs() require.NoError(t, err) @@ -191,7 +194,32 @@ func TestCompilerErrOutput(t *testing.T) { jsonOut.Query(".compiler_out").MustNotContain(`"fatal error"`) jsonOut.Query(".compiler_err").MustNotContain(`"fatal error"`) jsonOut.MustNotContain(`{ "diagnostics" : [] }`) - } + }) + + t.Run("PreprocessorErrorsOnStderr", func(t *testing.T) { + // Test the preprocessor errors are present in the diagnostics + // when they are printed on stderr + + // prepare sketch + sketch, err := paths.New("testdata", "blink_with_error_directive").Abs() + require.NoError(t, err) + + // Run compile and catch err stream + out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", "-v", "--json", sketch.String()) + require.Error(t, err) + jsonOut := requirejson.Parse(t, out) + jsonOut.Query(".compiler_out").MustNotContain(`"error:"`) + jsonOut.Query(".compiler_err").MustContain(`"error:"`) + jsonOut.Query(`.builder_result.diagnostics`).MustContain(` + [ + { + "severity": "ERROR", + "message": "#error void setup(){} void loop(){}\n #error void setup(){} void loop(){}\n ^~~~~", + "line": 1, + "column": 2 + } + ]`) + }) } func TestCompileRelativeLibraryPath(t *testing.T) { diff --git a/internal/integrationtest/compile_3/testdata/blink_with_error_directive/blink_with_error_directive.ino b/internal/integrationtest/compile_3/testdata/blink_with_error_directive/blink_with_error_directive.ino new file mode 100644 index 00000000000..02bc8b99521 --- /dev/null +++ b/internal/integrationtest/compile_3/testdata/blink_with_error_directive/blink_with_error_directive.ino @@ -0,0 +1 @@ +#error void setup(){} void loop(){}