Skip to content

Add diagnostics in the preprocessor #2515

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

Merged
merged 9 commits into from
Feb 19, 2024
Prev Previous commit
Next Next commit
Add integration tests
  • Loading branch information
alessio-perugini committed Jan 31, 2024
commit 7b4f7139f0ae7bb5d76498f4f5004e3d00040ae1
51 changes: 50 additions & 1 deletion internal/integrationtest/compile_3/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestCompilerErrOutput(t *testing.T) {
require.Error(t, err)
outJson := requirejson.Parse(t, out)
outJson.Query(`.compiler_err`).MustContain(`"error"`)
outJson.Query(`.diagnostics`).MustContain(`
outJson.Query(`.builder_result.diagnostics`).MustContain(`
[
{
"severity": "ERROR",
Expand All @@ -128,6 +128,55 @@ func TestCompilerErrOutput(t *testing.T) {
]`)
}

// 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)

// Run compile and catch err stream
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", "-v", "--format", "json", sketch.String())
require.Error(t, err)
outJson := requirejson.Parse(t, out)
outJson.Query(`.success`).MustContain(`false`)
outJson.Query(`.builder_result.diagnostics`).MustContain(`
[
{
"severity": "ERROR",
"line": 1,
"column": 2,
"message": "invalid preprocessing directive #wrong\n #wrong\n ^~~~~",
}
]`)
}

// 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)

// Run compile and catch err stream
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", "-v", "--format", "json", sketch.String())
require.Error(t, err)
outJson := requirejson.Parse(t, out)
outJson.Query(`.success`).MustContain(`false`)
outJson.Query(`.builder_result.diagnostics | length`).MustEqual("1")
outJson.Query(`.builder_result.diagnostics`).MustContain(`
[
{
"severity": "FATAL",
"message": "MissingWire.h: No such file or directory\n #include \u003cMissingWire.h\u003e\n ^~~~~~~~~~~~~~~",
"line": 2,
"column": 10,
}
]`)
}

// Check that library discover do not generate false errors
// https://github.com/arduino/arduino-cli/issues/2263
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#wrong
void setup() {}
void loop() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <Wire.h>
#include <MissingWire.h>

void setup() {}
void loop() {}