Skip to content

Commit 0210d00

Browse files
committed
Updated integration test
1 parent 3a6feb9 commit 0210d00

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

internal/integrationtest/compile_1/compile_test.go

+21-12
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,17 @@ func compileWithSimpleSketch(t *testing.T, env *integrationtest.Environment, cli
125125

126126
func compileWithCachePurgeNeeded(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
127127
// create directories that must be purged
128-
baseDir := paths.TempDir().Join("arduino", "sketches")
128+
out, _, err := cli.Run("config", "get", "build_cache.path")
129+
require.NoError(t, err)
130+
cacheDir := paths.New(strings.TrimSpace(string(out))).Join("sketches")
129131

130132
// purge case: last used file too old
131-
oldDir1 := baseDir.Join("test_old_sketch_1")
133+
oldDir1 := cacheDir.Join("test_old_sketch_1")
132134
require.NoError(t, oldDir1.MkdirAll())
133135
require.NoError(t, oldDir1.Join(".last-used").WriteFile([]byte{}))
134136
require.NoError(t, oldDir1.Join(".last-used").Chtimes(time.Now(), time.Unix(0, 0)))
135137
// no purge case: last used file not existing
136-
missingFileDir := baseDir.Join("test_sketch_2")
138+
missingFileDir := cacheDir.Join("test_sketch_2")
137139
require.NoError(t, missingFileDir.MkdirAll())
138140

139141
defer oldDir1.RemoveAll()
@@ -172,12 +174,13 @@ func compileWithSimpleSketchCustomEnv(t *testing.T, env *integrationtest.Environ
172174
require.NoError(t, err)
173175
require.NotEmpty(t, compileOutput["compiler_out"])
174176
require.Empty(t, compileOutput["compiler_err"])
177+
builderResult := compileOutput["builder_result"].(map[string]any)
178+
buildDir := paths.New(builderResult["build_path"].(string))
175179

176180
// Verifies expected binaries have been built
177181
md5 := md5.Sum(([]byte(sketchPath.String())))
178182
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
179183
require.NotEmpty(t, sketchPathMd5)
180-
buildDir := paths.TempDir().Join("arduino", "sketches", sketchPathMd5)
181184
require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String())
182185
require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String())
183186
require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String())
@@ -427,11 +430,16 @@ func compileWithOutputDirFlag(t *testing.T, env *integrationtest.Environment, cl
427430
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--output-dir", outputDir.String())
428431
require.NoError(t, err)
429432

433+
// Get default build cache dir
434+
out, _, err := cli.Run("config", "get", "build_cache.path")
435+
require.NoError(t, err)
436+
buildCache := paths.New(strings.TrimSpace(string(out)))
437+
430438
// Verifies expected binaries have been built
431439
md5 := md5.Sum(([]byte(sketchPath.String())))
432440
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
433441
require.NotEmpty(t, sketchPathMd5)
434-
buildDir := paths.TempDir().Join("arduino", "sketches", sketchPathMd5)
442+
buildDir := buildCache.Join("sketches", sketchPathMd5)
435443
require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String())
436444
require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String())
437445
require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String())
@@ -1008,14 +1016,15 @@ func compileWithInvalidBuildOptionJson(t *testing.T, env *integrationtest.Enviro
10081016
_, _, err := cli.Run("sketch", "new", sketchPath.String())
10091017
require.NoError(t, err)
10101018

1011-
// Get the build directory
1012-
md5 := md5.Sum(([]byte(sketchPath.String())))
1013-
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
1014-
require.NotEmpty(t, sketchPathMd5)
1015-
buildDir := paths.TempDir().Join("arduino", "sketches", sketchPathMd5)
1016-
1017-
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--verbose")
1019+
out, _, err := cli.Run("compile", "-b", fqbn, sketchPath.String(), "--json")
10181020
require.NoError(t, err)
1021+
var builderOutput struct {
1022+
BuilderResult struct {
1023+
BuildPath string `json:"build_path"`
1024+
} `json:"builder_result"`
1025+
}
1026+
require.NoError(t, json.Unmarshal(out, &builderOutput))
1027+
buildDir := paths.New(builderOutput.BuilderResult.BuildPath)
10191028

10201029
// Breaks the build.options.json file
10211030
buildOptionsJson := buildDir.Join("build.options.json")

0 commit comments

Comments
 (0)