Skip to content

[skip-changelog] Set test environment directory as CLI WorkingDir #1886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions internal/integrationtest/arduino-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func init() {

// FindRepositoryRootPath returns the repository root path
func FindRepositoryRootPath(t *testing.T) *paths.Path {
repoRootPath := paths.New(".")
require.NoError(t, repoRootPath.ToAbs())
repoRootPath, err := paths.Getwd()
require.NoError(t, err)
for !repoRootPath.Join(".git").Exist() {
require.Contains(t, repoRootPath.String(), "arduino-cli", "Error searching for repository root path")
repoRootPath = repoRootPath.Parent()
Expand Down Expand Up @@ -75,6 +75,7 @@ type ArduinoCLI struct {
stagingDir *paths.Path
dataDir *paths.Path
sketchbookDir *paths.Path
workingDir *paths.Path
daemonAddr string
daemonConn *grpc.ClientConn
daemonClient commands.ArduinoCoreServiceClient
Expand All @@ -96,6 +97,7 @@ func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoC
dataDir: env.RootDir().Join("A"),
sketchbookDir: env.RootDir().Join("Arduino"),
stagingDir: env.RootDir().Join("Arduino15/staging"),
workingDir: env.RootDir(),
}
if config.UseSharedStagingFolder {
cli.stagingDir = env.SharedDownloadsDir()
Expand Down Expand Up @@ -130,6 +132,11 @@ func (cli *ArduinoCLI) SketchbookDir() *paths.Path {
return cli.sketchbookDir
}

// WorkingDir returns the working directory
func (cli *ArduinoCLI) WorkingDir() *paths.Path {
return cli.workingDir
}

// CopySketch copies a sketch inside the testing environment and returns its path
func (cli *ArduinoCLI) CopySketch(sketchName string) *paths.Path {
p, err := paths.Getwd()
Expand Down Expand Up @@ -180,6 +187,7 @@ func (cli *ArduinoCLI) RunWithCustomEnv(env map[string]string, args ...string) (
cli.t.NoError(err)
_, err = cliProc.StdinPipe()
cli.t.NoError(err)
cliProc.SetDir(cli.WorkingDir().String())

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

Expand Down
5 changes: 1 addition & 4 deletions internal/integrationtest/compile/compile_part_1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ func TestOutputFlagDefaultPath(t *testing.T) {
require.NoError(t, err)

// Test the --output-dir flag defaulting to current working dir
workingDir, err := paths.Getwd()
require.NoError(t, err)
target := workingDir.Join("test")
defer target.RemoveAll()
target := cli.WorkingDir().Join("test")
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--output-dir", "test")
require.NoError(t, err)
require.DirExists(t, target.String())
Expand Down
3 changes: 1 addition & 2 deletions internal/integrationtest/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"testing"

"github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
"go.bug.st/testsuite"
)
Expand All @@ -31,7 +30,7 @@ func createEnvForDaemon(t *testing.T) (*testsuite.Environment, *integrationtest.
env := testsuite.NewEnvironment(t)

cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"),
ArduinoCLIPath: integrationtest.FindRepositoryRootPath(t).Join("arduino-cli"),
UseSharedStagingFolder: true,
})

Expand Down