From 54360c341255dd6a33b6b46e66d4d8b107243e07 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Wed, 13 Sep 2023 14:55:50 +0200 Subject: [PATCH] ported SketchWithFastledsLibrary from legacy into integration test --- .../integrationtest/compile_4/compile_test.go | 19 +++++++ .../SketchFastleds/SketchFastleds.ino | 0 .../SketchFastleds.preprocessed.txt | 37 +++++++++++++ .../try_build_of_problematic_sketch_test.go | 53 ------------------- 4 files changed, 56 insertions(+), 53 deletions(-) rename legacy/builder/test/sketch_fastleds/sketch_fastleds.ino => internal/integrationtest/compile_4/testdata/SketchFastleds/SketchFastleds.ino (100%) create mode 100644 internal/integrationtest/compile_4/testdata/SketchFastleds/SketchFastleds.preprocessed.txt delete mode 100644 legacy/builder/test/try_build_of_problematic_sketch_test.go diff --git a/internal/integrationtest/compile_4/compile_test.go b/internal/integrationtest/compile_4/compile_test.go index dc650d5692b..485e2962cd1 100644 --- a/internal/integrationtest/compile_4/compile_test.go +++ b/internal/integrationtest/compile_4/compile_test.go @@ -63,6 +63,8 @@ func TestCompileOfProblematicSketches(t *testing.T) { require.NoError(t, err) _, _, err = cli.Run("lib", "install", "CapacitiveSensor@0.5") require.NoError(t, err) + _, _, err = cli.Run("lib", "install", "FastLED@3.1.0") + require.NoError(t, err) // Install custom hardware required for tests customHwDir, err := paths.New("..", "testdata", "user_hardware").Abs() @@ -114,6 +116,7 @@ func TestCompileOfProblematicSketches(t *testing.T) { {"SketchWithMultilineTemplate", testBuilderSketchWithMultilineTemplate}, {"SketchWithFakeFunctionPointer", testBuilderSketchWithFakeFunctionPointer}, {"SketchWithMinMaxDefinitions", testBuilderSketchWithMinMaxDefinitions}, + {"SketchWithFastledsLibrary", testBuilderSketchWithFastledsLibrary}, }.Run(t, env, cli) } @@ -757,6 +760,22 @@ func testBuilderSketchWithMinMaxDefinitions(t *testing.T, env *integrationtest.E }) } +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) + }) +} + + type builderOutput struct { CompilerOut string `json:"compiler_out"` CompilerErr string `json:"compiler_err"` diff --git a/legacy/builder/test/sketch_fastleds/sketch_fastleds.ino b/internal/integrationtest/compile_4/testdata/SketchFastleds/SketchFastleds.ino similarity index 100% rename from legacy/builder/test/sketch_fastleds/sketch_fastleds.ino rename to internal/integrationtest/compile_4/testdata/SketchFastleds/SketchFastleds.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchFastleds/SketchFastleds.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchFastleds/SketchFastleds.preprocessed.txt new file mode 100644 index 00000000000..e770d0c709b --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchFastleds/SketchFastleds.preprocessed.txt @@ -0,0 +1,37 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +#include "FastLED.h" + +#define DATA_PIN 7 +#define CLK_PIN 6 +#define LED_TYPE APA102 +#define COLOR_ORDER GRB +#define NUM_LEDS 79 +CRGB leds[NUM_LEDS]; + +#define BRIGHTNESS 96 +#define FRAMES_PER_SECOND 120 +#line 12 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 17 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 25 {{QuoteCppString .sketchMainFile}} +void sinelon(); +#line 12 {{QuoteCppString .sketchMainFile}} +void setup() { + + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); +} + +void loop() { + +} + +typedef void (*SimplePatternList[])(); +//SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; +SimplePatternList gPatterns = {sinelon}; + +void sinelon() +{ +} + diff --git a/legacy/builder/test/try_build_of_problematic_sketch_test.go b/legacy/builder/test/try_build_of_problematic_sketch_test.go deleted file mode 100644 index f573cb41977..00000000000 --- a/legacy/builder/test/try_build_of_problematic_sketch_test.go +++ /dev/null @@ -1,53 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) -// Copyright 2015 Matthijs Kooijman -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package test - -import ( - "path/filepath" - "testing" - - "github.com/arduino/arduino-cli/arduino/builder/preprocessor" - "github.com/arduino/arduino-cli/legacy/builder" - "github.com/arduino/arduino-cli/legacy/builder/types" - paths "github.com/arduino/go-paths-helper" - "github.com/stretchr/testify/require" -) - -// TODO add them in the compile_4 - -func TestTryBuild036(t *testing.T) { - ctx := makeDefaultContext() - tryBuildWithContext(t, ctx, "arduino:samd:arduino_zero_native", paths.New("sketch_fastleds", "sketch_fastleds.ino")) -} - -func makeDefaultContext() *types.Context { - preprocessor.DebugPreprocessor = true - return &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), - BuiltInLibrariesDirs: paths.New("downloaded_libraries"), - OtherLibrariesDirs: paths.NewPathList("libraries"), - } -} - -func tryBuildWithContext(t *testing.T, ctx *types.Context, fqbn string, sketchLocation *paths.Path) { - ctx = prepareBuilderTestContext(t, ctx, sketchLocation, fqbn) - defer cleanUpBuilderTestContext(t, ctx) - - err := builder.RunBuilder(ctx) - require.NoError(t, err, "Build error for "+sketchLocation.String()) -}