Skip to content

Commit 26063d9

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 5730e2e commit 26063d9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

internal/integrationtest/arduino-cli.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import (
3939

4040
// FindRepositoryRootPath returns the repository root path
4141
func FindRepositoryRootPath(t *testing.T) *paths.Path {
42-
repoRootPath := paths.New(".")
42+
repoRootPath, err := paths.Getwd()
43+
require.NoError(t, err)
4344
require.NoError(t, repoRootPath.ToAbs())
4445
for !repoRootPath.Join(".git").Exist() {
4546
require.Contains(t, repoRootPath.String(), "arduino-cli", "Error searching for repository root path")
@@ -71,6 +72,7 @@ type ArduinoCLI struct {
7172
stagingDir *paths.Path
7273
dataDir *paths.Path
7374
sketchbookDir *paths.Path
75+
workingDir *paths.Path
7476
daemonAddr string
7577
daemonConn *grpc.ClientConn
7678
daemonClient commands.ArduinoCoreServiceClient
@@ -92,6 +94,7 @@ func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoC
9294
dataDir: env.RootDir().Join("Arduino15"),
9395
sketchbookDir: env.RootDir().Join("Arduino"),
9496
stagingDir: env.RootDir().Join("Arduino15/staging"),
97+
workingDir: env.RootDir(),
9598
}
9699
if config.UseSharedStagingFolder {
97100
cli.stagingDir = env.SharedDownloadsDir()
@@ -126,6 +129,11 @@ func (cli *ArduinoCLI) SketchbookDir() *paths.Path {
126129
return cli.sketchbookDir
127130
}
128131

132+
// WorkingDir returns the working directory
133+
func (cli *ArduinoCLI) WorkingDir() *paths.Path {
134+
return cli.workingDir
135+
}
136+
129137
// CopySketch copies a sketch inside the testing environment and returns its path
130138
func (cli *ArduinoCLI) CopySketch(sketchName string) *paths.Path {
131139
p, err := paths.Getwd()
@@ -176,6 +184,7 @@ func (cli *ArduinoCLI) RunWithCustomEnv(env map[string]string, args ...string) (
176184
cli.t.NoError(err)
177185
_, err = cliProc.StdinPipe()
178186
cli.t.NoError(err)
187+
cliProc.SetDir(cli.WorkingDir().String())
179188

180189
cli.t.NoError(cliProc.Start())
181190

0 commit comments

Comments
 (0)