diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index 9b5dfb1d402..5750189bead 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -146,6 +146,11 @@ func (cli *ArduinoCLI) DownloadDir() *paths.Path { return cli.stagingDir } +// SetWorkingDir sets a new working directory +func (cli *ArduinoCLI) SetWorkingDir(p *paths.Path) { + cli.workingDir = p +} + // CopySketch copies a sketch inside the testing environment and returns its path func (cli *ArduinoCLI) CopySketch(sketchName string) *paths.Path { p, err := paths.Getwd() diff --git a/internal/integrationtest/compile/compile_part_1_test.go b/internal/integrationtest/compile/compile_part_1_test.go index 203ce88ac90..ad2d8a8adb4 100644 --- a/internal/integrationtest/compile/compile_part_1_test.go +++ b/internal/integrationtest/compile/compile_part_1_test.go @@ -57,6 +57,12 @@ func TestCompile(t *testing.T) { {"WithExportBinariesEnvVar", compileWithExportBinariesEnvVar}, {"WithExportBinariesConfig", compileWithExportBinariesConfig}, {"WithInvalidUrl", compileWithInvalidUrl}, + {"WithPdeExtension", compileWithPdeExtension}, + {"WithMultipleMainFiles", compileWithMultipleMainFiles}, + {"CaseMismatchFails", compileCaseMismatchFails}, + {"OnlyCompilationDatabaseFlag", compileOnlyCompilationDatabaseFlag}, + {"UsingPlatformLocalTxt", compileUsingPlatformLocalTxt}, + {"UsingBoardsLocalTxt", compileUsingBoardsLocalTxt}, }.Run(t, env, cli) } @@ -526,3 +532,182 @@ func compileWithInvalidUrl(t *testing.T, env *integrationtest.Environment, cli * expectedIndexfile := cli.DataDir().Join("package_example_index.json") require.Contains(t, string(stderr), "loading json index file "+expectedIndexfile.String()+": open "+expectedIndexfile.String()+":") } + +func compileWithPdeExtension(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + sketchName := "CompilePdeSketch" + sketchPath := cli.SketchbookDir().Join(sketchName) + defer sketchPath.RemoveAll() + fqbn := "arduino:avr:uno" + + // Create a test sketch + _, _, err := cli.Run("sketch", "new", sketchPath.String()) + require.NoError(t, err) + + // Renames sketch file to pde + sketchFileIno := sketchPath.Join(sketchName + ".ino") + sketchFilePde := sketchPath.Join(sketchName + ".pde") + err = sketchFileIno.Rename(sketchFilePde) + require.NoError(t, err) + + // Build sketch from folder + _, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String()) + require.NoError(t, err) + require.Contains(t, string(stderr), "Sketches with .pde extension are deprecated, please rename the following files to .ino:") + require.Contains(t, string(stderr), sketchFilePde.String()) + + // Build sketch from file + _, stderr, err = cli.Run("compile", "--clean", "-b", fqbn, sketchFilePde.String()) + require.NoError(t, err) + require.Contains(t, string(stderr), "Sketches with .pde extension are deprecated, please rename the following files to .ino:") + require.Contains(t, string(stderr), sketchFilePde.String()) +} + +func compileWithMultipleMainFiles(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + sketchName := "CompileSketchMultipleMainFiles" + sketchPath := cli.SketchbookDir().Join(sketchName) + defer sketchPath.RemoveAll() + fqbn := "arduino:avr:uno" + + // Create a test sketch + _, _, err := cli.Run("sketch", "new", sketchPath.String()) + require.NoError(t, err) + + // Copy .ino sketch file to .pde + sketchFileIno := sketchPath.Join(sketchName + ".ino") + sketchFilePde := sketchPath.Join(sketchName + ".pde") + err = sketchFileIno.CopyTo(sketchFilePde) + require.NoError(t, err) + + // Build sketch from folder + _, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String()) + require.Error(t, err) + require.Contains(t, string(stderr), "Error opening sketch: multiple main sketch files found") + + // Build sketch from .ino file + _, stderr, err = cli.Run("compile", "--clean", "-b", fqbn, sketchFileIno.String()) + require.Error(t, err) + require.Contains(t, string(stderr), "Error opening sketch: multiple main sketch files found") + + // Build sketch from .pde file + _, stderr, err = cli.Run("compile", "--clean", "-b", fqbn, sketchFilePde.String()) + require.Error(t, err) + require.Contains(t, string(stderr), "Error opening sketch: multiple main sketch files found") +} + +func compileCaseMismatchFails(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + sketchName := "CompileSketchCaseMismatch" + sketchPath := cli.SketchbookDir().Join(sketchName) + defer sketchPath.RemoveAll() + fqbn := "arduino:avr:uno" + + _, _, err := cli.Run("sketch", "new", sketchPath.String()) + require.NoError(t, err) + + // Rename main .ino file so casing is different from sketch name + sketchFile := sketchPath.Join(sketchName + ".ino") + sketchMainFile := sketchPath.Join(strings.ToLower(sketchName) + ".ino") + err = sketchFile.Rename(sketchMainFile) + require.NoError(t, err) + + // Verifies compilation fails when: + // * Compiling with sketch path + _, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String()) + require.Error(t, err) + require.Contains(t, string(stderr), "Error opening sketch:") + // * Compiling with sketch main file + _, stderr, err = cli.Run("compile", "--clean", "-b", fqbn, sketchMainFile.String()) + require.Error(t, err) + require.Contains(t, string(stderr), "Error opening sketch:") + // * Compiling in sketch path + cli.SetWorkingDir(sketchPath) + defer cli.SetWorkingDir(env.RootDir()) + _, stderr, err = cli.Run("compile", "--clean", "-b", fqbn) + require.Error(t, err) + require.Contains(t, string(stderr), "Error opening sketch:") +} + +func compileOnlyCompilationDatabaseFlag(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + sketchName := "CompileSketchOnlyCompilationDatabaseFlag" + sketchPath := cli.SketchbookDir().Join(sketchName) + defer sketchPath.RemoveAll() + fqbn := "arduino:avr:uno" + + _, _, err := cli.Run("sketch", "new", sketchPath.String()) + require.NoError(t, err) + + // Verifies no binaries exist + buildPath := sketchPath.Join("build") + require.NoDirExists(t, buildPath.String()) + + // Compile with both --export-binaries and --only-compilation-database flags + _, _, err = cli.Run("compile", "--export-binaries", "--only-compilation-database", "--clean", "-b", fqbn, sketchPath.String()) + require.NoError(t, err) + + // Verifies no binaries are exported + require.NoDirExists(t, buildPath.String()) + + // Verifies no binaries exist + buildPath = cli.SketchbookDir().Join("export-dir") + require.NoDirExists(t, buildPath.String()) + + // Compile by setting the --output-dir flag and --only-compilation-database flags + _, _, err = cli.Run("compile", "--output-dir", buildPath.String(), "--only-compilation-database", "--clean", "-b", fqbn, sketchPath.String()) + require.NoError(t, err) + + // Verifies no binaries are exported + require.NoDirExists(t, buildPath.String()) +} + +func compileUsingPlatformLocalTxt(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + sketchName := "CompileSketchUsingPlatformLocalTxt" + sketchPath := cli.SketchbookDir().Join(sketchName) + defer sketchPath.RemoveAll() + fqbn := "arduino:avr:uno" + + _, _, err := cli.Run("sketch", "new", sketchPath.String()) + require.NoError(t, err) + + // Verifies compilation works without issues + _, _, err = cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String()) + require.NoError(t, err) + + // Overrides default platform compiler with an unexisting one + platformLocalTxt := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.5", "platform.local.txt") + err = platformLocalTxt.WriteFile([]byte("compiler.c.cmd=my-compiler-that-does-not-exist")) + require.NoError(t, err) + // Remove the file at the end of the test to avoid disrupting following tests + defer platformLocalTxt.Remove() + + // Verifies compilation now fails because compiler is not found + _, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String()) + require.Error(t, err) + require.Contains(t, string(stderr), "my-compiler-that-does-not-exist") +} + +func compileUsingBoardsLocalTxt(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + sketchName := "CompileSketchUsingBoardsLocalTxt" + sketchPath := cli.SketchbookDir().Join(sketchName) + defer sketchPath.RemoveAll() + // Usa a made up board + fqbn := "arduino:avr:nessuno" + + _, _, err := cli.Run("sketch", "new", sketchPath.String()) + require.NoError(t, err) + + // Verifies compilation fails because board doesn't exist + _, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String()) + require.Error(t, err) + require.Contains(t, string(stderr), "Error during build: Error resolving FQBN: board arduino:avr:nessuno not found") + + // Use custom boards.local.txt with made arduino:avr:nessuno board + boardsLocalTxt := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.5", "boards.local.txt") + wd, err := paths.Getwd() + require.NoError(t, err) + err = wd.Parent().Join("testdata", "boards.local.txt").CopyTo(boardsLocalTxt) + require.NoError(t, err) + // Remove the file at the end of the test to avoid disrupting following tests + defer boardsLocalTxt.Remove() + + _, _, err = cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String()) + require.NoError(t, err) +} diff --git a/internal/integrationtest/compile/compile_part_3_test.go b/internal/integrationtest/compile/compile_part_3_test.go new file mode 100644 index 00000000000..c95d645cfc6 --- /dev/null +++ b/internal/integrationtest/compile/compile_part_3_test.go @@ -0,0 +1,133 @@ +// This file is part of arduino-cli. +// +// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) +// +// 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 compile_test + +import ( + "testing" + + "github.com/arduino/arduino-cli/internal/integrationtest" + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" + "gopkg.in/src-d/go-git.v4" + "gopkg.in/src-d/go-git.v4/plumbing" +) + +func TestCompileWithFullyPrecompiledLibrary(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("update") + require.NoError(t, err) + + _, _, err = cli.Run("core", "install", "arduino:mbed@1.3.1") + require.NoError(t, err) + fqbn := "arduino:mbed:nano33ble" + + // Create settings with library unsafe install set to true + envVar := cli.GetDefaultEnv() + envVar["ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL"] = "true" + _, _, err = cli.RunWithCustomEnv(envVar, "config", "init", "--dest-dir", ".") + require.NoError(t, err) + + // Install fully precompiled library + // For more information see: + // https://arduino.github.io/arduino-cli/latest/library-specification/#precompiled-binaries + wd, err := paths.Getwd() + require.NoError(t, err) + _, _, err = cli.Run("lib", "install", "--zip-path", wd.Parent().Join("testdata", "Arduino_TensorFlowLite-2.1.0-ALPHA-precompiled.zip").String()) + require.NoError(t, err) + sketchFolder := cli.SketchbookDir().Join("libraries", "Arduino_TensorFlowLite-2.1.0-ALPHA-precompiled", "examples", "hello_world") + + // Install example dependency + _, _, err = cli.Run("lib", "install", "Arduino_LSM9DS1") + require.NoError(t, err) + + // Compile and verify dependencies detection for fully precompiled library is skipped + stdout, _, err := cli.Run("compile", "-b", fqbn, sketchFolder.String(), "-v") + require.NoError(t, err) + require.Contains(t, string(stdout), "Skipping dependencies detection for precompiled library Arduino_TensorFlowLite") +} + +func TestCompileManuallyInstalledPlatform(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("update") + require.NoError(t, err) + + sketchName := "CompileSketchManuallyInstalledPlatformUsingPlatformLocalTxt" + sketchPath := cli.SketchbookDir().Join(sketchName) + fqbn := "arduino-beta-development:avr:uno" + _, _, err = cli.Run("sketch", "new", sketchPath.String()) + require.NoError(t, err) + + // Manually installs a core in sketchbooks hardware folder + gitUrl := "https://github.com/arduino/ArduinoCore-avr.git" + repoDir := cli.SketchbookDir().Join("hardware", "arduino-beta-development", "avr") + _, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{ + URL: gitUrl, + ReferenceName: plumbing.NewTagReferenceName("1.8.3"), + }) + require.NoError(t, err) + + // Installs also the same core via CLI so all the necessary tools are installed + _, _, err = cli.Run("core", "install", "arduino:avr@1.8.3") + require.NoError(t, err) + + // Verifies compilation works without issues + _, _, err = cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String()) + require.NoError(t, err) +} + +func TestCompileManuallyInstalledPlatformUsingPlatformLocalTxt(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("update") + require.NoError(t, err) + + sketchName := "CompileSketchManuallyInstalledPlatformUsingPlatformLocalTxt" + sketchPath := cli.SketchbookDir().Join(sketchName) + fqbn := "arduino-beta-development:avr:uno" + _, _, err = cli.Run("sketch", "new", sketchPath.String()) + require.NoError(t, err) + + // Manually installs a core in sketchbooks hardware folder + gitUrl := "https://github.com/arduino/ArduinoCore-avr.git" + repoDir := cli.SketchbookDir().Join("hardware", "arduino-beta-development", "avr") + _, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{ + URL: gitUrl, + ReferenceName: plumbing.NewTagReferenceName("1.8.3"), + }) + require.NoError(t, err) + + // Installs also the same core via CLI so all the necessary tools are installed + _, _, err = cli.Run("core", "install", "arduino:avr@1.8.3") + require.NoError(t, err) + + // Verifies compilation works without issues + _, _, err = cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String()) + require.NoError(t, err) + + // Overrides default platform compiler with an unexisting one + platformLocalTxt := repoDir.Join("platform.local.txt") + platformLocalTxt.WriteFile([]byte("compiler.c.cmd=my-compiler-that-does-not-exist")) + + // Verifies compilation now fails because compiler is not found + _, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String()) + require.Error(t, err) + require.Contains(t, string(stderr), "my-compiler-that-does-not-exist") +} diff --git a/internal/integrationtest/testdata/Arduino_TensorFlowLite-2.1.0-ALPHA-precompiled.zip b/internal/integrationtest/testdata/Arduino_TensorFlowLite-2.1.0-ALPHA-precompiled.zip new file mode 100644 index 00000000000..d5b8529ce00 Binary files /dev/null and b/internal/integrationtest/testdata/Arduino_TensorFlowLite-2.1.0-ALPHA-precompiled.zip differ diff --git a/internal/integrationtest/testdata/boards.local.txt b/internal/integrationtest/testdata/boards.local.txt new file mode 100644 index 00000000000..ac8dc604b06 --- /dev/null +++ b/internal/integrationtest/testdata/boards.local.txt @@ -0,0 +1,26 @@ +nessuno.name=Arduino Nessuno +nessuno.vid.0=0x2341 +nessuno.pid.0=0x0043 +nessuno.vid.1=0x2341 +nessuno.pid.1=0x0001 +nessuno.vid.2=0x2A03 +nessuno.pid.2=0x0043 +nessuno.vid.3=0x2341 +nessuno.pid.3=0x0243 +nessuno.upload.tool=avrdude +nessuno.upload.protocol=arduino +nessuno.upload.maximum_size=32256 +nessuno.upload.maximum_data_size=2048 +nessuno.upload.speed=115200 +nessuno.bootloader.tool=avrdude +nessuno.bootloader.low_fuses=0xFF +nessuno.bootloader.high_fuses=0xDE +nessuno.bootloader.extended_fuses=0xFD +nessuno.bootloader.unlock_bits=0x3F +nessuno.bootloader.lock_bits=0x0F +nessuno.bootloader.file=optiboot/optiboot_atmega328.hex +nessuno.build.mcu=atmega328p +nessuno.build.f_cpu=16000000L +nessuno.build.board=AVR_NESSUNO +nessuno.build.core=arduino +nessuno.build.variant=standard \ No newline at end of file diff --git a/test/test_compile_part_3.py b/test/test_compile_part_3.py deleted file mode 100644 index 345c0069174..00000000000 --- a/test/test_compile_part_3.py +++ /dev/null @@ -1,268 +0,0 @@ -# This file is part of arduino-cli. -# -# Copyright 2020 ARDUINO SA (http://www.arduino.cc/) -# -# 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. - -import shutil -from git import Repo -from pathlib import Path - - -# def test_compile_with_fully_precompiled_library(run_command, data_dir): -# assert run_command(["update"]) -# -# assert run_command(["core", "install", "arduino:mbed@1.3.1"]) -# fqbn = "arduino:mbed:nano33ble" -# -# # Install fully precompiled library -# # For more information see: -# # https://arduino.github.io/arduino-cli/latest/library-specification/#precompiled-binaries -# assert run_command(["lib", "install", "Arduino_TensorFlowLite@2.1.1-ALPHA-precompiled"]) -# sketch_folder = Path(data_dir, "libraries", "Arduino_TensorFlowLite", "examples", "hello_world") -# -# # Install example dependency -# # assert run_command("lib install Arduino_LSM9DS1")# -# -# # Compile and verify dependencies detection for fully precompiled library is skipped -# result = run_command(["compile", "-b", fqbn, sketch_folder, "-v"]) -# assert result.ok -# assert "Skipping dependencies detection for precompiled library Arduino_TensorFlowLite" in result.stdout - - -def test_compile_sketch_with_pde_extension(run_command, data_dir): - # Init the environment explicitly - assert run_command(["update"]) - - # Install core to compile - assert run_command(["core", "install", "arduino:avr@1.8.3"]) - - sketch_name = "CompilePdeSketch" - sketch_path = Path(data_dir, sketch_name) - fqbn = "arduino:avr:uno" - - # Create a test sketch - assert run_command(["sketch", "new", sketch_path]) - - # Renames sketch file to pde - sketch_file = Path(sketch_path, f"{sketch_name}.ino").rename(sketch_path / f"{sketch_name}.pde") - - # Build sketch from folder - res = run_command(["compile", "--clean", "-b", fqbn, sketch_path]) - assert res.ok - assert "Sketches with .pde extension are deprecated, please rename the following files to .ino:" in res.stderr - assert str(sketch_file) in res.stderr - - # Build sketch from file - res = run_command(["compile", "--clean", "-b", fqbn, sketch_file]) - assert res.ok - assert "Sketches with .pde extension are deprecated, please rename the following files to .ino" in res.stderr - assert str(sketch_file) in res.stderr - - -def test_compile_sketch_with_multiple_main_files(run_command, data_dir): - # Init the environment explicitly - assert run_command(["update"]) - - # Install core to compile - assert run_command(["core", "install", "arduino:avr@1.8.3"]) - - sketch_name = "CompileSketchMultipleMainFiles" - sketch_path = Path(data_dir, sketch_name) - fqbn = "arduino:avr:uno" - - # Create a test sketch - assert run_command(["sketch", "new", sketch_path]) - - # Copy .ino sketch file to .pde - sketch_ino_file = Path(sketch_path, f"{sketch_name}.ino") - sketch_pde_file = Path(sketch_path / f"{sketch_name}.pde") - shutil.copyfile(sketch_ino_file, sketch_pde_file) - - # Build sketch from folder - res = run_command(["compile", "--clean", "-b", fqbn, sketch_path]) - assert res.failed - assert "Error opening sketch: multiple main sketch files found" in res.stderr - - # Build sketch from .ino file - res = run_command(["compile", "--clean", "-b", fqbn, sketch_ino_file]) - assert res.failed - assert "Error opening sketch: multiple main sketch files found" in res.stderr - - # Build sketch from .pde file - res = run_command(["compile", "--clean", "-b", fqbn, sketch_pde_file]) - assert res.failed - assert "Error opening sketch: multiple main sketch files found" in res.stderr - - -def test_compile_sketch_case_mismatch_fails(run_command, data_dir): - # Init the environment explicitly - assert run_command(["update"]) - - # Install core to compile - assert run_command(["core", "install", "arduino:avr@1.8.3"]) - - sketch_name = "CompileSketchCaseMismatch" - sketch_path = Path(data_dir, sketch_name) - fqbn = "arduino:avr:uno" - - assert run_command(["sketch", "new", sketch_path]) - - # Rename main .ino file so casing is different from sketch name - sketch_main_file = Path(sketch_path, f"{sketch_name}.ino").rename(sketch_path / f"{sketch_name.lower()}.ino") - - # Verifies compilation fails when: - # * Compiling with sketch path - res = run_command(["compile", "--clean", "-b", fqbn, sketch_path]) - assert res.failed - assert "Error opening sketch:" in res.stderr - # * Compiling with sketch main file - res = run_command(["compile", "--clean", "-b", fqbn, sketch_main_file]) - assert res.failed - assert "Error opening sketch:" in res.stderr - # * Compiling in sketch path - res = run_command(["compile", "--clean", "-b", fqbn], custom_working_dir=sketch_path) - assert res.failed - assert "Error opening sketch:" in res.stderr - - -def test_compile_with_only_compilation_database_flag(run_command, data_dir): - assert run_command(["update"]) - - assert run_command(["core", "install", "arduino:avr@1.8.3"]) - - sketch_name = "CompileSketchOnlyCompilationDatabaseFlag" - sketch_path = Path(data_dir, sketch_name) - fqbn = "arduino:avr:uno" - - assert run_command(["sketch", "new", sketch_path]) - - # Verifies no binaries exist - build_path = Path(sketch_path, "build") - assert not build_path.exists() - - # Compile with both --export-binaries and --only-compilation-database flags - assert run_command( - ["compile", "--export-binaries", "--only-compilation-database", "--clean", "-b", fqbn, sketch_path] - ) - - # Verifies no binaries are exported - assert not build_path.exists() - - # Verifies no binaries exist - build_path = Path(data_dir, "export-dir") - assert not build_path.exists() - - # Compile by setting the --output-dir flag and --only-compilation-database flags - assert run_command( - ["compile", "--output-dir", build_path, "--only-compilation-database", "--clean", "-b", fqbn, sketch_path] - ) - - # Verifies no binaries are exported - assert not build_path.exists() - - -def test_compile_using_platform_local_txt(run_command, data_dir): - assert run_command(["update"]) - - assert run_command(["core", "install", "arduino:avr@1.8.3"]) - - sketch_name = "CompileSketchUsingPlatformLocalTxt" - sketch_path = Path(data_dir, sketch_name) - fqbn = "arduino:avr:uno" - - assert run_command(["sketch", "new", sketch_path]) - - # Verifies compilation works without issues - assert run_command(["compile", "--clean", "-b", fqbn, sketch_path]) - - # Overrides default platform compiler with an unexisting one - platform_local_txt = Path(data_dir, "packages", "arduino", "hardware", "avr", "1.8.3", "platform.local.txt") - platform_local_txt.write_text("compiler.c.cmd=my-compiler-that-does-not-exist") - - # Verifies compilation now fails because compiler is not found - res = run_command(["compile", "--clean", "-b", fqbn, sketch_path]) - assert res.failed - assert "my-compiler-that-does-not-exist" in res.stderr - - -def test_compile_using_boards_local_txt(run_command, data_dir): - assert run_command(["update"]) - - assert run_command(["core", "install", "arduino:avr@1.8.3"]) - - sketch_name = "CompileSketchUsingBoardsLocalTxt" - sketch_path = Path(data_dir, sketch_name) - # Use a made up board - fqbn = "arduino:avr:nessuno" - - assert run_command(["sketch", "new", sketch_path]) - - # Verifies compilation fails because board doesn't exist - res = run_command(["compile", "--clean", "-b", fqbn, sketch_path]) - assert res.failed - assert "Error during build: Error resolving FQBN: board arduino:avr:nessuno not found" in res.stderr - - # Use custom boards.local.txt with made arduino:avr:nessuno board - boards_local_txt = Path(data_dir, "packages", "arduino", "hardware", "avr", "1.8.3", "boards.local.txt") - shutil.copyfile(Path(__file__).parent / "testdata" / "boards.local.txt", boards_local_txt) - - assert run_command(["compile", "--clean", "-b", fqbn, sketch_path]) - - -def test_compile_manually_installed_platform(run_command, data_dir): - assert run_command(["update"]) - - sketch_name = "CompileSketchManuallyInstalledPlatformUsingPlatformLocalTxt" - sketch_path = Path(data_dir, sketch_name) - fqbn = "arduino-beta-development:avr:uno" - assert run_command(["sketch", "new", sketch_path]) - - # Manually installs a core in sketchbooks hardware folder - git_url = "https://github.com/arduino/ArduinoCore-avr.git" - repo_dir = Path(data_dir, "hardware", "arduino-beta-development", "avr") - assert Repo.clone_from(git_url, repo_dir, multi_options=["-b 1.8.3"]) - - # Installs also the same core via CLI so all the necessary tools are installed - assert run_command(["core", "install", "arduino:avr@1.8.3"]) - - # Verifies compilation works without issues - assert run_command(["compile", "--clean", "-b", fqbn, sketch_path]) - - -def test_compile_manually_installed_platform_using_platform_local_txt(run_command, data_dir): - assert run_command(["update"]) - - sketch_name = "CompileSketchManuallyInstalledPlatformUsingPlatformLocalTxt" - sketch_path = Path(data_dir, sketch_name) - fqbn = "arduino-beta-development:avr:uno" - assert run_command(["sketch", "new", sketch_path]) - - # Manually installs a core in sketchbooks hardware folder - git_url = "https://github.com/arduino/ArduinoCore-avr.git" - repo_dir = Path(data_dir, "hardware", "arduino-beta-development", "avr") - assert Repo.clone_from(git_url, repo_dir, multi_options=["-b 1.8.3"]) - - # Installs also the same core via CLI so all the necessary tools are installed - assert run_command(["core", "install", "arduino:avr@1.8.3"]) - - # Verifies compilation works without issues - assert run_command(["compile", "--clean", "-b", fqbn, sketch_path]) - - # Overrides default platform compiler with an unexisting one - platform_local_txt = Path(repo_dir, "platform.local.txt") - platform_local_txt.write_text("compiler.c.cmd=my-compiler-that-does-not-exist") - - # Verifies compilation now fails because compiler is not found - res = run_command(["compile", "--clean", "-b", fqbn, sketch_path]) - assert res.failed - assert "my-compiler-that-does-not-exist" in res.stderr