Skip to content

Commit 4c745c9

Browse files
Set test environment directory as CLI WorkingDir
By default, the working directory is the one containing the test.go file. This causes problems when executing commands that have to create files specifically in the working directory, because they either must be deleted manually or the user has to be aware of it and defer a deleting instruction. Furthermore, it messes with tests using relative paths. Setting the environment directory as the CLI's WorkingDir prevents the above mentioned issues from occurring.
1 parent 6c3755c commit 4c745c9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

internal/integrationtest/arduino-cli.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ func init() {
4343

4444
// FindRepositoryRootPath returns the repository root path
4545
func FindRepositoryRootPath(t *testing.T) *paths.Path {
46-
repoRootPath := paths.New(".")
46+
repoRootPath, err := paths.Getwd()
47+
require.NoError(t, err)
4748
require.NoError(t, repoRootPath.ToAbs())
4849
for !repoRootPath.Join(".git").Exist() {
4950
require.Contains(t, repoRootPath.String(), "arduino-cli", "Error searching for repository root path")
@@ -75,6 +76,7 @@ type ArduinoCLI struct {
7576
stagingDir *paths.Path
7677
dataDir *paths.Path
7778
sketchbookDir *paths.Path
79+
workingDir *paths.Path
7880
daemonAddr string
7981
daemonConn *grpc.ClientConn
8082
daemonClient commands.ArduinoCoreServiceClient
@@ -96,6 +98,7 @@ func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoC
9698
dataDir: env.RootDir().Join("A"),
9799
sketchbookDir: env.RootDir().Join("Arduino"),
98100
stagingDir: env.RootDir().Join("Arduino15/staging"),
101+
workingDir: env.RootDir(),
99102
}
100103
if config.UseSharedStagingFolder {
101104
cli.stagingDir = env.SharedDownloadsDir()
@@ -130,6 +133,11 @@ func (cli *ArduinoCLI) SketchbookDir() *paths.Path {
130133
return cli.sketchbookDir
131134
}
132135

136+
// WorkingDir returns the working directory
137+
func (cli *ArduinoCLI) WorkingDir() *paths.Path {
138+
return cli.workingDir
139+
}
140+
133141
// CopySketch copies a sketch inside the testing environment and returns its path
134142
func (cli *ArduinoCLI) CopySketch(sketchName string) *paths.Path {
135143
p, err := paths.Getwd()
@@ -180,6 +188,7 @@ func (cli *ArduinoCLI) RunWithCustomEnv(env map[string]string, args ...string) (
180188
cli.t.NoError(err)
181189
_, err = cliProc.StdinPipe()
182190
cli.t.NoError(err)
191+
cliProc.SetDir(cli.WorkingDir().String())
183192

184193
cli.t.NoError(cliProc.Start())
185194

0 commit comments

Comments
 (0)