Skip to content

Commit 44918ec

Browse files
committed
Update a few tests to work with windows paths system
1 parent eb00b69 commit 44918ec

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

internal/interpreters/r_test.go

+21-28
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ func (s *RSuite) TestRenvEnvironmentErrorCheck_renvNotInstalled() {
601601

602602
executor := executortest.NewMockExecutor()
603603
executor.On("RunCommand", mock.Anything, []string{"--version"}, mock.Anything, mock.Anything).Return([]byte("R version 4.3.0 (2023-04-21)"), nil, nil)
604-
executor.On("RunCommand", "/usr/bin/R", []string{"-s", "-e", "cat(system.file(package = \"renv\"))"}, mock.Anything, mock.Anything).Return([]byte(""), nil, nil)
604+
executor.On("RunCommand", mock.Anything, []string{"-s", "-e", "cat(system.file(package = \"renv\"))"}, mock.Anything, mock.Anything).Return([]byte(""), nil, nil)
605605

606606
i, _ := NewRInterpreter(s.cwd, util.Path{}, log, executor, nil, nil)
607607
interpreter := i.(*defaultRInterpreter)
@@ -613,11 +613,10 @@ func (s *RSuite) TestRenvEnvironmentErrorCheck_renvNotInstalled() {
613613
s.Error(err)
614614
s.Equal(err.GetCode(), types.ErrorRenvPackageNotInstalled)
615615
s.Equal(err.Message, "Package renv is not installed. An renv lockfile is needed for deployment.")
616-
s.Equal(err.Data, types.ErrorData{
617-
"Action": "renvsetup",
618-
"ActionLabel": "Setup renv",
619-
"Command": "/usr/bin/R -s -e \"install.packages(\\\"renv\\\"); renv::init();\"",
620-
})
616+
s.Equal(err.Data["Action"], "renvsetup")
617+
s.Equal(err.Data["ActionLabel"], "Setup renv")
618+
s.Contains(err.Data["Command"], "install.packages")
619+
s.Contains(err.Data["Command"], "renv::init()")
621620
}
622621

623622
func (s *RSuite) TestRenvEnvironmentErrorCheck_renvInstallCheckErr() {
@@ -626,7 +625,7 @@ func (s *RSuite) TestRenvEnvironmentErrorCheck_renvInstallCheckErr() {
626625
renvCmdErr := errors.New("renv command errrz")
627626
executor := executortest.NewMockExecutor()
628627
executor.On("RunCommand", mock.Anything, []string{"--version"}, mock.Anything, mock.Anything).Return([]byte("R version 4.3.0 (2023-04-21)"), nil, nil)
629-
executor.On("RunCommand", "/usr/bin/R", []string{"-s", "-e", "cat(system.file(package = \"renv\"))"}, mock.Anything, mock.Anything).Return([]byte(""), nil, renvCmdErr)
628+
executor.On("RunCommand", mock.Anything, []string{"-s", "-e", "cat(system.file(package = \"renv\"))"}, mock.Anything, mock.Anything).Return([]byte(""), nil, renvCmdErr)
630629

631630
i, _ := NewRInterpreter(s.cwd, util.Path{}, log, executor, nil, nil)
632631
interpreter := i.(*defaultRInterpreter)
@@ -647,8 +646,8 @@ func (s *RSuite) TestRenvEnvironmentErrorCheck_renvRequiresInit() {
647646
renvStatusOutput := []byte("Use `renv::init()` to initialize the project.")
648647
executor := executortest.NewMockExecutor()
649648
executor.On("RunCommand", mock.Anything, []string{"--version"}, mock.Anything, mock.Anything).Return([]byte("R version 4.3.0 (2023-04-21)"), nil, nil)
650-
executor.On("RunCommand", "/usr/bin/R", []string{"-s", "-e", "cat(system.file(package = \"renv\"))"}, mock.Anything, mock.Anything).Return([]byte("/usr/dir/lib/R/x86_64/4.4/library/renv"), nil, nil)
651-
executor.On("RunCommand", "/usr/bin/R", []string{"-s", "-e", "renv::status()"}, mock.Anything, mock.Anything).Return(renvStatusOutput, nil, nil)
649+
executor.On("RunCommand", mock.Anything, []string{"-s", "-e", "cat(system.file(package = \"renv\"))"}, mock.Anything, mock.Anything).Return([]byte("/usr/dir/lib/R/x86_64/4.4/library/renv"), nil, nil)
650+
executor.On("RunCommand", mock.Anything, []string{"-s", "-e", "renv::status()"}, mock.Anything, mock.Anything).Return(renvStatusOutput, nil, nil)
652651

653652
i, _ := NewRInterpreter(s.cwd, util.Path{}, log, executor, nil, nil)
654653
interpreter := i.(*defaultRInterpreter)
@@ -660,11 +659,9 @@ func (s *RSuite) TestRenvEnvironmentErrorCheck_renvRequiresInit() {
660659
s.Error(err)
661660
s.Equal(err.GetCode(), types.ErrorRenvActionRequired)
662661
s.Equal(err.Message, `Project requires renv initialization "renv::init()" to be deployed.`)
663-
s.Equal(err.Data, types.ErrorData{
664-
"Action": "renvinit",
665-
"ActionLabel": "Setup renv",
666-
"Command": "/usr/bin/R -s -e \"renv::init()\"",
667-
})
662+
s.Equal(err.Data["Action"], "renvinit")
663+
s.Equal(err.Data["ActionLabel"], "Setup renv")
664+
s.Contains(err.Data["Command"], "renv::init()")
668665
}
669666

670667
func (s *RSuite) TestRenvEnvironmentErrorCheck_lockfileMissing() {
@@ -673,8 +670,8 @@ func (s *RSuite) TestRenvEnvironmentErrorCheck_lockfileMissing() {
673670
renvStatusOutput := []byte("Use `renv::snapshot()` to create a lockfile.")
674671
executor := executortest.NewMockExecutor()
675672
executor.On("RunCommand", mock.Anything, []string{"--version"}, mock.Anything, mock.Anything).Return([]byte("R version 4.3.0 (2023-04-21)"), nil, nil)
676-
executor.On("RunCommand", "/usr/bin/R", []string{"-s", "-e", "cat(system.file(package = \"renv\"))"}, mock.Anything, mock.Anything).Return([]byte("/usr/dir/lib/R/x86_64/4.4/library/renv"), nil, nil)
677-
executor.On("RunCommand", "/usr/bin/R", []string{"-s", "-e", "renv::status()"}, mock.Anything, mock.Anything).Return(renvStatusOutput, nil, nil)
673+
executor.On("RunCommand", mock.Anything, []string{"-s", "-e", "cat(system.file(package = \"renv\"))"}, mock.Anything, mock.Anything).Return([]byte("/usr/dir/lib/R/x86_64/4.4/library/renv"), nil, nil)
674+
executor.On("RunCommand", mock.Anything, []string{"-s", "-e", "renv::status()"}, mock.Anything, mock.Anything).Return(renvStatusOutput, nil, nil)
678675

679676
i, _ := NewRInterpreter(s.cwd, util.Path{}, log, executor, nil, nil)
680677
interpreter := i.(*defaultRInterpreter)
@@ -686,11 +683,9 @@ func (s *RSuite) TestRenvEnvironmentErrorCheck_lockfileMissing() {
686683
s.Error(err)
687684
s.Equal(err.GetCode(), types.ErrorRenvActionRequired)
688685
s.Equal(err.Message, `Project requires renv to update the lockfile to be deployed.`)
689-
s.Equal(err.Data, types.ErrorData{
690-
"Action": "renvsnapshot",
691-
"ActionLabel": "Setup lockfile",
692-
"Command": "/usr/bin/R -s -e \"renv::snapshot()\"",
693-
})
686+
s.Equal(err.Data["Action"], "renvsnapshot")
687+
s.Equal(err.Data["ActionLabel"], "Setup lockfile")
688+
s.Contains(err.Data["Command"], "renv::snapshot()")
694689
}
695690

696691
func (s *RSuite) TestRenvEnvironmentErrorCheck_unknownRenvStatus() {
@@ -699,8 +694,8 @@ func (s *RSuite) TestRenvEnvironmentErrorCheck_unknownRenvStatus() {
699694
renvStatusOutput := []byte("- The project is out-of-sync -- use `renv::status()` for details.")
700695
executor := executortest.NewMockExecutor()
701696
executor.On("RunCommand", mock.Anything, []string{"--version"}, mock.Anything, mock.Anything).Return([]byte("R version 4.3.0 (2023-04-21)"), nil, nil)
702-
executor.On("RunCommand", "/usr/bin/R", []string{"-s", "-e", "cat(system.file(package = \"renv\"))"}, mock.Anything, mock.Anything).Return([]byte("/usr/dir/lib/R/x86_64/4.4/library/renv"), nil, nil)
703-
executor.On("RunCommand", "/usr/bin/R", []string{"-s", "-e", "renv::status()"}, mock.Anything, mock.Anything).Return(renvStatusOutput, nil, nil)
697+
executor.On("RunCommand", mock.Anything, []string{"-s", "-e", "cat(system.file(package = \"renv\"))"}, mock.Anything, mock.Anything).Return([]byte("/usr/dir/lib/R/x86_64/4.4/library/renv"), nil, nil)
698+
executor.On("RunCommand", mock.Anything, []string{"-s", "-e", "renv::status()"}, mock.Anything, mock.Anything).Return(renvStatusOutput, nil, nil)
704699

705700
i, _ := NewRInterpreter(s.cwd, util.Path{}, log, executor, nil, nil)
706701
interpreter := i.(*defaultRInterpreter)
@@ -712,9 +707,7 @@ func (s *RSuite) TestRenvEnvironmentErrorCheck_unknownRenvStatus() {
712707
s.Error(err)
713708
s.Equal(err.GetCode(), types.ErrorRenvActionRequired)
714709
s.Equal(err.Message, `The renv environment for this project is not in a healthy state. Run renv::status() for more details.`)
715-
s.Equal(err.Data, types.ErrorData{
716-
"Action": "renvstatus",
717-
"ActionLabel": "Run and show renv::status()",
718-
"Command": "/usr/bin/R -s -e \"renv::status()\"",
719-
})
710+
s.Equal(err.Data["Action"], "renvstatus")
711+
s.Equal(err.Data["ActionLabel"], "Run and show renv::status()")
712+
s.Contains(err.Data["Command"], "renv::status()")
720713
}

0 commit comments

Comments
 (0)