Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1fda6db

Browse files
committed
Prepare infra to add integration test
1 parent eb89f2d commit 1fda6db

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

‎internal/integrationtest/compile_4/compile_test.go‎

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -904,56 +904,58 @@ func comparePreprocessGoldenFile(t *testing.T, sketchDir *paths.Path, preprocess
904904
require.Equal(t, buf.String(), strings.ReplaceAll(preprocessedSketch, "\r\n", "\n"))
905905
}
906906

907-
func TestCoreCaching(t *testing.T) {
907+
func TestBuildCaching(t *testing.T) {
908908
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
909909
defer env.CleanUp()
910910

911-
sketchPath, err := paths.New("..", "testdata", "bare_minimum").Abs()
912-
require.NoError(t, err)
913-
914911
// Install Arduino AVR Boards
915-
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.6")
912+
_, _, err := cli.Run("core", "install", "arduino:avr@1.8.6")
916913
require.NoError(t, err)
917914

918-
// Create temporary cache dir
919-
buildCachePath, err := paths.MkTempDir("", "test_build_cache")
920-
require.NoError(t, err)
921-
defer buildCachePath.RemoveAll()
915+
t.Run("CoreCaching", func(t *testing.T) {
916+
sketchPath, err := paths.New("..", "testdata", "bare_minimum").Abs()
917+
require.NoError(t, err)
922918

923-
// Build first time
924-
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String())
925-
require.NoError(t, err)
919+
// Create temporary cache dir
920+
buildCachePath, err := paths.MkTempDir("", "test_build_cache")
921+
require.NoError(t, err)
922+
defer buildCachePath.RemoveAll()
926923

927-
// Find cached core and save timestamp
928-
pathList, err := buildCachePath.ReadDirRecursiveFiltered(nil, paths.FilterPrefixes("core.a"))
929-
require.NoError(t, err)
930-
require.Len(t, pathList, 1)
931-
cachedCoreFile := pathList[0]
932-
lastUsedPath := cachedCoreFile.Parent().Join(".last-used")
933-
require.True(t, lastUsedPath.Exist())
934-
coreStatBefore, err := cachedCoreFile.Stat()
935-
require.NoError(t, err)
924+
// Build first time
925+
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String())
926+
require.NoError(t, err)
936927

937-
// Run build again and check timestamp is unchanged
938-
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String())
939-
require.NoError(t, err)
940-
coreStatAfterRebuild, err := cachedCoreFile.Stat()
941-
require.NoError(t, err)
942-
require.Equal(t, coreStatBefore.ModTime(), coreStatAfterRebuild.ModTime())
928+
// Find cached core and save timestamp
929+
pathList, err := buildCachePath.ReadDirRecursiveFiltered(nil, paths.FilterPrefixes("core.a"))
930+
require.NoError(t, err)
931+
require.Len(t, pathList, 1)
932+
cachedCoreFile := pathList[0]
933+
lastUsedPath := cachedCoreFile.Parent().Join(".last-used")
934+
require.True(t, lastUsedPath.Exist())
935+
coreStatBefore, err := cachedCoreFile.Stat()
936+
require.NoError(t, err)
943937

944-
// Touch a file of the core and check if the builder invalidate the cache
945-
time.Sleep(time.Second)
946-
now:=time.Now().Local()
947-
coreFolder:= cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.6")
948-
err=coreFolder.Join("cores", "arduino", "Arduino.h").Chtimes(now, now)
949-
require.NoError(t, err)
938+
// Run build again and check timestamp is unchanged
939+
_, _, err=cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String())
940+
require.NoError(t, err)
941+
coreStatAfterRebuild, err:= cachedCoreFile.Stat()
942+
require.NoError(t, err)
943+
require.Equal(t, coreStatBefore.ModTime(), coreStatAfterRebuild.ModTime())
950944

951-
// Run build again, to verify that the builder rebuilds core.a
952-
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String())
953-
require.NoError(t, err)
954-
coreStatAfterTouch, err := cachedCoreFile.Stat()
955-
require.NoError(t, err)
956-
require.NotEqual(t, coreStatBefore.ModTime(), coreStatAfterTouch.ModTime())
945+
// Touch a file of the core and check if the builder invalidate the cache
946+
time.Sleep(time.Second)
947+
now := time.Now().Local()
948+
coreFolder := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.6")
949+
err = coreFolder.Join("cores", "arduino", "Arduino.h").Chtimes(now, now)
950+
require.NoError(t, err)
951+
952+
// Run build again, to verify that the builder rebuilds core.a
953+
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String())
954+
require.NoError(t, err)
955+
coreStatAfterTouch, err := cachedCoreFile.Stat()
956+
require.NoError(t, err)
957+
require.NotEqual(t, coreStatBefore.ModTime(), coreStatAfterTouch.ModTime())
958+
})
957959
}
958960

959961
func TestMergeSketchWithBootloader(t *testing.T) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /