Movatterモバイル変換


[0]ホーム

URL:


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

Commitd99c7c4

Browse files
committed
feat: Add test for cache clean
Clean cache files with command `arduino-cli cache clean`.
1 parent3345c6d commitd99c7c4

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

‎cli/cache/clean.go‎

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ package cache
1717

1818
import (
1919
"os"
20-
"path/filepath"
21-
"runtime"
2220

2321
"github.com/arduino/arduino-cli/cli/errorcodes"
2422
"github.com/arduino/arduino-cli/cli/feedback"
25-
"github.com/arduino/go-win32-utils"
2623
"github.com/sirupsen/logrus"
2724
"github.com/spf13/cobra"
25+
"github.com/spf13/viper"
2826
)
2927

3028
funcinitCleanCommand()*cobra.Command {
@@ -42,34 +40,10 @@ func initCleanCommand() *cobra.Command {
4240
funcrunCleanCommand(cmd*cobra.Command,args []string) {
4341
logrus.Info("Executing `arduino cache clean`")
4442

45-
cachePath:=getDefaultArduinoDataDir()+"/staging"
43+
cachePath:=viper.GetString("directories.Downloads")
4644
err:=os.RemoveAll(cachePath)
4745
iferr!=nil {
4846
feedback.Errorf("Error cleaning caches: %v",err)
4947
os.Exit(errorcodes.ErrGeneric)
5048
}
5149
}
52-
53-
funcgetDefaultArduinoDataDir()string {
54-
userHomeDir,err:=os.UserHomeDir()
55-
iferr!=nil {
56-
feedback.Errorf("Unable to get user home dir: %v",err)
57-
return"."
58-
}
59-
60-
switchruntime.GOOS {
61-
case"linux":
62-
returnfilepath.Join(userHomeDir,".arduino15")
63-
case"darwin":
64-
returnfilepath.Join(userHomeDir,"Library","Arduino15")
65-
case"windows":
66-
localAppDataPath,err:=win32.GetLocalAppDataFolder()
67-
iferr!=nil {
68-
feedback.Errorf("Unable to get Local App Data Folder: %v",err)
69-
return"."
70-
}
71-
returnfilepath.Join(localAppDataPath,"Arduino15")
72-
default:
73-
return"."
74-
}
75-
}

‎test/test_cache.py‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This file is part of arduino-cli.
2+
#
3+
# Copyright 2020 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 modify or
12+
# otherwise use the software for commercial activities involving the Arduino
13+
# software without disclosing the source code of your own applications. To purchase
14+
# a commercial license, send an email to license@arduino.cc.
15+
importos
16+
importplatform
17+
18+
19+
deftest_cache_clean(run_command):
20+
"""
21+
Clean the cache under arduino caching file directory which is
22+
"<Arduino configure file path>/staging"
23+
"""
24+
result=run_command("cache clean")
25+
assertresult.ok
26+
27+
# Generate /staging directory
28+
result=run_command("lib list")
29+
assertresult.ok
30+
31+
result=run_command("cache clean")
32+
assertresult.ok
33+
34+
running_platform=platform.system()
35+
homeDir=os.path.expanduser("~")
36+
ifrunning_platform=="Linux":
37+
assertnot (os.path.isdir(homeDir+".arduino15/staging"))
38+
elifrunning_platform=="Darwin":
39+
assertnot (os.path.isdir(homeDir+"Library/Arduino15/staging"))
40+
elifrunning_platform=="Windows":
41+
assertnot (os.path.isdir(homeDir+"Arduino15/staging"))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp