diff --git a/.github/workflows/test-go-task.yml b/.github/workflows/test-go-task.yml index d8266519e59..836940ef262 100644 --- a/.github/workflows/test-go-task.yml +++ b/.github/workflows/test-go-task.yml @@ -4,6 +4,7 @@ name: Test Go env: # See: https://github.com/actions/setup-go/tree/main#supported-version-syntax GO_VERSION: "1.17" + COVERAGE_ARTIFACT: coverage-data # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows on: @@ -99,18 +100,30 @@ jobs: if: runner.os == 'Linux' run: task test-legacy - - name: Send unit tests coverage to Codecov + - name: Upload coverage data to workflow artifact if: runner.os == 'Linux' - uses: codecov/codecov-action@v3 + uses: actions/upload-artifact@v3 with: - file: ./coverage_unit.txt - flags: unit - fail_ci_if_error: ${{ github.repository == 'arduino/arduino-cli' }} + if-no-files-found: error + name: ${{ env.COVERAGE_ARTIFACT }} + path: | + ./coverage_unit.txt + ./coverage_legacy.txt - - name: Send legacy tests coverage to Codecov - if: runner.os == 'Linux' + coverage-upload: + runs-on: ubuntu-latest + needs: test + steps: + - name: Download coverage data artifact + uses: actions/download-artifact@v3 + with: + name: ${{ env.COVERAGE_ARTIFACT }} + + - name: Send unit tests coverage to Codecov uses: codecov/codecov-action@v3 with: - file: ./coverage_legacy.txt + files: > + ./coverage_unit.txt, + ./coverage_legacy.txt flags: unit fail_ci_if_error: ${{ github.repository == 'arduino/arduino-cli' }} diff --git a/docs/platform-specification.md b/docs/platform-specification.md index b95ffffb4dc..9a4418464f5 100644 --- a/docs/platform-specification.md +++ b/docs/platform-specification.md @@ -437,6 +437,7 @@ no longer used. You can specify pre and post actions around each recipe. These are called "hooks". Here is the complete list of available hooks: +- `recipe.hooks.prebuild.NUMBER.pattern` (called before sketch preprocessing and libraries discovery) - `recipe.hooks.sketch.prebuild.NUMBER.pattern` (called before sketch compilation) - `recipe.hooks.sketch.postbuild.NUMBER.pattern` (called after sketch compilation) - `recipe.hooks.libraries.prebuild.NUMBER.pattern` (called before libraries compilation) diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index f7ba53601cb..5750189bead 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -146,13 +146,18 @@ 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() cli.t.NoError(err) cli.t.NotNil(p) testSketch := p.Parent().Join("testdata", sketchName) - sketchPath := cli.SketchbookDir().Join(sketchName) + sketchPath := cli.WorkingDir().Join(sketchName) err = testSketch.CopyDirTo(sketchPath) cli.t.NoError(err) return sketchPath diff --git a/internal/integrationtest/board/board_test.go b/internal/integrationtest/board/board_test.go new file mode 100644 index 00000000000..41777710a13 --- /dev/null +++ b/internal/integrationtest/board/board_test.go @@ -0,0 +1,483 @@ +// 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 board_test + +import ( + "encoding/json" + "os" + "strings" + "testing" + + "github.com/arduino/arduino-cli/internal/integrationtest" + "github.com/stretchr/testify/require" + semver "go.bug.st/relaxed-semver" + "go.bug.st/testifyjson/requirejson" + "gopkg.in/src-d/go-git.v4" + "gopkg.in/src-d/go-git.v4/plumbing" +) + +func TestBoardList(t *testing.T) { + if os.Getenv("CI") != "" { + t.Skip("VMs have no serial ports") + } + + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("core", "update-index") + require.NoError(t, err) + stdout, _, err := cli.Run("board", "list", "--format", "json") + require.NoError(t, err) + // check is a valid json and contains a list of ports + requirejson.Parse(t, stdout). + Query(`[ .[].port | select(.protocol == null or .protocol_label == null) ]`). + MustBeEmpty() +} + +func TestBoardListWithInvalidDiscovery(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("core", "update-index") + require.NoError(t, err) + _, _, err = cli.Run("board", "list") + require.NoError(t, err) + + // check that the CLI does not crash if an invalid discovery is installed + // (for example if the installation fails midway). + // https://github.com/arduino/arduino-cli/issues/1669 + toolDir := cli.DataDir().Join("packages", "builtin", "tools", "serial-discovery") + dirsToEmpty, err := toolDir.ReadDir() + require.NoError(t, err) + require.Len(t, dirsToEmpty, 1) + require.NoError(t, dirsToEmpty[0].RemoveAll()) + require.NoError(t, dirsToEmpty[0].MkdirAll()) + + _, stderr, err := cli.Run("board", "list") + require.NoError(t, err) + require.Contains(t, string(stderr), "builtin:serial-discovery") +} + +func TestBoardListall(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:avr@1.8.3") + require.NoError(t, err) + + stdout, _, err := cli.Run("board", "listall", "--format", "json") + require.NoError(t, err) + + requirejson.Query(t, stdout, ".boards | length", "26") + + requirejson.Contains(t, stdout, `{ + "boards":[ + { + "name": "Arduino Yún", + "fqbn": "arduino:avr:yun", + "platform": { + "id": "arduino:avr", + "installed": "1.8.3", + "name": "Arduino AVR Boards" + } + }, + { + "name": "Arduino Uno", + "fqbn": "arduino:avr:uno", + "platform": { + "id": "arduino:avr", + "installed": "1.8.3", + "name": "Arduino AVR Boards" + } + } + ] + }`) + + // Check if the boards' "latest" value is not empty + requirejson.Parse(t, stdout). + Query(`[ .boards | .[] | .platform | select(.latest == "") ]`). + MustBeEmpty() +} + +func TestBoardListallWithManuallyInstalledPlatform(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("update") + require.NoError(t, err) + + // Manually installs a core in sketchbooks hardware folder + gitUrl := "https://github.com/arduino/ArduinoCore-samd.git" + repoDir := cli.SketchbookDir().Join("hardware", "arduino-beta-development", "samd") + _, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{ + URL: gitUrl, + ReferenceName: plumbing.NewTagReferenceName("1.8.11"), + }) + require.NoError(t, err) + + stdout, _, err := cli.Run("board", "listall", "--format", "json") + require.NoError(t, err) + + requirejson.Query(t, stdout, ".boards | length", "17") + + requirejson.Contains(t, stdout, `{ + "boards": [ + { + "name": "Arduino MKR1000", + "fqbn": "arduino-beta-development:samd:mkr1000", + "platform": { + "id": "arduino-beta-development:samd", + "installed": "1.8.11", + "latest": "1.8.11", + "name": "Arduino SAMD (32-bits ARM Cortex-M0+) Boards", + } + }, + { + "name": "Arduino NANO 33 IoT", + "fqbn": "arduino-beta-development:samd:nano_33_iot", + "platform": { + "id": "arduino-beta-development:samd", + "installed": "1.8.11", + "latest": "1.8.11", + "name": "Arduino SAMD (32-bits ARM Cortex-M0+) Boards" + } + } + ] + }`) +} + +func TestBoardDetails(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("core", "update-index") + require.NoError(t, err) + // Download samd core pinned to 1.8.6 + _, _, err = cli.Run("core", "install", "arduino:samd@1.8.6") + require.NoError(t, err) + + // Test board listall with and without showing hidden elements + stdout, _, err := cli.Run("board", "listall", "MIPS", "--format", "json") + require.NoError(t, err) + require.Equal(t, string(stdout), "{}\n") + + stdout, _, err = cli.Run("board", "listall", "MIPS", "-a", "--format", "json") + require.NoError(t, err) + requirejson.Contains(t, stdout, `{ + "boards": [ + { + "name": "Arduino Tian (MIPS Console port)" + } + ] + }`) + + stdout, _, err = cli.Run("board", "details", "-b", "arduino:samd:nano_33_iot", "--format", "json") + require.NoError(t, err) + + requirejson.Contains(t, stdout, `{ + "fqbn": "arduino:samd:nano_33_iot", + "name": "Arduino NANO 33 IoT", + "version": "1.8.6", + "properties_id": "nano_33_iot", + "official": true, + "package": { + "maintainer": "Arduino", + "url": "https://downloads.arduino.cc/packages/package_index.tar.bz2", + "website_url": "http://www.arduino.cc/", + "email": "packages@arduino.cc", + "name": "arduino", + "help": { + "online": "http://www.arduino.cc/en/Reference/HomePage" + } + }, + "platform": { + "architecture": "samd", + "category": "Arduino", + "url": "http://downloads.arduino.cc/cores/samd-1.8.6.tar.bz2", + "archive_filename": "samd-1.8.6.tar.bz2", + "checksum": "SHA-256:68a4fffa6fe6aa7886aab2e69dff7d3f94c02935bbbeb42de37f692d7daf823b", + "size": 2980953, + "name": "Arduino SAMD Boards (32-bits ARM Cortex-M0+)" + }, + "identification_properties": [ + { + "properties": { + "vid": "0x2341", + "pid": "0x8057" + } + }, + { + "properties": { + "vid": "0x2341", + "pid": "0x0057" + } + } + ], + "programmers": [ + { + "platform": "Arduino SAMD Boards (32-bits ARM Cortex-M0+)", + "id": "edbg", + "name": "Atmel EDBG" + }, + { + "platform": "Arduino SAMD Boards (32-bits ARM Cortex-M0+)", + "id": "atmel_ice", + "name": "Atmel-ICE" + }, + { + "platform": "Arduino SAMD Boards (32-bits ARM Cortex-M0+)", + "id": "sam_ice", + "name": "Atmel SAM-ICE" + } + ] + }`) + + // Download samd core pinned to 1.8.8 + _, _, err = cli.Run("core", "install", "arduino:samd@1.8.8") + require.NoError(t, err) + + stdout, _, err = cli.Run("board", "details", "-b", "arduino:samd:nano_33_iot", "--format", "json") + require.NoError(t, err) + requirejson.Contains(t, stdout, `{"debugging_supported": true}`) +} + +func TestBoardDetailsNoFlags(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("core", "update-index") + require.NoError(t, err) + // Download samd core pinned to 1.8.6 + _, _, err = cli.Run("core", "install", "arduino:samd@1.8.6") + require.NoError(t, err) + stdout, stderr, err := cli.Run("board", "details") + require.Error(t, err) + require.Contains(t, string(stderr), "Error: required flag(s) \"fqbn\" not set") + require.Empty(t, stdout) +} + +func TestBoardDetailsListProgrammersWithoutFlag(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("core", "update-index") + require.NoError(t, err) + // Download samd core pinned to 1.8.6 + _, _, err = cli.Run("core", "install", "arduino:samd@1.8.6") + require.NoError(t, err) + stdout, _, err := cli.Run("board", "details", "-b", "arduino:samd:nano_33_iot") + require.NoError(t, err) + split := strings.Split(string(stdout), "\n") + lines := make([][]string, len(split)) + for i, l := range split { + lines[i] = strings.Fields(l) + } + require.Contains(t, lines, []string{"Programmers:", "Id", "Name"}) + require.Contains(t, lines, []string{"edbg", "Atmel", "EDBG"}) + require.Contains(t, lines, []string{"atmel_ice", "Atmel-ICE"}) + require.Contains(t, lines, []string{"sam_ice", "Atmel", "SAM-ICE"}) +} + +func TestBoardDetailsListProgrammersFlag(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("core", "update-index") + require.NoError(t, err) + // Download samd core pinned to 1.8.6 + _, _, err = cli.Run("core", "install", "arduino:samd@1.8.6") + require.NoError(t, err) + stdout, _, err := cli.Run("board", "details", "-b", "arduino:samd:nano_33_iot", "--list-programmers") + require.NoError(t, err) + lines := strings.Split(string(stdout), "\n") + for i, l := range lines { + lines[i] = strings.TrimSpace(l) + } + require.Contains(t, lines, "Id Programmer name") + require.Contains(t, lines, "edbg Atmel EDBG") + require.Contains(t, lines, "atmel_ice Atmel-ICE") + require.Contains(t, lines, "sam_ice Atmel SAM-ICE") +} + +func TestBoardSearch(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("update") + require.NoError(t, err) + + stdout, _, err := cli.Run("board", "search", "--format", "json") + require.NoError(t, err) + // Verifies boards are returned + requirejson.NotEmpty(t, stdout) + // Verifies no board has FQBN set since no platform is installed + requirejson.Query(t, stdout, "[ .[] | select(.fqbn) ] | length", "0") + requirejson.Contains(t, stdout, `[ + {"name": "Arduino Uno"}, + {"name": "Arduino Yún"}, + {"name": "Arduino Zero"}, + {"name": "Arduino Nano 33 BLE"}, + {"name": "Arduino Portenta H7"} + ]`) + + // Search in non installed boards + stdout, _, err = cli.Run("board", "search", "--format", "json", "nano", "33") + require.NoError(t, err) + // Verifies boards are returned + requirejson.NotEmpty(t, stdout) + // Verifies no board has FQBN set since no platform is installed + requirejson.Query(t, stdout, "[ .[] | select(.fqbn) ] | length", "0") + requirejson.Contains(t, stdout, `[ + {"name": "Arduino Nano 33 BLE"}, + {"name": "Arduino Nano 33 IoT"} + ]`) + + // Install a platform from index + _, _, err = cli.Run("core", "install", "arduino:avr@1.8.3") + require.NoError(t, err) + + stdout, _, err = cli.Run("board", "search", "--format", "json") + require.NoError(t, err) + requirejson.NotEmpty(t, stdout) + // Verifies some FQBNs are now returned after installing a platform + requirejson.Query(t, stdout, "[ .[] | select(.fqbn) ] | length", "26") + requirejson.Contains(t, stdout, `[ + { + "name": "Arduino Yún", + "fqbn": "arduino:avr:yun" + }, + { + "name": "Arduino Uno", + "fqbn": "arduino:avr:uno" + } + ]`) + + stdout, _, err = cli.Run("board", "search", "--format", "json", "arduino", "yun") + require.NoError(t, err) + requirejson.NotEmpty(t, stdout) + requirejson.Contains(t, stdout, `[ + { + "name": "Arduino Yún", + "fqbn": "arduino:avr:yun" + } + ]`) + + // Manually installs a core in sketchbooks hardware folder + gitUrl := "https://github.com/arduino/ArduinoCore-samd.git" + repoDir := cli.SketchbookDir().Join("hardware", "arduino-beta-development", "samd") + _, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{ + URL: gitUrl, + ReferenceName: plumbing.NewTagReferenceName("1.8.11"), + }) + require.NoError(t, err) + + stdout, _, err = cli.Run("board", "search", "--format", "json") + require.NoError(t, err) + requirejson.NotEmpty(t, stdout) + // Verifies some FQBNs are now returned after installing a platform + requirejson.Query(t, stdout, "[ .[] | select(.fqbn) ] | length", "43") + requirejson.Contains(t, stdout, `[ + { + "name": "Arduino Uno", + "fqbn": "arduino:avr:uno" + }, + { + "name": "Arduino Yún", + "fqbn": "arduino:avr:yun" + }, + { + "name": "Arduino MKR WiFi 1010", + "fqbn": "arduino-beta-development:samd:mkrwifi1010" + }, + { + "name": "Arduino MKR1000", + "fqbn": "arduino-beta-development:samd:mkr1000" + }, + { + "name": "Arduino MKRZERO", + "fqbn": "arduino-beta-development:samd:mkrzero" + }, + { + "name": "Arduino NANO 33 IoT", + "fqbn": "arduino-beta-development:samd:nano_33_iot" + }, + { + "fqbn": "arduino-beta-development:samd:arduino_zero_native" + } + ]`) + + stdout, _, err = cli.Run("board", "search", "--format", "json", "mkr1000") + require.NoError(t, err) + requirejson.NotEmpty(t, stdout) + // Verifies some FQBNs are now returned after installing a platform + requirejson.Contains(t, stdout, `[ + { + "name": "Arduino MKR1000", + "fqbn": "arduino-beta-development:samd:mkr1000" + } + ]`) +} + +func TestBoardAttachWithoutSketchJson(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("update") + require.NoError(t, err) + + sketchName := "BoardAttachWithoutSketchJson" + sketchPath := cli.SketchbookDir().Join(sketchName) + fqbn := "arduino:avr:uno" + + // Create a test sketch + _, _, err = cli.Run("sketch", "new", sketchPath.String()) + require.NoError(t, err) + + _, _, err = cli.Run("board", "attach", "-b", fqbn, sketchPath.String()) + require.NoError(t, err) +} + +func TestBoardSearchWithOutdatedCore(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("update") + require.NoError(t, err) + + // Install an old core version + _, _, err = cli.Run("core", "install", "arduino:samd@1.8.6") + require.NoError(t, err) + + stdout, _, err := cli.Run("board", "search", "arduino:samd:mkrwifi1010", "--format", "json") + require.NoError(t, err) + requirejson.Len(t, stdout, 1) + var data []map[string]interface{} + err = json.Unmarshal(stdout, &data) + require.NoError(t, err) + board := data[0] + require.Equal(t, board["name"], "Arduino MKR WiFi 1010") + require.Equal(t, board["fqbn"], "arduino:samd:mkrwifi1010") + samdCore := board["platform"].(map[string]interface{}) + require.Equal(t, samdCore["id"], "arduino:samd") + installedVersion, err := semver.Parse(samdCore["installed"].(string)) + require.NoError(t, err) + latestVersion, err := semver.Parse(samdCore["latest"].(string)) + require.NoError(t, err) + // Installed version must be older than latest + require.True(t, installedVersion.LessThan(latestVersion)) +} diff --git a/internal/integrationtest/compile/compile_part_1_test.go b/internal/integrationtest/compile/compile_part_1_test.go index 203ce88ac90..9f3d78e9772 100644 --- a/internal/integrationtest/compile/compile_part_1_test.go +++ b/internal/integrationtest/compile/compile_part_1_test.go @@ -57,6 +57,10 @@ func TestCompile(t *testing.T) { {"WithExportBinariesEnvVar", compileWithExportBinariesEnvVar}, {"WithExportBinariesConfig", compileWithExportBinariesConfig}, {"WithInvalidUrl", compileWithInvalidUrl}, + {"WithPdeExtension", compileWithPdeExtension}, + {"WithMultipleMainFiles", compileWithMultipleMainFiles}, + {"CaseMismatchFails", compileCaseMismatchFails}, + {"OnlyCompilationDatabaseFlag", compileOnlyCompilationDatabaseFlag}, }.Run(t, env, cli) } @@ -526,3 +530,127 @@ 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) + + 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()) +} 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..f1398ac490d --- /dev/null +++ b/internal/integrationtest/compile/compile_part_3_test.go @@ -0,0 +1,199 @@ +// 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 TestCompileUsingPlatformLocalTxt(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:avr@1.8.3") + require.NoError(t, err) + + sketchName := "CompileSketchUsingPlatformLocalTxt" + sketchPath := cli.SketchbookDir().Join(sketchName) + 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.3", "platform.local.txt") + err = platformLocalTxt.WriteFile([]byte("compiler.c.cmd=my-compiler-that-does-not-exist")) + require.NoError(t, err) + + // 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 TestCompileUsingBoardsLocalTxt(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:avr@1.8.3") + require.NoError(t, err) + + sketchName := "CompileSketchUsingBoardsLocalTxt" + sketchPath := cli.SketchbookDir().Join(sketchName) + // 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.3", "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) + + _, _, err = cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String()) + require.NoError(t, err) +} + +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_board.py b/test/test_board.py deleted file mode 100644 index 0f36b07c34a..00000000000 --- a/test/test_board.py +++ /dev/null @@ -1,680 +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. -from pathlib import Path -from git import Repo -import os -import glob -import simplejson as json -import semver -import pytest - -from .common import running_on_ci - - -gold_board = """ - { - "fqbn": "arduino:samd:nano_33_iot", - "name": "Arduino NANO 33 IoT", - "version": "1.8.6", - "properties_id": "nano_33_iot", - "official": true, - "package": { - "maintainer": "Arduino", - "url": "https://downloads.arduino.cc/packages/package_index.tar.bz2", - "website_url": "http://www.arduino.cc/", - "email": "packages@arduino.cc", - "name": "arduino", - "help": { - "online": "http://www.arduino.cc/en/Reference/HomePage" - } - }, - "platform": { - "architecture": "samd", - "category": "Arduino", - "url": "http://downloads.arduino.cc/cores/samd-1.8.6.tar.bz2", - "archive_filename": "samd-1.8.6.tar.bz2", - "checksum": "SHA-256:68a4fffa6fe6aa7886aab2e69dff7d3f94c02935bbbeb42de37f692d7daf823b", - "size": 2980953, - "name": "Arduino SAMD Boards (32-bits ARM Cortex-M0+)" - }, - "toolsDependencies": [ - { - "packager": "arduino", - "name": "arm-none-eabi-gcc", - "version": "7-2017q4", - "systems": [ - { - "checksum": "SHA-256:34180943d95f759c66444a40b032f7dd9159a562670fc334f049567de140c51b", - "host": "arm-linux-gnueabihf", - "archive_filename": "gcc-arm-none-eabi-7-2019-q4-major-linuxarm.tar.bz2", - "url": "http://downloads.arduino.cc/tools/gcc-arm-none-eabi-7-2019-q4-major-linuxarm.tar.bz2", - "size": 96613739 - }, - { - "checksum": "SHA-256:6fb5752fb4d11012bd0a1ceb93a19d0641ff7cf29d289b3e6b86b99768e66f76", - "host": "aarch64-linux-gnu", - "archive_filename": "gcc-arm-none-eabi-7-2018-q2-update-linuxarm64.tar.bz2", - "url": "http://downloads.arduino.cc/tools/gcc-arm-none-eabi-7-2018-q2-update-linuxarm64.tar.bz2", - "size": 99558726 - }, - { - "checksum": "SHA-256:96dd0091856f4d2eb21046eba571321feecf7d50b9c156f708b2a8b683903382", - "host": "i686-mingw32", - "archive_filename": "gcc-arm-none-eabi-7-2017-q4-major-win32-arduino1.zip", - "url": "http://downloads.arduino.cc/tools/gcc-arm-none-eabi-7-2017-q4-major-win32-arduino1.zip", - "size": 131761924 - }, - { - "checksum": "SHA-256:89b776c7cf0591c810b5b60067e4dc113b5b71bc50084a536e71b894a97fdccb", - "host": "x86_64-apple-darwin", - "archive_filename": "gcc-arm-none-eabi-7-2017-q4-major-mac.tar.bz2", - "url": "http://downloads.arduino.cc/tools/gcc-arm-none-eabi-7-2017-q4-major-mac.tar.bz2", - "size": 104550003 - }, - { - "checksum": "SHA-256:96a029e2ae130a1210eaa69e309ea40463028eab18ba19c1086e4c2dafe69a6a", - "host": "x86_64-pc-linux-gnu", - "archive_filename": "gcc-arm-none-eabi-7-2017-q4-major-linux64.tar.bz2", - "url": "http://downloads.arduino.cc/tools/gcc-arm-none-eabi-7-2017-q4-major-linux64.tar.bz2", - "size": 99857645 - }, - { - "checksum": "SHA-256:090a0bc2b1956bc49392dff924a6c30fa57c88130097b1972204d67a45ce3cf3", - "host": "i686-pc-linux-gnu", - "archive_filename": "gcc-arm-none-eabi-7-2018-q2-update-linux32.tar.bz2", - "url": "http://downloads.arduino.cc/tools/gcc-arm-none-eabi-7-2018-q2-update-linux32.tar.bz2", - "size": 97427309 - } - ] - }, - { - "packager": "arduino", - "name": "bossac", - "version": "1.7.0-arduino3", - "systems": [ - { - "checksum": "SHA-256:62745cc5a98c26949ec9041ef20420643c561ec43e99dae659debf44e6836526", - "host": "i686-mingw32", - "archive_filename": "bossac-1.7.0-arduino3-windows.tar.gz", - "url": "http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-windows.tar.gz", - "size": 3607421 - }, - { - "checksum": "SHA-256:adb3c14debd397d8135e9e970215c6972f0e592c7af7532fa15f9ce5e64b991f", - "host": "x86_64-apple-darwin", - "archive_filename": "bossac-1.7.0-arduino3-osx.tar.gz", - "url": "http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-osx.tar.gz", - "size": 75510 - }, - { - "checksum": "SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100", - "host": "x86_64-pc-linux-gnu", - "archive_filename": "bossac-1.7.0-arduino3-linux64.tar.gz", - "url": "http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz", - "size": 207271 - }, - { - "checksum": "SHA-256:4ac4354746d1a09258f49a43ef4d1baf030d81c022f8434774268b00f55d3ec3", - "host": "i686-pc-linux-gnu", - "archive_filename": "bossac-1.7.0-arduino3-linux32.tar.gz", - "url": "http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux32.tar.gz", - "size": 193577 - }, - { - "checksum": "SHA-256:626c6cc548046901143037b782bf019af1663bae0d78cf19181a876fb9abbb90", - "host": "arm-linux-gnueabihf", - "archive_filename": "bossac-1.7.0-arduino3-linuxarm.tar.gz", - "url": "http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linuxarm.tar.gz", - "size": 193941 - }, - { - "checksum": "SHA-256:a098b2cc23e29f0dc468416210d097c4a808752cd5da1a7b9b8b7b931a04180b", - "host": "aarch64-linux-gnu", - "archive_filename": "bossac-1.7.0-arduino3-linuxaarch64.tar.gz", - "url": "http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linuxaarch64.tar.gz", - "size": 268365 - } - ] - }, - { - "packager": "arduino", - "name": "openocd", - "version": "0.10.0-arduino7", - "systems": [ - { - "checksum": "SHA-256:f8e0d783e80a3d5f75ee82e9542315871d46e1e283a97447735f1cbcd8986b06", - "host": "arm-linux-gnueabihf", - "archive_filename": "openocd-0.10.0-arduino7-static-arm-linux-gnueabihf.tar.bz2", - "url": "http://downloads.arduino.cc/tools/openocd-0.10.0-arduino7-static-arm-linux-gnueabihf.tar.bz2", - "size": 1638575 - }, - { - "checksum": "SHA-256:d47d728a9a8d98f28dc22e31d7127ced9de0d5e268292bf935e050ef1d2bdfd0", - "host": "aarch64-linux-gnu", - "archive_filename": "openocd-0.10.0-arduino7-static-aarch64-linux-gnu.tar.bz2", - "url": "http://downloads.arduino.cc/tools/openocd-0.10.0-arduino7-static-aarch64-linux-gnu.tar.bz2", - "size": 1580739 - }, - { - "checksum": "SHA-256:1e539a587a0c54a551ce0dc542af10a2520b1c93bbfe2ca4ebaef4c83411df1a", - "host": "i386-apple-darwin11", - "archive_filename": "openocd-0.10.0-arduino7-static-x86_64-apple-darwin13.tar.bz2", - "url": "http://downloads.arduino.cc/tools/openocd-0.10.0-arduino7-static-x86_64-apple-darwin13.tar.bz2", - "size": 1498970 - }, - { - "checksum": "SHA-256:91d418bd309ec1e98795c622cd25c936aa537c0b3828fa5bcb191389378a1b27", - "host": "x86_64-linux-gnu", - "archive_filename": "openocd-0.10.0-arduino7-static-x86_64-ubuntu12.04-linux-gnu.tar.bz2", - "url": "http://downloads.arduino.cc/tools/openocd-0.10.0-arduino7-static-x86_64-ubuntu12.04-linux-gnu.tar.bz2", - "size": 1701581 - }, - { - "checksum": "SHA-256:08a18f39d72a5626383503053a30a5da89eed7fdccb6f514b20b77403eb1b2b4", - "host": "i686-linux-gnu", - "archive_filename": "openocd-0.10.0-arduino7-static-i686-ubuntu12.04-linux-gnu.tar.bz2", - "url": "http://downloads.arduino.cc/tools/openocd-0.10.0-arduino7-static-i686-ubuntu12.04-linux-gnu.tar.bz2", - "size": 1626347 - }, - { - "checksum": "SHA-256:f251aec5471296e18aa540c3078d66475357a76a77c16c06a2d9345f4e12b3d5", - "host": "i686-mingw32", - "archive_filename": "openocd-0.10.0-arduino7-static-i686-w64-mingw32.zip", - "url": "http://downloads.arduino.cc/tools/openocd-0.10.0-arduino7-static-i686-w64-mingw32.zip", - "size": 2016965 - } - ] - }, - { - "packager": "arduino", - "name": "CMSIS", - "version": "4.5.0", - "systems": [ - { - "checksum": "SHA-256:cd8f7eae9fc7c8b4a1b5e40b89b9666d33953b47d3d2eb81844f5af729fa224d", - "host": "i686-mingw32", - "archive_filename": "CMSIS-4.5.0.tar.bz2", - "url": "http://downloads.arduino.cc/CMSIS-4.5.0.tar.bz2", - "size": 31525196 - }, - { - "checksum": "SHA-256:cd8f7eae9fc7c8b4a1b5e40b89b9666d33953b47d3d2eb81844f5af729fa224d", - "host": "x86_64-apple-darwin", - "archive_filename": "CMSIS-4.5.0.tar.bz2", - "url": "http://downloads.arduino.cc/CMSIS-4.5.0.tar.bz2", - "size": 31525196 - }, - { - "checksum": "SHA-256:cd8f7eae9fc7c8b4a1b5e40b89b9666d33953b47d3d2eb81844f5af729fa224d", - "host": "x86_64-pc-linux-gnu", - "archive_filename": "CMSIS-4.5.0.tar.bz2", - "url": "http://downloads.arduino.cc/CMSIS-4.5.0.tar.bz2", - "size": 31525196 - }, - { - "checksum": "SHA-256:cd8f7eae9fc7c8b4a1b5e40b89b9666d33953b47d3d2eb81844f5af729fa224d", - "host": "i686-pc-linux-gnu", - "archive_filename": "CMSIS-4.5.0.tar.bz2", - "url": "http://downloads.arduino.cc/CMSIS-4.5.0.tar.bz2", - "size": 31525196 - }, - { - "checksum": "SHA-256:cd8f7eae9fc7c8b4a1b5e40b89b9666d33953b47d3d2eb81844f5af729fa224d", - "host": "arm-linux-gnueabihf", - "archive_filename": "CMSIS-4.5.0.tar.bz2", - "url": "http://downloads.arduino.cc/CMSIS-4.5.0.tar.bz2", - "size": 31525196 - }, - { - "checksum": "SHA-256:cd8f7eae9fc7c8b4a1b5e40b89b9666d33953b47d3d2eb81844f5af729fa224d", - "host": "aarch64-linux-gnu", - "archive_filename": "CMSIS-4.5.0.tar.bz2", - "url": "http://downloads.arduino.cc/CMSIS-4.5.0.tar.bz2", - "size": 31525196 - }, - { - "checksum": "SHA-256:cd8f7eae9fc7c8b4a1b5e40b89b9666d33953b47d3d2eb81844f5af729fa224d", - "host": "all", - "archive_filename": "CMSIS-4.5.0.tar.bz2", - "url": "http://downloads.arduino.cc/CMSIS-4.5.0.tar.bz2", - "size": 31525196 - } - ] - }, - { - "packager": "arduino", - "name": "CMSIS-Atmel", - "version": "1.2.0", - "systems": [ - { - "checksum": "SHA-256:5e02670be7e36be9691d059bee0b04ee8b249404687531f33893922d116b19a5", - "host": "i686-mingw32", - "archive_filename": "CMSIS-Atmel-1.2.0.tar.bz2", - "url": "http://downloads.arduino.cc/CMSIS-Atmel-1.2.0.tar.bz2", - "size": 2221805 - }, - { - "checksum": "SHA-256:5e02670be7e36be9691d059bee0b04ee8b249404687531f33893922d116b19a5", - "host": "x86_64-apple-darwin", - "archive_filename": "CMSIS-Atmel-1.2.0.tar.bz2", - "url": "http://downloads.arduino.cc/CMSIS-Atmel-1.2.0.tar.bz2", - "size": 2221805 - }, - { - "checksum": "SHA-256:5e02670be7e36be9691d059bee0b04ee8b249404687531f33893922d116b19a5", - "host": "x86_64-pc-linux-gnu", - "archive_filename": "CMSIS-Atmel-1.2.0.tar.bz2", - "url": "https://downloads.arduino.cc/CMSIS-Atmel-1.2.0.tar.bz2", - "size": 2221805 - }, - { - "checksum": "SHA-256:5e02670be7e36be9691d059bee0b04ee8b249404687531f33893922d116b19a5", - "host": "i686-pc-linux-gnu", - "archive_filename": "CMSIS-Atmel-1.2.0.tar.bz2", - "url": "https://downloads.arduino.cc/CMSIS-Atmel-1.2.0.tar.bz2", - "size": 2221805 - }, - { - "checksum": "SHA-256:5e02670be7e36be9691d059bee0b04ee8b249404687531f33893922d116b19a5", - "host": "arm-linux-gnueabihf", - "archive_filename": "CMSIS-Atmel-1.2.0.tar.bz2", - "url": "https://downloads.arduino.cc/CMSIS-Atmel-1.2.0.tar.bz2", - "size": 2221805 - }, - { - "checksum": "SHA-256:5e02670be7e36be9691d059bee0b04ee8b249404687531f33893922d116b19a5", - "host": "aarch64-linux-gnu", - "archive_filename": "CMSIS-Atmel-1.2.0.tar.bz2", - "url": "https://downloads.arduino.cc/CMSIS-Atmel-1.2.0.tar.bz2", - "size": 2221805 - }, - { - "checksum": "SHA-256:5e02670be7e36be9691d059bee0b04ee8b249404687531f33893922d116b19a5", - "host": "all", - "archive_filename": "CMSIS-Atmel-1.2.0.tar.bz2", - "url": "https://downloads.arduino.cc/CMSIS-Atmel-1.2.0.tar.bz2", - "size": 2221805 - } - ] - }, - { - "packager": "arduino", - "name": "arduinoOTA", - "version": "1.2.1", - "systems": [ - { - "checksum": "SHA-256:2ffdf64b78486c1d0bf28dc23d0ca36ab75ca92e84b9487246da01888abea6d4", - "host": "i686-linux-gnu", - "archive_filename": "arduinoOTA-1.2.1-linux_386.tar.bz2", - "url": "http://downloads.arduino.cc/tools/arduinoOTA-1.2.1-linux_386.tar.bz2", - "size": 2133779 - }, - { - "checksum": "SHA-256:5b82310d53688480f34a916aac31cd8f2dd2be65dd8fa6c2445262262e1948f9", - "host": "x86_64-linux-gnu", - "archive_filename": "arduinoOTA-1.2.1-linux_amd64.tar.bz2", - "url": "http://downloads.arduino.cc/tools/arduinoOTA-1.2.1-linux_amd64.tar.bz2", - "size": 2257689 - }, - { - "checksum": "SHA-256:ad54b3dcd586212941fd992bab573b53d13207a419a3f2981c970a085ae0e9e0", - "host": "arm-linux-gnueabihf", - "archive_filename": "arduinoOTA-1.2.1-linux_arm.tar.bz2", - "url": "http://downloads.arduino.cc/tools/arduinoOTA-1.2.1-linux_arm.tar.bz2", - "size": 2093132 - }, - { - "checksum": "SHA-256:ad54b3dcd586212941fd992bab573b53d13207a419a3f2981c970a085ae0e9e0", - "host": "aarch64-linux-gnu", - "archive_filename": "arduinoOTA-1.2.1-linux_arm.tar.bz2", - "url": "http://downloads.arduino.cc/tools/arduinoOTA-1.2.1-linux_arm.tar.bz2", - "size": 2093132 - }, - { - "checksum": "SHA-256:93a6d9f9c0c765d237be1665bf7a0a8e2b0b6d2a8531eae92db807f5515088a7", - "host": "i386-apple-darwin11", - "archive_filename": "arduinoOTA-1.2.1-darwin_amd64.tar.bz2", - "url": "http://downloads.arduino.cc/tools/arduinoOTA-1.2.1-darwin_amd64.tar.bz2", - "size": 2244088 - }, - { - "checksum": "SHA-256:e1ebf21f2c073fce25c09548c656da90d4ef6c078401ec6f323e0c58335115e5", - "host": "i686-mingw32", - "archive_filename": "arduinoOTA-1.2.1-windows_386.zip", - "url": "http://downloads.arduino.cc/tools/arduinoOTA-1.2.1-windows_386.zip", - "size": 2237511 - } - ] - } - ], - "identification_properties": [ - { - "properties": { - "vid": "0x2341", - "pid": "0x8057" - } - }, - { - "properties": { - "vid": "0x2341", - "pid": "0x0057" - } - } - ], - "programmers": [ - { - "platform": "Arduino SAMD Boards (32-bits ARM Cortex-M0+)", - "id": "edbg", - "name": "Atmel EDBG" - }, - { - "platform": "Arduino SAMD Boards (32-bits ARM Cortex-M0+)", - "id": "atmel_ice", - "name": "Atmel-ICE" - }, - { - "platform": "Arduino SAMD Boards (32-bits ARM Cortex-M0+)", - "id": "sam_ice", - "name": "Atmel SAM-ICE" - } - ] -} -""" # noqa: E501 - - -@pytest.mark.skipif(running_on_ci(), reason="VMs have no serial ports") -def test_board_list(run_command): - run_command(["core", "update-index"]) - result = run_command(["board", "list", "--format", "json"]) - assert result.ok - # check is a valid json and contains a list of ports - ports = json.loads(result.stdout) - assert isinstance(ports, list) - for port in ports: - assert "protocol" in port["port"] - assert "protocol_label" in port["port"] - - -def test_board_list_with_invalid_discovery(run_command, data_dir): - run_command(["core", "update-index"]) - result = run_command(["board", "list"]) - assert result.ok - - # check that the CLI do no crash if an invalid discovery is installed - # (for example if the installation fails midway). - # https://github.com/arduino/arduino-cli/issues/1669 - tool_dir = os.path.join(data_dir, "packages", "builtin", "tools", "serial-discovery") - for file_to_delete in glob.glob(tool_dir + "/*/*"): - os.remove(file_to_delete) - - result = run_command(["board", "list"]) - assert result.ok - assert "builtin:serial-discovery" in result.stderr - - -def test_board_listall(run_command): - assert run_command(["update"]) - assert run_command(["core", "install", "arduino:avr@1.8.3"]) - res = run_command(["board", "listall", "--format", "json"]) - assert res.ok - data = json.loads(res.stdout) - boards = {b["fqbn"]: b for b in data["boards"]} - assert len(boards) == 26 - assert "arduino:avr:yun" in boards - assert "Arduino Yún" == boards["arduino:avr:yun"]["name"] - platform = boards["arduino:avr:yun"]["platform"] - assert "arduino:avr" == platform["id"] - assert "1.8.3" == platform["installed"] - assert "" != platform["latest"] - assert "Arduino AVR Boards" == platform["name"] - - assert "arduino:avr:uno" in boards - assert "Arduino Uno" == boards["arduino:avr:uno"]["name"] - platform = boards["arduino:avr:uno"]["platform"] - assert "arduino:avr" == platform["id"] - assert "1.8.3" == platform["installed"] - assert "" != platform["latest"] - assert "Arduino AVR Boards" == platform["name"] - - -def test_board_listall_with_manually_installed_platform(run_command, data_dir): - assert run_command(["update"]) - - # Manually installs a core in sketchbooks hardware folder - git_url = "https://github.com/arduino/ArduinoCore-samd.git" - repo_dir = Path(data_dir, "hardware", "arduino-beta-development", "samd") - assert Repo.clone_from(git_url, repo_dir, multi_options=["-b 1.8.11"]) - - res = run_command(["board", "listall", "--format", "json"]) - assert res.ok - data = json.loads(res.stdout) - boards = {b["fqbn"]: b for b in data["boards"]} - assert len(boards) == 17 - assert "arduino-beta-development:samd:nano_33_iot" in boards - assert "Arduino NANO 33 IoT" == boards["arduino-beta-development:samd:nano_33_iot"]["name"] - platform = boards["arduino-beta-development:samd:nano_33_iot"]["platform"] - assert "arduino-beta-development:samd" == platform["id"] - assert "1.8.11" == platform["installed"] - assert "1.8.11" == platform["latest"] - assert "Arduino SAMD (32-bits ARM Cortex-M0+) Boards" == platform["name"] - - assert "arduino-beta-development:samd:mkr1000" in boards - assert "Arduino MKR1000" == boards["arduino-beta-development:samd:mkr1000"]["name"] - platform = boards["arduino-beta-development:samd:mkr1000"]["platform"] - assert "arduino-beta-development:samd" == platform["id"] - assert "1.8.11" == platform["installed"] - assert "1.8.11" == platform["latest"] - assert "Arduino SAMD (32-bits ARM Cortex-M0+) Boards" == platform["name"] - - -def test_board_details(run_command): - run_command(["core", "update-index"]) - # Download samd core pinned to 1.8.6 - run_command(["core", "install", "arduino:samd@1.8.6"]) - - # Test board listall with and without showing hidden elements - result = run_command(["board", "listall", "MIPS", "--format", "json"]) - assert result.ok - assert result.stdout == "{}\n" - - result = run_command(["board", "listall", "MIPS", "-a", "--format", "json"]) - assert result.ok - result = json.loads(result.stdout) - assert result["boards"][0]["name"] == "Arduino Tian (MIPS Console port)" - - result = run_command(["board", "details", "-b", "arduino:samd:nano_33_iot", "--format", "json"]) - assert result.ok - # Sort everything before compare - result = json.loads(result.stdout) - gold_board_details = json.loads(gold_board) - - assert result["fqbn"] == gold_board_details["fqbn"] - assert result["name"] == gold_board_details["name"] - assert result["version"] == gold_board_details["version"] - assert result["properties_id"] == gold_board_details["properties_id"] - assert result["official"] == gold_board_details["official"] - assert result["package"] == gold_board_details["package"] - assert result["platform"] == gold_board_details["platform"] - for usb_id in gold_board_details["identification_properties"]: - assert usb_id in result["identification_properties"] - for programmer in gold_board_details["programmers"]: - assert programmer in result["programmers"] - - # Download samd core pinned to 1.8.8 - run_command(["core", "install", "arduino:samd@1.8.8"]) - - result = run_command(["board", "details", "-b", "arduino:samd:nano_33_iot", "--format", "json"]) - assert result.ok - result = json.loads(result.stdout) - assert result["debugging_supported"] is True - - -def test_board_details_no_flags(run_command): - run_command(["core", "update-index"]) - # Download samd core pinned to 1.8.6 - run_command(["core", "install", "arduino:samd@1.8.6"]) - result = run_command(["board", "details"]) - assert not result.ok - assert 'Error: required flag(s) "fqbn" not set' in result.stderr - assert result.stdout == "" - - -def test_board_details_list_programmers_without_flag(run_command): - run_command(["core", "update-index"]) - # Download samd core pinned to 1.8.6 - run_command(["core", "install", "arduino:samd@1.8.6"]) - result = run_command(["board", "details", "-b", "arduino:samd:nano_33_iot"], hide=True) - assert result.ok - lines = [l.strip().split() for l in result.stdout.splitlines()] - assert ["Programmers:", "Id", "Name"] in lines - assert ["edbg", "Atmel", "EDBG"] in lines - assert ["atmel_ice", "Atmel-ICE"] in lines - assert ["sam_ice", "Atmel", "SAM-ICE"] in lines - - -def test_board_details_list_programmers_flag(run_command): - run_command(["core", "update-index"]) - # Download samd core pinned to 1.8.6 - run_command(["core", "install", "arduino:samd@1.8.6"]) - result = run_command(["board", "details", "-b", "arduino:samd:nano_33_iot", "--list-programmers"], hide=True) - assert result.ok - - lines = [l.strip() for l in result.stdout.splitlines()] - assert "Id Programmer name" in lines - assert "edbg Atmel EDBG" in lines - assert "atmel_ice Atmel-ICE" in lines - assert "sam_ice Atmel SAM-ICE" in lines - - -def test_board_search(run_command, data_dir): - assert run_command(["update"]) - - res = run_command(["board", "search", "--format", "json"]) - assert res.ok - data = json.loads(res.stdout) - # Verifies boards are returned - assert len(data) > 0 - # Verifies no board has FQBN set since no platform is installed - assert len([board["fqbn"] for board in data if "fqbn" in board]) == 0 - names = [board["name"] for board in data if "name" in board] - assert "Arduino Uno" in names - assert "Arduino Yún" in names - assert "Arduino Zero" in names - assert "Arduino Nano 33 BLE" in names - assert "Arduino Portenta H7" in names - - # Search in non installed boards - res = run_command(["board", "search", "--format", "json", "nano", "33"]) - assert res.ok - data = json.loads(res.stdout) - # Verifies boards are returned - assert len(data) > 0 - # Verifies no board has FQBN set since no platform is installed - assert len([board["fqbn"] for board in data if "fqbn" in board]) == 0 - names = [board["name"] for board in data if "name" in board] - assert "Arduino Nano 33 BLE" in names - assert "Arduino Nano 33 IoT" in names - - # Install a platform from index - assert run_command(["core", "install", "arduino:avr@1.8.3"]) - - res = run_command(["board", "search", "--format", "json"]) - assert res.ok - data = json.loads(res.stdout) - assert len(data) > 0 - # Verifies some FQBNs are now returned after installing a platform - assert len([board["fqbn"] for board in data if "fqbn" in board]) == 26 - installed_boards = {board["fqbn"]: board for board in data if "fqbn" in board} - assert "arduino:avr:uno" in installed_boards - assert "Arduino Uno" == installed_boards["arduino:avr:uno"]["name"] - assert "arduino:avr:yun" in installed_boards - assert "Arduino Yún" == installed_boards["arduino:avr:yun"]["name"] - - res = run_command(["board", "search", "--format", "json", "arduino", "yun"]) - assert res.ok - data = json.loads(res.stdout) - assert len(data) > 0 - installed_boards = {board["fqbn"]: board for board in data if "fqbn" in board} - assert "arduino:avr:yun" in installed_boards - assert "Arduino Yún" == installed_boards["arduino:avr:yun"]["name"] - - # Manually installs a core in sketchbooks hardware folder - git_url = "https://github.com/arduino/ArduinoCore-samd.git" - repo_dir = Path(data_dir, "hardware", "arduino-beta-development", "samd") - assert Repo.clone_from(git_url, repo_dir, multi_options=["-b 1.8.11"]) - - res = run_command(["board", "search", "--format", "json"]) - assert res.ok - data = json.loads(res.stdout) - assert len(data) > 0 - # Verifies some FQBNs are now returned after installing a platform - assert len([board["fqbn"] for board in data if "fqbn" in board]) == 43 - installed_boards = {board["fqbn"]: board for board in data if "fqbn" in board} - assert "arduino:avr:uno" in installed_boards - assert "Arduino Uno" == installed_boards["arduino:avr:uno"]["name"] - assert "arduino:avr:yun" in installed_boards - assert "Arduino Yún" == installed_boards["arduino:avr:yun"]["name"] - assert "arduino-beta-development:samd:mkrwifi1010" in installed_boards - assert "Arduino MKR WiFi 1010" == installed_boards["arduino-beta-development:samd:mkrwifi1010"]["name"] - assert "arduino-beta-development:samd:mkr1000" in installed_boards - assert "Arduino MKR1000" == installed_boards["arduino-beta-development:samd:mkr1000"]["name"] - assert "arduino-beta-development:samd:mkrzero" in installed_boards - assert "Arduino MKRZERO" == installed_boards["arduino-beta-development:samd:mkrzero"]["name"] - assert "arduino-beta-development:samd:nano_33_iot" in installed_boards - assert "Arduino NANO 33 IoT" == installed_boards["arduino-beta-development:samd:nano_33_iot"]["name"] - assert "arduino-beta-development:samd:arduino_zero_native" in installed_boards - - res = run_command(["board", "search", "--format", "json", "mkr1000"]) - assert res.ok - data = json.loads(res.stdout) - assert len(data) > 0 - # Verifies some FQBNs are now returned after installing a platform - installed_boards = {board["fqbn"]: board for board in data if "fqbn" in board} - assert "arduino-beta-development:samd:mkr1000" in installed_boards - assert "Arduino MKR1000" == installed_boards["arduino-beta-development:samd:mkr1000"]["name"] - - -def test_board_attach_without_sketch_json(run_command, data_dir): - run_command(["update"]) - - sketch_name = "BoardAttachWithoutSketchJson" - sketch_path = Path(data_dir, sketch_name) - fqbn = "arduino:avr:uno" - - # Create a test sketch - assert run_command(["sketch", "new", sketch_path]) - - assert run_command(["board", "attach", "-b", fqbn, sketch_path]) - - -def test_board_search_with_outdated_core(run_command): - assert run_command(["update"]) - - # Install an old core version - assert run_command(["core", "install", "arduino:samd@1.8.6"]) - - res = run_command(["board", "search", "arduino:samd:mkrwifi1010", "--format", "json"]) - - data = json.loads(res.stdout) - assert len(data) == 1 - board = data[0] - assert board["name"] == "Arduino MKR WiFi 1010" - assert board["fqbn"] == "arduino:samd:mkrwifi1010" - samd_core = board["platform"] - assert samd_core["id"] == "arduino:samd" - installed_version = semver.parse_version_info(samd_core["installed"]) - latest_version = semver.parse_version_info(samd_core["latest"]) - # Installed version must be older than latest - assert installed_version.compare(latest_version) == -1 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