Unverified Commit 04cbdffa authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

[skip-changelog] Reuse already installed platforms to speed up integration tests (#1913)

* Factor all compile_part_1 and 2 test setup

* Made an object to simplify running of subtests

* Moved all subtests in the same file

Just moved functions around, no code change.

* Reuse installed platform to speedup debug integration tests
parent 063f4f86
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications. // Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc. // To purchase a commercial license, send an email to license@arduino.cc.
package compile_part_1_test package compile_test
import ( import (
"crypto/md5" "crypto/md5"
...@@ -26,9 +26,10 @@ import ( ...@@ -26,9 +26,10 @@ import (
"github.com/arduino/arduino-cli/internal/integrationtest" "github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/arduino/go-paths-helper" "github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.bug.st/testifyjson/requirejson"
) )
func TestCompileWithoutFqbn(t *testing.T) { func TestCompile(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp() defer env.CleanUp()
...@@ -37,26 +38,35 @@ func TestCompileWithoutFqbn(t *testing.T) { ...@@ -37,26 +38,35 @@ func TestCompileWithoutFqbn(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// Install Arduino AVR Boards // Install Arduino AVR Boards
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3") _, _, err = cli.Run("core", "install", "arduino:avr@1.8.5")
require.NoError(t, err) require.NoError(t, err)
integrationtest.CLISubtests{
{"WithoutFqbn", compileWithoutFqbn},
{"ErrorMessage", compileErrorMessage},
{"WithSimpleSketch", compileWithSimpleSketch},
{"OutputFlagDefaultPath", compileOutputFlagDefaultPath},
{"WithSketchWithSymlinkSelfloop", compileWithSketchWithSymlinkSelfloop},
{"BlacklistedSketchname", compileBlacklistedSketchname},
{"WithBuildPropertiesFlag", compileWithBuildPropertiesFlag},
{"WithBuildPropertyContainingQuotes", compileWithBuildPropertyContainingQuotes},
{"WithMultipleBuildPropertyFlags", compileWithMultipleBuildPropertyFlags},
{"WithOutputDirFlag", compileWithOutputDirFlag},
{"WithExportBinariesFlag", compileWithExportBinariesFlag},
{"WithCustomBuildPath", compileWithCustomBuildPath},
{"WithExportBinariesEnvVar", compileWithExportBinariesEnvVar},
{"WithExportBinariesConfig", compileWithExportBinariesConfig},
{"WithInvalidUrl", compileWithInvalidUrl},
}.Run(t, env, cli)
}
func compileWithoutFqbn(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
// Build sketch without FQBN // Build sketch without FQBN
_, _, err = cli.Run("compile") _, _, err := cli.Run("compile")
require.Error(t, err) require.Error(t, err)
} }
func TestCompileErrorMessage(t *testing.T) { func compileErrorMessage(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
// Download latest AVR
_, _, err = cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)
// Run a batch of bogus compile in a temp dir to check the error messages // Run a batch of bogus compile in a temp dir to check the error messages
tmp, err := paths.MkTempDir("", "tmp_dir") tmp, err := paths.MkTempDir("", "tmp_dir")
require.NoError(t, err) require.NoError(t, err)
...@@ -90,20 +100,10 @@ func TestCompileErrorMessage(t *testing.T) { ...@@ -90,20 +100,10 @@ func TestCompileErrorMessage(t *testing.T) {
require.Contains(t, string(stderr), "main file missing from sketch:") require.Contains(t, string(stderr), "main file missing from sketch:")
} }
func TestCompileWithSimpleSketch(t *testing.T) { func compileWithSimpleSketch(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
// Download latest AVR
_, _, err = cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)
sketchName := "CompileIntegrationTest" sketchName := "CompileIntegrationTest"
sketchPath := cli.SketchbookDir().Join(sketchName) sketchPath := cli.SketchbookDir().Join(sketchName)
defer sketchPath.RemoveAll()
fqbn := "arduino:avr:uno" fqbn := "arduino:avr:uno"
// Create a test sketch // Create a test sketch
...@@ -145,22 +145,12 @@ func TestCompileWithSimpleSketch(t *testing.T) { ...@@ -145,22 +145,12 @@ func TestCompileWithSimpleSketch(t *testing.T) {
require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.with_bootloader.hex").String()) require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.with_bootloader.hex").String())
} }
func TestOutputFlagDefaultPath(t *testing.T) { func compileOutputFlagDefaultPath(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
// Install Arduino AVR Boards
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
require.NoError(t, err)
// Create a test sketch // Create a test sketch
sketchPath := cli.SketchbookDir().Join("test_output_flag_default_path") sketchPath := cli.SketchbookDir().Join("test_output_flag_default_path")
defer sketchPath.RemoveAll()
fqbn := "arduino:avr:uno" fqbn := "arduino:avr:uno"
_, _, err = cli.Run("sketch", "new", sketchPath.String()) _, _, err := cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err) require.NoError(t, err)
// Test the --output-dir flag defaulting to current working dir // Test the --output-dir flag defaulting to current working dir
...@@ -170,80 +160,64 @@ func TestOutputFlagDefaultPath(t *testing.T) { ...@@ -170,80 +160,64 @@ func TestOutputFlagDefaultPath(t *testing.T) {
require.DirExists(t, target.String()) require.DirExists(t, target.String())
} }
func TestCompileWithSketchWithSymlinkSelfloop(t *testing.T) { func compileWithSketchWithSymlinkSelfloop(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) {
defer env.CleanUp() sketchName := "CompileIntegrationTestSymlinkSelfLoop"
sketchPath := cli.SketchbookDir().Join(sketchName)
// Init the environment explicitly defer sketchPath.RemoveAll()
_, _, err := cli.Run("core", "update-index") fqbn := "arduino:avr:uno"
require.NoError(t, err)
// Create a test sketch
// Install Arduino AVR Boards stdout, _, err := cli.Run("sketch", "new", sketchPath.String())
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3") require.NoError(t, err)
require.NoError(t, err) require.Contains(t, string(stdout), "Sketch created in: "+sketchPath.String())
sketchName := "CompileIntegrationTestSymlinkSelfLoop" // create a symlink that loops on himself
sketchPath := cli.SketchbookDir().Join(sketchName) loopFilePath := sketchPath.Join("loop")
fqbn := "arduino:avr:uno" err = os.Symlink(loopFilePath.String(), loopFilePath.String())
require.NoError(t, err)
// Create a test sketch
stdout, _, err := cli.Run("sketch", "new", sketchPath.String()) // Build sketch for arduino:avr:uno
require.NoError(t, err) _, stderr, err := cli.Run("compile", "-b", fqbn, sketchPath.String())
require.Contains(t, string(stdout), "Sketch created in: "+sketchPath.String()) // The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
// returning a different error detailed message
// create a symlink that loops on himself require.Contains(t, string(stderr), "Error opening sketch:")
loopFilePath := sketchPath.Join("loop") require.Error(t, err)
err = os.Symlink(loopFilePath.String(), loopFilePath.String()) }
require.NoError(t, err) {
sketchName := "CompileIntegrationTestSymlinkDirLoop"
// Build sketch for arduino:avr:uno sketchPath := cli.SketchbookDir().Join(sketchName)
_, stderr, err := cli.Run("compile", "-b", fqbn, sketchPath.String()) defer sketchPath.RemoveAll()
// The assertion is a bit relaxed in this case because win behaves differently from macOs and linux fqbn := "arduino:avr:uno"
// returning a different error detailed message
require.Contains(t, string(stderr), "Error opening sketch:") // Create a test sketch
require.Error(t, err) stdout, _, err := cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err)
sketchName = "CompileIntegrationTestSymlinkDirLoop" require.Contains(t, string(stdout), "Sketch created in: "+sketchPath.String())
sketchPath = cli.SketchbookDir().Join(sketchName)
// create a symlink that loops on the upper level
// Create a test sketch loopDirPath := sketchPath.Join("loop_dir")
stdout, _, err = cli.Run("sketch", "new", sketchPath.String()) err = loopDirPath.Mkdir()
require.NoError(t, err) require.NoError(t, err)
require.Contains(t, string(stdout), "Sketch created in: "+sketchPath.String()) loopDirSymlinkPath := loopDirPath.Join("loop_dir_symlink")
err = os.Symlink(loopDirPath.String(), loopDirSymlinkPath.String())
// create a symlink that loops on the upper level require.NoError(t, err)
loopDirPath := sketchPath.Join("loop_dir")
err = loopDirPath.Mkdir() // Build sketch for arduino:avr:uno
require.NoError(t, err) _, stderr, err := cli.Run("compile", "-b", fqbn, sketchPath.String())
loopDirSymlinkPath := loopDirPath.Join("loop_dir_symlink") // The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
err = os.Symlink(loopDirPath.String(), loopDirSymlinkPath.String()) // returning a different error detailed message
require.NoError(t, err) require.Contains(t, string(stderr), "Error opening sketch:")
require.Error(t, err)
// Build sketch for arduino:avr:uno }
_, stderr, err = cli.Run("compile", "-b", fqbn, sketchPath.String())
// The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
// returning a different error detailed message
require.Contains(t, string(stderr), "Error opening sketch:")
require.Error(t, err)
} }
func TestCompileBlacklistedSketchname(t *testing.T) { func compileBlacklistedSketchname(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Compile should ignore folders named `RCS`, `.git` and the likes, but // Compile should ignore folders named `RCS`, `.git` and the likes, but
// it should be ok for a sketch to be named like RCS.ino // it should be ok for a sketch to be named like RCS.ino
// Init the environment explicitly
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
// Install Arduino AVR Boards
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
require.NoError(t, err)
sketchName := "RCS" sketchName := "RCS"
sketchPath := cli.SketchbookDir().Join(sketchName) sketchPath := cli.SketchbookDir().Join(sketchName)
defer sketchPath.RemoveAll()
fqbn := "arduino:avr:uno" fqbn := "arduino:avr:uno"
// Create a test sketch // Create a test sketch
...@@ -256,126 +230,55 @@ func TestCompileBlacklistedSketchname(t *testing.T) { ...@@ -256,126 +230,55 @@ func TestCompileBlacklistedSketchname(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
} }
func TestCompileWithoutPrecompiledLibraries(t *testing.T) { func compileWithBuildPropertiesFlag(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) {
defer env.CleanUp() sketchName := "sketch_with_single_string_define"
sketchPath := cli.CopySketch(sketchName)
// Init the environment explicitly defer sketchPath.RemoveAll()
url := "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json" fqbn := "arduino:avr:uno"
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url)
require.NoError(t, err) // Compile using a build property with quotes
_, _, err = cli.Run("core", "install", "arduino:mbed@1.3.1", "--additional-urls="+url) _, stderr, err := cli.Run("compile", "-b", fqbn, "--build-properties=\"build.extra_flags=\"-DMY_DEFINE=\"hello world\"\"", sketchPath.String(), "--verbose", "--clean")
require.NoError(t, err) require.Error(t, err)
require.NotContains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
// // Precompiled version of Arduino_TensorflowLite
// _, _, err = cli.Run("lib", "install", "Arduino_LSM9DS1") // Try again with quotes
// require.NoError(t, err) _, stderr, err = cli.Run("compile", "-b", fqbn, "--build-properties=\"build.extra_flags=-DMY_DEFINE=\"hello\"\"", sketchPath.String(), "--verbose", "--clean")
// _, _, err = cli.Run("lib", "install", "Arduino_TensorflowLite@2.1.1-ALPHA-precompiled") require.Error(t, err)
// require.NoError(t, err) require.NotContains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
}
// sketchPath := cli.SketchbookDir().Join("libraries", "Arduino_TensorFlowLite", "examples", "hello_world") {
// _, _, err = cli.Run("compile", "-b", "arduino:mbed:nano33ble", sketchPath.String()) sketchName := "sketch_with_single_int_define"
// require.NoError(t, err) sketchPath := cli.CopySketch(sketchName)
defer sketchPath.RemoveAll()
_, _, err = cli.Run("core", "install", "arduino:samd@1.8.7", "--additional-urls="+url) fqbn := "arduino:avr:uno"
require.NoError(t, err)
// _, _, err = cli.Run("core", "install", "adafruit:samd@1.6.4", "--additional-urls="+url) // Try without quotes
// require.NoError(t, err) stdout, stderr, err := cli.Run("compile", "-b", fqbn, "--build-properties=\"build.extra_flags=-DMY_DEFINE=1\"", sketchPath.String(), "--verbose", "--clean")
// // should work on adafruit too after https://github.com/arduino/arduino-cli/pull/1134 require.NoError(t, err)
// _, _, err = cli.Run("compile", "-b", "adafruit:samd:adafruit_feather_m4", sketchPath.String()) require.Contains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
// require.NoError(t, err) require.Contains(t, string(stdout), "-DMY_DEFINE=1")
}
// // Non-precompiled version of Arduino_TensorflowLite {
// _, _, err = cli.Run("lib", "install", "Arduino_TensorflowLite@2.1.0-ALPHA") sketchName := "sketch_with_multiple_int_defines"
// require.NoError(t, err) sketchPath := cli.CopySketch(sketchName)
// _, _, err = cli.Run("compile", "-b", "arduino:mbed:nano33ble", sketchPath.String()) defer sketchPath.RemoveAll()
// require.NoError(t, err) fqbn := "arduino:avr:uno"
// _, _, err = cli.Run("compile", "-b", "adafruit:samd:adafruit_feather_m4", sketchPath.String())
// require.NoError(t, err) stdout, stderr, err := cli.Run("compile", "-b", fqbn,
"--build-properties", "build.extra_flags=-DFIRST_PIN=1,compiler.cpp.extra_flags=-DSECOND_PIN=2",
// Bosch sensor library sketchPath.String(), "--verbose", "--clean")
_, _, err = cli.Run("lib", "install", "BSEC Software Library@1.5.1474") require.NoError(t, err)
require.NoError(t, err) require.Contains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
sketchPath := cli.SketchbookDir().Join("libraries", "BSEC_Software_Library", "examples", "basic") require.Contains(t, string(stdout), "-DFIRST_PIN=1")
_, _, err = cli.Run("compile", "-b", "arduino:samd:mkr1000", sketchPath.String()) require.Contains(t, string(stdout), "-DSECOND_PIN=2")
require.NoError(t, err) }
_, _, err = cli.Run("compile", "-b", "arduino:mbed:nano33ble", sketchPath.String())
require.NoError(t, err)
// USBBlaster library
_, _, err = cli.Run("lib", "install", "USBBlaster@1.0.0")
require.NoError(t, err)
sketchPath = cli.SketchbookDir().Join("libraries", "USBBlaster", "examples", "USB_Blaster")
_, _, err = cli.Run("compile", "-b", "arduino:samd:mkrvidor4000", sketchPath.String())
require.NoError(t, err)
}
func TestCompileWithBuildPropertiesFlag(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
// Install Arduino AVR Boards
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
require.NoError(t, err)
sketchName := "sketch_with_single_string_define"
sketchPath := cli.CopySketch(sketchName)
fqbn := "arduino:avr:uno"
// Compile using a build property with quotes
_, stderr, err := cli.Run("compile", "-b", fqbn, "--build-properties=\"build.extra_flags=\"-DMY_DEFINE=\"hello world\"\"", sketchPath.String(), "--verbose", "--clean")
require.Error(t, err)
require.NotContains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
// Try again with quotes
_, stderr, err = cli.Run("compile", "-b", fqbn, "--build-properties=\"build.extra_flags=-DMY_DEFINE=\"hello\"\"", sketchPath.String(), "--verbose", "--clean")
require.Error(t, err)
require.NotContains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
sketchName = "sketch_with_single_int_define"
sketchPath = cli.CopySketch(sketchName)
// Try without quotes
stdout, stderr, err := cli.Run("compile", "-b", fqbn, "--build-properties=\"build.extra_flags=-DMY_DEFINE=1\"", sketchPath.String(), "--verbose", "--clean")
require.NoError(t, err)
require.Contains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
require.Contains(t, string(stdout), "-DMY_DEFINE=1")
sketchName = "sketch_with_multiple_int_defines"
sketchPath = cli.CopySketch(sketchName)
stdout, stderr, err = cli.Run("compile",
"-b",
fqbn,
"--build-properties",
"build.extra_flags=-DFIRST_PIN=1,compiler.cpp.extra_flags=-DSECOND_PIN=2",
sketchPath.String(),
"--verbose",
"--clean")
require.NoError(t, err)
require.Contains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
require.Contains(t, string(stdout), "-DFIRST_PIN=1")
require.Contains(t, string(stdout), "-DSECOND_PIN=2")
} }
func TestCompileWithBuildPropertyContainingQuotes(t *testing.T) { func compileWithBuildPropertyContainingQuotes(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
// Install Arduino AVR Boards
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
require.NoError(t, err)
sketchName := "sketch_with_single_string_define" sketchName := "sketch_with_single_string_define"
sketchPath := cli.CopySketch(sketchName) sketchPath := cli.CopySketch(sketchName)
defer sketchPath.RemoveAll()
fqbn := "arduino:avr:uno" fqbn := "arduino:avr:uno"
// Compile using a build property with quotes // Compile using a build property with quotes
...@@ -389,84 +292,237 @@ func TestCompileWithBuildPropertyContainingQuotes(t *testing.T) { ...@@ -389,84 +292,237 @@ func TestCompileWithBuildPropertyContainingQuotes(t *testing.T) {
require.Contains(t, string(stdout), `-DMY_DEFINE=\"hello world\"`) require.Contains(t, string(stdout), `-DMY_DEFINE=\"hello world\"`)
} }
func TestCompileWithMultipleBuildPropertyFlags(t *testing.T) { func compileWithMultipleBuildPropertyFlags(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
// Install Arduino AVR Boards
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
require.NoError(t, err)
sketchName := "sketch_with_multiple_defines" sketchName := "sketch_with_multiple_defines"
sketchPath := cli.CopySketch(sketchName) sketchPath := cli.CopySketch(sketchName)
defer sketchPath.RemoveAll()
fqbn := "arduino:avr:uno" fqbn := "arduino:avr:uno"
// Compile using multiple build properties separated by a space // Compile using multiple build properties separated by a space
_, _, err = cli.Run( _, _, err := cli.Run("compile", "-b", fqbn,
"compile",
"-b",
fqbn,
"--build-property=compiler.cpp.extra_flags=\"-DPIN=2 -DSSID=\"This is a String\"\"", "--build-property=compiler.cpp.extra_flags=\"-DPIN=2 -DSSID=\"This is a String\"\"",
sketchPath.String(), sketchPath.String(), "--verbose", "--clean",
"--verbose",
"--clean",
) )
require.Error(t, err) require.Error(t, err)
// Compile using multiple build properties separated by a space and properly quoted // Compile using multiple build properties separated by a space and properly quoted
stdout, _, err := cli.Run( stdout, _, err := cli.Run(
"compile", "compile", "-b", fqbn,
"-b",
fqbn,
"--build-property=compiler.cpp.extra_flags=-DPIN=2 \"-DSSID=\"This is a String\"\"", "--build-property=compiler.cpp.extra_flags=-DPIN=2 \"-DSSID=\"This is a String\"\"",
sketchPath.String(), sketchPath.String(), "--verbose", "--clean",
"--verbose",
"--clean",
) )
require.NoError(t, err) require.NoError(t, err)
require.Contains(t, string(stdout), "-DPIN=2 \"-DSSID=\\\"This is a String\\\"\"") require.Contains(t, string(stdout), "-DPIN=2 \"-DSSID=\\\"This is a String\\\"\"")
// Tries compilation using multiple build properties separated by a comma // Tries compilation using multiple build properties separated by a comma
_, _, err = cli.Run( _, _, err = cli.Run(
"compile", "compile", "-b", fqbn,
"-b",
fqbn,
"--build-property=compiler.cpp.extra_flags=\"-DPIN=2,-DSSID=\"This is a String\"\"", "--build-property=compiler.cpp.extra_flags=\"-DPIN=2,-DSSID=\"This is a String\"\"",
sketchPath.String(), sketchPath.String(), "--verbose", "--clean",
"--verbose",
"--clean",
) )
require.Error(t, err) require.Error(t, err)
stdout, _, err = cli.Run( stdout, _, err = cli.Run(
"compile", "compile", "-b", fqbn,
"-b",
fqbn,
"--build-property=compiler.cpp.extra_flags=\"-DPIN=2\"", "--build-property=compiler.cpp.extra_flags=\"-DPIN=2\"",
"--build-property=compiler.cpp.extra_flags=\"-DSSID=\"This is a String\"\"", "--build-property=compiler.cpp.extra_flags=\"-DSSID=\"This is a String\"\"",
sketchPath.String(), sketchPath.String(), "--verbose", "--clean",
"--verbose",
"--clean",
) )
require.Error(t, err) require.Error(t, err)
require.NotContains(t, string(stdout), "-DPIN=2") require.NotContains(t, string(stdout), "-DPIN=2")
require.Contains(t, string(stdout), "-DSSID=\\\"This is a String\\\"") require.Contains(t, string(stdout), "-DSSID=\\\"This is a String\\\"")
stdout, _, err = cli.Run( stdout, _, err = cli.Run(
"compile", "compile", "-b", fqbn,
"-b",
fqbn,
"--build-property=compiler.cpp.extra_flags=\"-DPIN=2\"", "--build-property=compiler.cpp.extra_flags=\"-DPIN=2\"",
"--build-property=build.extra_flags=\"-DSSID=\"hello world\"\"", "--build-property=build.extra_flags=\"-DSSID=\"hello world\"\"",
sketchPath.String(), sketchPath.String(), "--verbose", "--clean",
"--verbose",
"--clean",
) )
require.NoError(t, err) require.NoError(t, err)
require.Contains(t, string(stdout), "-DPIN=2") require.Contains(t, string(stdout), "-DPIN=2")
require.Contains(t, string(stdout), "-DSSID=\\\"hello world\\\"") require.Contains(t, string(stdout), "-DSSID=\\\"hello world\\\"")
} }
func compileWithOutputDirFlag(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
sketchName := "CompileWithOutputDir"
sketchPath := cli.SketchbookDir().Join(sketchName)
defer sketchPath.RemoveAll()
fqbn := "arduino:avr:uno"
// Create a test sketch
stdout, _, err := cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err)
require.Contains(t, string(stdout), "Sketch created in: "+sketchPath.String())
// Test the --output-dir flag with absolute path
outputDir := cli.SketchbookDir().Join("test_dir", "output_dir")
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--output-dir", outputDir.String())
require.NoError(t, err)
// Verifies expected binaries have been built
md5 := md5.Sum(([]byte(sketchPath.String())))
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
require.NotEmpty(t, sketchPathMd5)
buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5)
require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String())
require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String())
require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String())
require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String())
require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String())
// Verifies binaries are exported when --output-dir flag is specified
require.DirExists(t, outputDir.String())
require.FileExists(t, outputDir.Join(sketchName+".ino.eep").String())
require.FileExists(t, outputDir.Join(sketchName+".ino.elf").String())
require.FileExists(t, outputDir.Join(sketchName+".ino.hex").String())
require.FileExists(t, outputDir.Join(sketchName+".ino.with_bootloader.bin").String())
require.FileExists(t, outputDir.Join(sketchName+".ino.with_bootloader.hex").String())
}
func compileWithExportBinariesFlag(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
sketchName := "CompileWithExportBinariesFlag"
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)
// Test the --output-dir flag with absolute path
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--export-binaries")
require.NoError(t, err)
require.DirExists(t, sketchPath.Join("build").String())
// Verifies binaries are exported when --export-binaries flag is set
fqbn = strings.ReplaceAll(fqbn, ":", ".")
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.eep").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.elf").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.hex").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.bin").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.hex").String())
}
func compileWithCustomBuildPath(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
sketchName := "CompileWithBuildPath"
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)
// Test the --build-path flag with absolute path
buildPath := cli.DataDir().Join("test_dir", "build_dir")
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--build-path", buildPath.String())
require.NoError(t, err)
// Verifies expected binaries have been built to build_path
require.DirExists(t, buildPath.String())
require.FileExists(t, buildPath.Join(sketchName+".ino.eep").String())
require.FileExists(t, buildPath.Join(sketchName+".ino.elf").String())
require.FileExists(t, buildPath.Join(sketchName+".ino.hex").String())
require.FileExists(t, buildPath.Join(sketchName+".ino.with_bootloader.bin").String())
require.FileExists(t, buildPath.Join(sketchName+".ino.with_bootloader.hex").String())
// Verifies there are no binaries in temp directory
md5 := md5.Sum(([]byte(sketchPath.String())))
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
require.NotEmpty(t, sketchPathMd5)
buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5)
require.NoFileExists(t, buildDir.Join(sketchName+".ino.eep").String())
require.NoFileExists(t, buildDir.Join(sketchName+".ino.elf").String())
require.NoFileExists(t, buildDir.Join(sketchName+".ino.hex").String())
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String())
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String())
}
func compileWithExportBinariesEnvVar(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
sketchName := "CompileWithExportBinariesEnvVar"
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)
envVar := cli.GetDefaultEnv()
envVar["ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES"] = "true"
// Test compilation with export binaries env var set
_, _, err = cli.RunWithCustomEnv(envVar, "compile", "-b", fqbn, sketchPath.String())
require.NoError(t, err)
require.DirExists(t, sketchPath.Join("build").String())
// Verifies binaries are exported when export binaries env var is set
fqbn = strings.ReplaceAll(fqbn, ":", ".")
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.eep").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.elf").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.hex").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.bin").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.hex").String())
}
func compileWithExportBinariesConfig(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
sketchName := "CompileWithExportBinariesEnvVar"
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)
// Create settings with export binaries set to true
envVar := cli.GetDefaultEnv()
envVar["ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES"] = "true"
_, _, err = cli.RunWithCustomEnv(envVar, "config", "init", "--dest-dir", ".")
require.NoError(t, err)
defer cli.WorkingDir().Join("arduino-cli.yaml").Remove()
// Test if arduino-cli config file written in the previous run has the `always_export_binaries` flag set.
stdout, _, err := cli.Run("config", "dump", "--format", "json")
require.NoError(t, err)
requirejson.Contains(t, stdout, `
{
"sketch": {
"always_export_binaries": "true"
}
}`)
// Test compilation with export binaries env var set
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String())
require.NoError(t, err)
require.DirExists(t, sketchPath.Join("build").String())
// Verifies binaries are exported when export binaries env var is set
fqbn = strings.ReplaceAll(fqbn, ":", ".")
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.eep").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.elf").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.hex").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.bin").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.hex").String())
}
func compileWithInvalidUrl(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
sketchName := "CompileWithInvalidURL"
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)
_, _, err = cli.Run("config", "init", "--dest-dir", ".", "--additional-urls", "https://example.com/package_example_index.json")
require.NoError(t, err)
defer cli.WorkingDir().Join("arduino-cli.yaml").Remove()
_, stderr, err := cli.Run("compile", "-b", fqbn, sketchPath.String())
require.NoError(t, err)
require.Contains(t, string(stderr), "Error initializing instance: Loading index file: loading json index file")
expectedIndexfile := cli.DataDir().Join("package_example_index.json")
require.Contains(t, string(stderr), "loading json index file "+expectedIndexfile.String()+": open "+expectedIndexfile.String()+":")
}
...@@ -13,261 +13,69 @@ ...@@ -13,261 +13,69 @@
// Arduino software without disclosing the source code of your own applications. // Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc. // To purchase a commercial license, send an email to license@arduino.cc.
package compile_part_1_test package compile_test
import ( import (
"crypto/md5"
"encoding/hex"
"encoding/json" "encoding/json"
"strings"
"testing" "testing"
"github.com/arduino/arduino-cli/internal/integrationtest" "github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/arduino/go-paths-helper" "github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.bug.st/testifyjson/requirejson"
) )
func TestCompileWithOutputDirFlag(t *testing.T) { func TestCompileWithoutPrecompiledLibraries(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp() defer env.CleanUp()
// Init the environment explicitly // Init the environment explicitly
_, _, err := cli.Run("core", "update-index") url := "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json"
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url)
require.NoError(t, err) require.NoError(t, err)
_, _, err = cli.Run("core", "install", "arduino:mbed@1.3.1", "--additional-urls="+url)
// Download latest AVR
_, _, err = cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)
sketchName := "CompileWithOutputDir"
sketchPath := cli.SketchbookDir().Join(sketchName)
fqbn := "arduino:avr:uno"
// Create a test sketch
stdout, _, err := cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err)
require.Contains(t, string(stdout), "Sketch created in: "+sketchPath.String())
// Test the --output-dir flag with absolute path
outputDir := cli.SketchbookDir().Join("test_dir", "output_dir")
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--output-dir", outputDir.String())
require.NoError(t, err)
// Verifies expected binaries have been built
md5 := md5.Sum(([]byte(sketchPath.String())))
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
require.NotEmpty(t, sketchPathMd5)
buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5)
require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String())
require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String())
require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String())
require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String())
require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String())
// Verifies binaries are exported when --output-dir flag is specified
require.DirExists(t, outputDir.String())
require.FileExists(t, outputDir.Join(sketchName+".ino.eep").String())
require.FileExists(t, outputDir.Join(sketchName+".ino.elf").String())
require.FileExists(t, outputDir.Join(sketchName+".ino.hex").String())
require.FileExists(t, outputDir.Join(sketchName+".ino.with_bootloader.bin").String())
require.FileExists(t, outputDir.Join(sketchName+".ino.with_bootloader.hex").String())
}
func TestCompileWithExportBinariesFlag(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
// Download latest AVR
_, _, err = cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)
sketchName := "CompileWithExportBinariesFlag"
sketchPath := cli.SketchbookDir().Join(sketchName)
fqbn := "arduino:avr:uno"
// Create a test sketch
_, _, err = cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err) require.NoError(t, err)
// Test the --output-dir flag with absolute path // // Precompiled version of Arduino_TensorflowLite
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--export-binaries") // _, _, err = cli.Run("lib", "install", "Arduino_LSM9DS1")
require.NoError(t, err) // require.NoError(t, err)
require.DirExists(t, sketchPath.Join("build").String()) // _, _, err = cli.Run("lib", "install", "Arduino_TensorflowLite@2.1.1-ALPHA-precompiled")
// require.NoError(t, err)
// Verifies binaries are exported when --export-binaries flag is set
fqbn = strings.ReplaceAll(fqbn, ":", ".")
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.eep").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.elf").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.hex").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.bin").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.hex").String())
}
func TestCompileWithCustomBuildPath(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
// Download latest AVR
_, _, err = cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)
sketchName := "CompileWithBuildPath"
sketchPath := cli.SketchbookDir().Join(sketchName)
fqbn := "arduino:avr:uno"
// Create a test sketch // sketchPath := cli.SketchbookDir().Join("libraries", "Arduino_TensorFlowLite", "examples", "hello_world")
_, _, err = cli.Run("sketch", "new", sketchPath.String()) // _, _, err = cli.Run("compile", "-b", "arduino:mbed:nano33ble", sketchPath.String())
require.NoError(t, err) // require.NoError(t, err)
// Test the --build-path flag with absolute path _, _, err = cli.Run("core", "install", "arduino:samd@1.8.7", "--additional-urls="+url)
buildPath := cli.DataDir().Join("test_dir", "build_dir")
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--build-path", buildPath.String())
require.NoError(t, err) require.NoError(t, err)
// _, _, err = cli.Run("core", "install", "adafruit:samd@1.6.4", "--additional-urls="+url)
// require.NoError(t, err)
// // should work on adafruit too after https://github.com/arduino/arduino-cli/pull/1134
// _, _, err = cli.Run("compile", "-b", "adafruit:samd:adafruit_feather_m4", sketchPath.String())
// require.NoError(t, err)
// Verifies expected binaries have been built to build_path // // Non-precompiled version of Arduino_TensorflowLite
require.DirExists(t, buildPath.String()) // _, _, err = cli.Run("lib", "install", "Arduino_TensorflowLite@2.1.0-ALPHA")
require.FileExists(t, buildPath.Join(sketchName+".ino.eep").String()) // require.NoError(t, err)
require.FileExists(t, buildPath.Join(sketchName+".ino.elf").String()) // _, _, err = cli.Run("compile", "-b", "arduino:mbed:nano33ble", sketchPath.String())
require.FileExists(t, buildPath.Join(sketchName+".ino.hex").String()) // require.NoError(t, err)
require.FileExists(t, buildPath.Join(sketchName+".ino.with_bootloader.bin").String()) // _, _, err = cli.Run("compile", "-b", "adafruit:samd:adafruit_feather_m4", sketchPath.String())
require.FileExists(t, buildPath.Join(sketchName+".ino.with_bootloader.hex").String()) // require.NoError(t, err)
// Verifies there are no binaries in temp directory
md5 := md5.Sum(([]byte(sketchPath.String())))
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
require.NotEmpty(t, sketchPathMd5)
buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5)
require.NoFileExists(t, buildDir.Join(sketchName+".ino.eep").String())
require.NoFileExists(t, buildDir.Join(sketchName+".ino.elf").String())
require.NoFileExists(t, buildDir.Join(sketchName+".ino.hex").String())
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String())
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String())
}
func TestCompileWithExportBinariesEnvVar(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly // Bosch sensor library
_, _, err := cli.Run("core", "update-index") _, _, err = cli.Run("lib", "install", "BSEC Software Library@1.5.1474")
require.NoError(t, err)
// Download latest AVR
_, _, err = cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)
sketchName := "CompileWithExportBinariesEnvVar"
sketchPath := cli.SketchbookDir().Join(sketchName)
fqbn := "arduino:avr:uno"
// Create a test sketch
_, _, err = cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err)
envVar := cli.GetDefaultEnv()
envVar["ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES"] = "true"
// Test compilation with export binaries env var set
_, _, err = cli.RunWithCustomEnv(envVar, "compile", "-b", fqbn, sketchPath.String())
require.NoError(t, err)
require.DirExists(t, sketchPath.Join("build").String())
// Verifies binaries are exported when export binaries env var is set
fqbn = strings.ReplaceAll(fqbn, ":", ".")
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.eep").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.elf").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.hex").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.bin").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.hex").String())
}
func TestCompileWithExportBinariesConfig(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
// Download latest AVR
_, _, err = cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)
sketchName := "CompileWithExportBinariesEnvVar"
sketchPath := cli.SketchbookDir().Join(sketchName)
fqbn := "arduino:avr:uno"
// Create a test sketch
_, _, err = cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err)
// Create settings with export binaries set to true
envVar := cli.GetDefaultEnv()
envVar["ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES"] = "true"
_, _, err = cli.RunWithCustomEnv(envVar, "config", "init", "--dest-dir", ".")
require.NoError(t, err)
// Test if arduino-cli config file written in the previous run has the `always_export_binaries` flag set.
stdout, _, err := cli.Run("config", "dump", "--format", "json")
require.NoError(t, err)
requirejson.Contains(t, stdout, `
{
"sketch": {
"always_export_binaries": "true"
}
}`)
// Test compilation with export binaries env var set
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String())
require.NoError(t, err)
require.DirExists(t, sketchPath.Join("build").String())
// Verifies binaries are exported when export binaries env var is set
fqbn = strings.ReplaceAll(fqbn, ":", ".")
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.eep").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.elf").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.hex").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.bin").String())
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.hex").String())
}
func TestCompileWithInvalidUrl(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Init the environment explicitly
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err) require.NoError(t, err)
sketchPath := cli.SketchbookDir().Join("libraries", "BSEC_Software_Library", "examples", "basic")
// Download latest AVR _, _, err = cli.Run("compile", "-b", "arduino:samd:mkr1000", sketchPath.String())
_, _, err = cli.Run("core", "install", "arduino:avr")
require.NoError(t, err) require.NoError(t, err)
_, _, err = cli.Run("compile", "-b", "arduino:mbed:nano33ble", sketchPath.String())
sketchName := "CompileWithInvalidURL"
sketchPath := cli.SketchbookDir().Join(sketchName)
fqbn := "arduino:avr:uno"
// Create a test sketch
_, _, err = cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err) require.NoError(t, err)
_, _, err = cli.Run("config", "init", "--dest-dir", ".", "--additional-urls", "https://example.com/package_example_index.json") // USBBlaster library
_, _, err = cli.Run("lib", "install", "USBBlaster@1.0.0")
require.NoError(t, err) require.NoError(t, err)
sketchPath = cli.SketchbookDir().Join("libraries", "USBBlaster", "examples", "USB_Blaster")
_, stderr, err := cli.Run("compile", "-b", fqbn, sketchPath.String()) _, _, err = cli.Run("compile", "-b", "arduino:samd:mkrvidor4000", sketchPath.String())
require.NoError(t, err) require.NoError(t, err)
require.Contains(t, string(stderr), "Error initializing instance: Loading index file: loading json index file")
expectedIndexfile := cli.DataDir().Join("package_example_index.json")
require.Contains(t, string(stderr), "loading json index file "+expectedIndexfile.String()+": open "+expectedIndexfile.String()+":")
} }
func TestCompileWithCustomLibraries(t *testing.T) { func TestCompileWithCustomLibraries(t *testing.T) {
......
...@@ -22,7 +22,7 @@ import ( ...@@ -22,7 +22,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestDebuggerStarts(t *testing.T) { func TestDebug(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp() defer env.CleanUp()
...@@ -34,12 +34,20 @@ func TestDebuggerStarts(t *testing.T) { ...@@ -34,12 +34,20 @@ func TestDebuggerStarts(t *testing.T) {
_, _, err = cli.Run("core", "install", "arduino:samd") _, _, err = cli.Run("core", "install", "arduino:samd")
require.NoError(t, err) require.NoError(t, err)
integrationtest.CLISubtests{
{"Start", testDebuggerStarts},
{"WithPdeSketchStarts", testDebuggerWithPdeSketchStarts},
}.Run(t, env, cli)
}
func testDebuggerStarts(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
// Create sketch for testing // Create sketch for testing
sketchName := "DebuggerStartTest" sketchName := "DebuggerStartTest"
sketchPath := cli.DataDir().Join(sketchName) sketchPath := cli.DataDir().Join(sketchName)
defer sketchPath.RemoveAll()
fqbn := "arduino:samd:mkr1000" fqbn := "arduino:samd:mkr1000"
_, _, err = cli.Run("sketch", "new", sketchPath.String()) _, _, err := cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err) require.NoError(t, err)
// Build sketch // Build sketch
...@@ -52,22 +60,13 @@ func TestDebuggerStarts(t *testing.T) { ...@@ -52,22 +60,13 @@ func TestDebuggerStarts(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
} }
func TestDebuggerWithPdeSketchStarts(t *testing.T) { func testDebuggerWithPdeSketchStarts(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
_, _, err := cli.Run("update")
require.NoError(t, err)
// Install core
_, _, err = cli.Run("core", "install", "arduino:samd")
require.NoError(t, err)
sketchName := "DebuggerPdeSketchStartTest" sketchName := "DebuggerPdeSketchStartTest"
sketchPath := cli.DataDir().Join(sketchName) sketchPath := cli.DataDir().Join(sketchName)
defer sketchPath.RemoveAll()
fqbn := "arduino:samd:mkr1000" fqbn := "arduino:samd:mkr1000"
_, _, err = cli.Run("sketch", "new", sketchPath.String()) _, _, err := cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err) require.NoError(t, err)
// Looks for sketch file .ino // Looks for sketch file .ino
......
// 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 integrationtest
import "testing"
// CLISubtests is a suite of tests to run under the same integreationtest.Environment
type CLISubtests []struct {
Name string
Function func(*testing.T, *Environment, *ArduinoCLI)
}
// Run runs the test suite as subtests of the current test
func (testSuite CLISubtests) Run(t *testing.T, env *Environment, cli *ArduinoCLI) {
for _, test := range testSuite {
t.Run(test.Name, func(t *testing.T) {
test.Function(t, env, cli)
})
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment