Skip to content

Porting legacy tests to new integration-test infra (part 4...) #2315

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 19 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
40f0110
ported SketchThatIncludesArduinoH from legacy into integration test
alessio-perugini Sep 13, 2023
380bd2b
ported SketchWithStaticAsserts from legacy into integration test
alessio-perugini Sep 13, 2023
010ec16
ported SketchWithEnumClass from legacy into integration test
alessio-perugini Sep 13, 2023
2213a52
ported SketchWithExternC from legacy into integration test
alessio-perugini Sep 13, 2023
90cbaa3
ported testBuilderSketchWithMultilinePrototypes from legacy into inte…
alessio-perugini Sep 13, 2023
7126d9b
ported SketchWithExternCMultiline from legacy into integration test
alessio-perugini Sep 13, 2023
257f146
ported SketchWithMultilineTemplate from legacy into integration test
alessio-perugini Sep 13, 2023
c9c8e3c
ported SketchWithFakeFunctionPointer from legacy into integration test
alessio-perugini Sep 13, 2023
6f6822f
fix wrong templating
alessio-perugini Sep 13, 2023
09d6e20
ported SketchWithMinMaxDefinitions from legacy into integration test
alessio-perugini Sep 13, 2023
da31148
ported SketchWithFastledsLibrary from legacy into integration test
alessio-perugini Sep 13, 2023
66394be
ported sketch with merged sketch and bootloader from legacy into inte…
alessio-perugini Sep 13, 2023
3be02a5
temporary disable legacy test, before porting them to the new infra
alessio-perugini Sep 13, 2023
74de390
update .gitignore
alessio-perugini Sep 14, 2023
7e99332
ported CheckBuildOptionsFile from legacy into integration test
alessio-perugini Sep 14, 2023
6e358dc
ported SketchClassFunction from legacy into integration test
alessio-perugini Sep 14, 2023
26c9c95
ported SketchThatChecksIfSPIHasTransactionsAndIncludesMissingEthernet…
alessio-perugini Sep 14, 2023
0bf2756
remove legacy builder test folder
alessio-perugini Sep 14, 2023
1a6d693
remove unsued fields from context
alessio-perugini Sep 14, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ venv
/dist
/.pytest-tmp-dir
/node_modules/
__debug_bin*

# gRPC client example folder
/client_example/client_example
Expand Down
273 changes: 273 additions & 0 deletions internal/integrationtest/compile_4/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
"go.bug.st/testifyjson/requirejson"
"golang.org/x/exp/slices"
)

Expand Down Expand Up @@ -63,6 +64,8 @@ func TestCompileOfProblematicSketches(t *testing.T) {
require.NoError(t, err)
_, _, err = cli.Run("lib", "install", "[email protected]")
require.NoError(t, err)
_, _, err = cli.Run("lib", "install", "[email protected]")
require.NoError(t, err)

// Install custom hardware required for tests
customHwDir, err := paths.New("..", "testdata", "user_hardware").Abs()
Expand Down Expand Up @@ -99,12 +102,24 @@ func TestCompileOfProblematicSketches(t *testing.T) {
{"SketchNoFunctionsTwoFiles", testBuilderSketchNoFunctionsTwoFiles},
{"SketchWithClassAndMethodSubstring", testBuilderSketchWithClassAndMethodSubstring},
{"SketchThatChecksIfSPIHasTransactions", tryBuildAvrLeonardo},
{"SketchThatChecksIfSPIHasTransactionsAndIncludesMissingEthernet", testBuilderSketchThatChecksIfSPIHasTransactionsAndIncludesMissingEthernet},
{"SketchWithDependendLibraries", tryBuildAvrLeonardo},
{"SketchWithFunctionPointer", tryBuildAvrLeonardo},
{"USBHostExample", testBuilderUSBHostExample},
{"SketchWithConflictingLibraries", testBuilderSketchWithConflictingLibraries},
{"SketchLibraryProvidesAllIncludes", testBuilderSketchLibraryProvidesAllIncludes},
{"UserHardware", testBuilderWithUserHardware},
{"SketchThatIncludesArduinoH", testBuilderSketchThatIncludesArduinoH},
{"SketchWithStaticAsserts", testBuilderSketchWithStaticAsserts},
{"SketchWithEnumClass", testBuilderSketchWithEnumClass},
{"SketchWithExternC", testBuilderSketchWithExternC},
{"SketchWithMultilinePrototypes", testBuilderSketchWithMultilinePrototypes},
{"SketchWithExternCMultiline", testBuilderSketchWithExternCMultiline},
{"SketchWithMultilineTemplate", testBuilderSketchWithMultilineTemplate},
{"SketchWithFakeFunctionPointer", testBuilderSketchWithFakeFunctionPointer},
{"SketchWithMinMaxDefinitions", testBuilderSketchWithMinMaxDefinitions},
{"SketchWithFastledsLibrary", testBuilderSketchWithFastledsLibrary},
{"SketchClassFunction", testBuilderSketchClassFunction},
}.Run(t, env, cli)
}

Expand Down Expand Up @@ -613,6 +628,179 @@ func tryBuildAvrLeonardo(t *testing.T, env *integrationtest.Environment, cli *in
require.NoError(t, err)
}

func testBuilderSketchThatIncludesArduinoH(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithStaticAsserts(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithEnumClass(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithExternC(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithMultilinePrototypes(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithExternCMultiline(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithMultilineTemplate(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithFakeFunctionPointer(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithMinMaxDefinitions(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:samd:arduino_zero_native")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:samd:arduino_zero_native")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithFastledsLibrary(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:samd:arduino_zero_native")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:samd:arduino_zero_native")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchClassFunction(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchThatChecksIfSPIHasTransactionsAndIncludesMissingEthernet(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.Error(t, err)
})
}

type builderOutput struct {
CompilerOut string `json:"compiler_out"`
CompilerErr string `json:"compiler_err"`
Expand Down Expand Up @@ -765,3 +953,88 @@ func TestCoreCaching(t *testing.T) {
require.NoError(t, err)
require.NotEqual(t, coreStatBefore.ModTime(), coreStatAfterTouch.ModTime())
}

func TestMergeSketchWithBootloader(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

sketchPath, err := paths.New("testdata", "SketchWithMergedSketchAndBootloader").Abs()
require.NoError(t, err)

// Install Arduino AVR Boards
_, _, err = cli.Run("core", "install", "arduino:[email protected]")
require.NoError(t, err)

buildPath, err := paths.MkTempDir("", "arduino-integration-test")
require.NoError(t, err)
defer buildPath.RemoveAll()

// Build first time
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
require.NoError(t, err)

bytes, err := buildPath.Join("SketchWithMergedSketchAndBootloader.ino.with_bootloader.hex").ReadFile()
require.NoError(t, err)
mergedSketchHex := string(bytes)

require.Contains(t, mergedSketchHex, ":100000000C9434000C9446000C9446000C9446006A\n")
require.True(t, strings.HasSuffix(mergedSketchHex, ":00000001FF\n"))
}

func TestBuildOptionsFile(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

sketchPath := cli.CopySketch("sketch_simple")
defer sketchPath.RemoveAll()

_, _, err := cli.Run("core", "install", "arduino:[email protected]")
require.NoError(t, err)

buildPath, err := paths.MkTempDir("", "arduino-integration-test")
require.NoError(t, err)
defer buildPath.RemoveAll()

// Build first time
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
require.NoError(t, err)

exist, err := buildPath.Join("build.options.json").ExistCheck()
require.NoError(t, err)
require.True(t, exist)

buildOptionsBytes, err := buildPath.Join("build.options.json").ReadFile()
require.NoError(t, err)

requirejson.Query(t, buildOptionsBytes, "keys", `[
"additionalFiles",
"builtInToolsFolders",
"compiler.optimization_flags",
"customBuildProperties",
"fqbn",
"hardwareFolders",
"otherLibrariesFolders",
"sketchLocation"
]`)
requirejson.Query(t, buildOptionsBytes, ".fqbn", `"arduino:avr:uno"`)
requirejson.Query(t, buildOptionsBytes, ".customBuildProperties", `"build.warn_data_percentage=75"`)

// Recompiling a second time should provide the same result
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
require.NoError(t, err)

buildOptionsBytes, err = buildPath.Join("build.options.json").ReadFile()
require.NoError(t, err)
requirejson.Query(t, buildOptionsBytes, ".customBuildProperties", `"build.warn_data_percentage=75"`)

// Recompiling with a new build option must produce a new `build.options.json`
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(),
"--build-property", "custom=prop",
sketchPath.String(),
)
require.NoError(t, err)

buildOptionsBytes, err = buildPath.Join("build.options.json").ReadFile()
require.NoError(t, err)
requirejson.Query(t, buildOptionsBytes, ".customBuildProperties", `"custom=prop,build.warn_data_percentage=75"`)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <Arduino.h>
#line 1 {{QuoteCppString .sketchMainFile}}
class test {
void asdf() {}
};
#line 4 {{QuoteCppString .sketchMainFile}}
void setup();
#line 7 {{QuoteCppString .sketchMainFile}}
void loop();
#line 8 {{QuoteCppString .sketchMainFile}}
void asdf();
#line 4 {{QuoteCppString .sketchMainFile}}
void setup() {
asdf();
}
void loop() {}
void asdf() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#line 1 {{QuoteCppString .sketchMainFile}}
// Arduino.h should not be automatically included by the Arduino
// preprocessor before the explicit include line in this sketch.

#if defined(HIGH)
#error Arduino.h seems to be automatically included
#endif

# include <Arduino.h>

#line 10 {{QuoteCppString .sketchMainFile}}
void setup();
#line 13 {{QuoteCppString .sketchMainFile}}
void loop();
#line 10 {{QuoteCppString .sketchMainFile}}
void setup() {
}

void loop() {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <Arduino.h>
#line 1 {{QuoteCppString .sketchMainFile}}
#line 1 {{QuoteCppString .sketchMainFile}}
void test();
#line 11 {{QuoteCppString .sketchMainFile}}
void test2();
#line 14 {{QuoteCppString .sketchMainFile}}
void setup();
#line 17 {{QuoteCppString .sketchMainFile}}
void loop();
#line 1 {{QuoteCppString .sketchMainFile}}
void test() {
test2();
}

enum class MyEnum
{
AValue = 0,
AnotherValue = 1
};

void test2() {
}

void setup() {
}

void loop() {
}


Loading