8000 Porting `legacy` tests to new integration-test infra (part 3...) by cmaglie · Pull Request #2300 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

Porting legacy tests to new integration-test infra (part 3...) #2300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments. Retry
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Grouped tests inside the same correct sub-group
  • Loading branch information
cmaglie committed Sep 7, 2023
commit aa0e293745acd552c73b7fd0efdeb02f4f048c67
91 changes: 46 additions & 45 deletions internal/integrationtest/compile_1/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func TestCompile(t *testing.T) {
{"WithMultipleBuildPropertyFlags", compileWithMultipleBuildPropertyFlags},
{"WithOutputDirFlag", compileWithOutputDirFlag},
{"WithExportBinariesFlag", compileWithExportBinariesFlag},
{"WithCustomBuildPath", compileWithCustomBuildPath},
{"WithExportBinariesEnvVar", compileWithExportBinariesEnvVar},
{"WithExportBinariesConfig", compileWithExportBinariesConfig},
{"WithInvalidUrl", compileWithInvalidUrl},
Expand All @@ -73,7 +72,7 @@ func TestCompile(t *testing.T) {
{"WithRelativeBuildPath", compileWithRelativeBuildPath},
{"WithFakeSecureBootCore", compileWithFakeSecureBootCore},
{"PreprocessFlagDoNotMessUpWithOutput", preprocessFlagDoNotMessUpWithOutput},
{"BuildWithBuildPathInSketchDir", buildWithBuildPathInSketchDir},
{"WithCustomBuildPath", buildWithCustomBuildPath},
}.Run(t, env, cli)
}

Expand Down Expand Up @@ -449,41 +448,6 @@ func compileWithExportBinariesFlag(t *testing.T, env *integrationtest.Environmen
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", "sketches", 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)
Expand Down Expand Up @@ -1206,17 +1170,54 @@ void loop() {
require.Equal(t, expected, string(output))
}

func buildWithBuildPathInSketchDir(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
func buildWithCustomBuildPath(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
sketchName := "bare_minimum"
sketchPath := cli.CopySketch(sketchName)
defer sketchPath.RemoveAll()
buildPath := sketchPath.Join("build")

// Run build
_, _, err := cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
require.NoError(t, err)
t.Run("OutsideSketch", func(t *testing.T) {
sketchName := "CompileWithBuildPath"
sketchPath := cli.SketchbookDir().Join(sketchName)
defer sketchPath.RemoveAll()
fqbn := "arduino:avr:uno"

// Run build twice, to verify the build still works when the build directory is present at the start
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
require.NoError(t, err)
// 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", "sketches", 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())
})

t.Run("InsideSketch", func(t *testing.T) {
buildPath := sketchPath.Join("build")

// Run build
_, _, err := cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
require.NoError(t, err)
// Run build twice, to verify the build still works when the build directory is present at the start
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
require.NoError(t, err)
})
}
0