Skip to content

Commit 0f7cca4

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 0f7cca4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

internal/integrationtest/arduino-cli.go

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

4444
// FindRepositoryRootPath returns the repository root path
4545
func FindRepositoryRootPath(t *testing.T) *paths.Path {
46-
repoRootPath := paths.New(".")
47-
require.NoError(t, repoRootPath.ToAbs())
46+
repoRootPath, err := paths.Getwd()
47+
require.NoError(t, err)
4848
for !repoRootPath.Join(".git").Exist() {
4949
require.Contains(t, repoRootPath.String(), "arduino-cli", "Error searching for repository root path")
5050
repoRootPath = repoRootPath.Parent()
@@ -75,6 +75,7 @@ type ArduinoCLI struct {
7575
stagingDir *paths.Path
7676
dataDir *paths.Path
7777
sketchbookDir *paths.Path
78+
workingDir *paths.Path
7879
daemonAddr string
7980
daemonConn *grpc.ClientConn
8081
daemonClient commands.ArduinoCoreServiceClient
@@ -96,6 +97,7 @@ func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoC
9697
dataDir: env.RootDir().Join("A"),
9798
sketchbookDir: env.RootDir().Join("Arduino"),
9899
stagingDir: env.RootDir().Join("Arduino15/staging"),
100+
workingDir: env.RootDir(),
99101
}
100102
if config.UseSharedStagingFolder {
101103
cli.stagingDir = env.SharedDownloadsDir()
@@ -130,6 +132,11 @@ func (cli *ArduinoCLI) SketchbookDir() *paths.Path {
130132
return cli.sketchbookDir
131133
}
132134

135+
// WorkingDir returns the working directory
136+
func (cli *ArduinoCLI) WorkingDir() *paths.Path {
137+
return cli.workingDir
138+
}
139+
133140
// CopySketch copies a sketch inside the testing environment and returns its path
134141
func (cli *ArduinoCLI) CopySketch(sketchName string) *paths.Path {
135142
p, err := paths.Getwd()
@@ -180,6 +187,7 @@ func (cli *ArduinoCLI) RunWithCustomEnv(env map[string]string, args ...string) (
180187
cli.t.NoError(err)
181188
_, err = cliProc.StdinPipe()
182189
cli.t.NoError(err)
190+
cliProc.SetDir(cli.WorkingDir().String())
183191

184192
cli.t.NoError(cliProc.Start())
185193

0 commit comments

Comments
 (0)