Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Sketch preprocessing errors were displayed on stdout instead of stderr #2806

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:[email protected]")
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(){}
Loading