Skip to content

Commit

Permalink
fix: Sketch preprocessing errors were displayed on stdout instead of …
Browse files Browse the repository at this point in the history
…stderr (#2806)

* Slightly refactored integration test

* Added integration test

* Fixed output channel for stderr in sketch preprocessing
  • Loading branch information
cmaglie authored Jan 9, 2025
1 parent f08b2d3 commit 24799f3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
2 changes: 1 addition & 1 deletion internal/arduino/builder/preprocess_sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
60 changes: 44 additions & 16 deletions internal/integrationtest/compile_3/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#error void setup(){} void loop(){}

0 comments on commit 24799f3

Please sign in to comment.