Skip to content

Commit 8acaade

Browse files
committed
Added integration tests
1 parent 1b6d3ed commit 8acaade

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2023 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package compile_test
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/arduino-cli/internal/integrationtest"
22+
"github.com/arduino/go-paths-helper"
23+
"github.com/stretchr/testify/require"
24+
)
25+
26+
func TestBuildCacheCoreWithExtraDirs(t *testing.T) {
27+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
28+
t.Cleanup(env.CleanUp)
29+
30+
// Install Arduino AVR Boards
31+
_, _, err := cli.Run("core", "install", "arduino:[email protected]")
32+
require.NoError(t, err)
33+
34+
// Main core cache
35+
defaultCache := paths.TempDir().Join("arduino")
36+
cache1, err := paths.MkTempDir("", "core_cache")
37+
require.NoError(t, err)
38+
t.Cleanup(func() { cache1.RemoveAll() })
39+
cache2, err := paths.MkTempDir("", "extra_core_cache")
40+
require.NoError(t, err)
41+
t.Cleanup(func() { cache2.RemoveAll() })
42+
43+
sketch, err := paths.New("testdata", "BareMinimum").Abs()
44+
require.NoError(t, err)
45+
46+
{
47+
// Compile sketch with empty cache
48+
out, _, err := cli.Run("compile", "-v", "-b", "arduino:avr:uno", sketch.String())
49+
require.NoError(t, err)
50+
require.Contains(t, string(out), "Archiving built core (caching) in: "+defaultCache.String())
51+
52+
// Check that the core cache is re-used
53+
out, _, err = cli.Run("compile", "-v", "-b", "arduino:avr:uno", sketch.String())
54+
require.NoError(t, err)
55+
require.Contains(t, string(out), "Using precompiled core: "+defaultCache.String())
56+
}
57+
58+
{
59+
env := cli.GetDefaultEnv()
60+
env["ARDUINO_BUILD_CACHE_PATH"] = cache1.String()
61+
62+
// Compile sketch with empty cache user-defined core cache
63+
out, _, err := cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", sketch.String())
64+
require.NoError(t, err)
65+
require.Contains(t, string(out), "Archiving built core (caching) in: "+cache1.String())
66+
67+
// Check that the core cache is re-used with user-defined core cache
68+
out, _, err = cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", sketch.String())
69+
require.NoError(t, err)
70+
require.Contains(t, string(out), "Using precompiled core: "+cache1.String())
71+
72+
// Clean run should rebuild and save in user-defined core cache
73+
out, _, err = cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", "--clean", sketch.String())
74+
require.NoError(t, err)
75+
require.Contains(t, string(out), "Archiving built core (caching) in: "+cache1.String())
76+
}
77+
78+
{
79+
env := cli.GetDefaultEnv()
80+
env["ARDUINO_BUILD_CACHE_EXTRA_PATHS"] = cache1.String()
81+
82+
// Both extra and default cache are full, should use the default one
83+
out, _, err := cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", sketch.String())
84+
require.NoError(t, err)
85+
require.Contains(t, string(out), "Using precompiled core: "+defaultCache.String())
86+
87+
// Clean run, should rebuild and save in default cache
88+
out, _, err = cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", "--clean", sketch.String())
89+
require.NoError(t, err)
90+
require.Contains(t, string(out), "Archiving built core (caching) in: "+defaultCache.String())
91+
92+
// Clean default cache
93+
require.NoError(t, defaultCache.RemoveAll())
94+
95+
// Now, extra is full and default is empty, should use extra
96+
out, _, err = cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", sketch.String())
97+
require.NoError(t, err)
98+
require.Contains(t, string(out), "Using precompiled core: "+cache1.String())
99+
}
100+
101+
{
102+
env := cli.GetDefaultEnv()
103+
env["ARDUINO_BUILD_CACHE_EXTRA_PATHS"] = cache1.String() // Populated
104+
env["ARDUINO_BUILD_CACHE_PATH"] = cache2.String() // Empty
105+
106+
// Extra cache is full, should use the cache1 (extra)
107+
out, _, err := cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", sketch.String())
108+
require.NoError(t, err)
109+
require.Contains(t, string(out), "Using precompiled core: "+cache1.String())
110+
111+
// Clean run, should rebuild and save in cache2 (user defined default cache)
112+
out, _, err = cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", "--clean", sketch.String())
113+
require.NoError(t, err)
114+
require.Contains(t, string(out), "Archiving built core (caching) in: "+cache2.String())
115+
116+
// Both caches are full, should use the cache2 (user defined default)
117+
out, _, err = cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", sketch.String())
118+
require.NoError(t, err)
119+
require.Contains(t, string(out), "Using precompiled core: "+cache2.String())
120+
}
121+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}

0 commit comments

Comments
 (0)