Skip to content

Commit fac6269

Browse files
committed
Added integration tests
1 parent a105754 commit fac6269

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
// Compile sketch with empty cache
47+
out, _, err := cli.Run("compile", "-v", "-b", "arduino:avr:uno", sketch.String())
48+
require.NoError(t, err)
49+
require.Contains(t, string(out), "Archiving built core (caching) in: "+defaultCache.String())
50+
51+
// Check that the core cache is re-used
52+
out, _, err = cli.Run("compile", "-v", "-b", "arduino:avr:uno", sketch.String())
53+
require.NoError(t, err)
54+
require.Contains(t, string(out), "Using precompiled core: "+defaultCache.String())
55+
56+
{
57+
env := cli.GetDefaultEnv()
58+
env["ARDUINO_BUILD_CACHE_PATH"] = cache1.String()
59+
60+
// Compile sketch with empty cache user-defined core cache
61+
out, _, err := cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", sketch.String())
62+
require.NoError(t, err)
63+
require.Contains(t, string(out), "Archiving built core (caching) in: "+cache1.String())
64+
65+
// Check that the core cache is re-used with user-defined core cache
66+
out, _, err = cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", sketch.String())
67+
require.NoError(t, err)
68+
require.Contains(t, string(out), "Using precompiled core: "+cache1.String())
69+
70+
// Clean run should rebuild and save in user-defined core cache
71+
out, _, err = cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", "--clean", sketch.String())
72+
require.NoError(t, err)
73+
require.Contains(t, string(out), "Archiving built core (caching) in: "+cache1.String())
74+
}
75+
76+
{
77+
env := cli.GetDefaultEnv()
78+
env["ARDUINO_BUILD_CACHE_EXTRA_PATHS"] = cache1.String()
79+
80+
// Both extra and default cache are full, should use the default one
81+
out, _, err := cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", sketch.String())
82+
require.NoError(t, err)
83+
require.Contains(t, string(out), "Using precompiled core: "+defaultCache.String())
84+
85+
// Clean run, should rebuild and save in default cache
86+
out, _, err = cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", "--clean", sketch.String())
87+
require.NoError(t, err)
88+
require.Contains(t, string(out), "Archiving built core (caching) in: "+defaultCache.String())
89+
}
90+
91+
{
92+
env := cli.GetDefaultEnv()
93+
env["ARDUINO_BUILD_CACHE_EXTRA_PATHS"] = cache1.String() // Populated
94+
env["ARDUINO_BUILD_CACHE_PATH"] = cache2.String() // Empty
95+
96+
// Extra cache is full, should use the cache1 (extra)
97+
out, _, err := cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", sketch.String())
98+
require.NoError(t, err)
99+
require.Contains(t, string(out), "Using precompiled core: "+cache1.String())
100+
101+
// Clean run, should rebuild and save in cache2 (user defined default cache)
102+
out, _, err = cli.RunWithCustomEnv(env, "compile", "-v", "-b", "arduino:avr:uno", "--clean", sketch.String())
103+
require.NoError(t, err)
104+
require.Contains(t, string(out), "Archiving built core (caching) in: "+cache2.String())
105+
106+
// Both caches are full, should use the cache2 (user defined default)
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: "+cache2.String())
110+
}
111+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}

0 commit comments

Comments
 (0)