From aa0e293745acd552c73b7fd0efdeb02f4f048c67 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 7 Sep 2023 19:56:08 +0200 Subject: [PATCH] Grouped tests inside the same correct sub-group --- .../integrationtest/compile_1/compile_test.go | 91 ++++++++++--------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/internal/integrationtest/compile_1/compile_test.go b/internal/integrationtest/compile_1/compile_test.go index 0be102cbc0c..c90d2727e45 100644 --- a/internal/integrationtest/compile_1/compile_test.go +++ b/internal/integrationtest/compile_1/compile_test.go @@ -59,7 +59,6 @@ func TestCompile(t *testing.T) { {"WithMultipleBuildPropertyFlags", compileWithMultipleBuildPropertyFlags}, {"WithOutputDirFlag", compileWithOutputDirFlag}, {"WithExportBinariesFlag", compileWithExportBinariesFlag}, - {"WithCustomBuildPath", compileWithCustomBuildPath}, {"WithExportBinariesEnvVar", compileWithExportBinariesEnvVar}, {"WithExportBinariesConfig", compileWithExportBinariesConfig}, {"WithInvalidUrl", compileWithInvalidUrl}, @@ -73,7 +72,7 @@ func TestCompile(t *testing.T) { {"WithRelativeBuildPath", compileWithRelativeBuildPath}, {"WithFakeSecureBootCore", compileWithFakeSecureBootCore}, {"PreprocessFlagDoNotMessUpWithOutput", preprocessFlagDoNotMessUpWithOutput}, - {"BuildWithBuildPathInSketchDir", buildWithBuildPathInSketchDir}, + {"WithCustomBuildPath", buildWithCustomBuildPath}, }.Run(t, env, cli) } @@ -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) @@ -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) + }) }