@@ -9,10 +9,12 @@ import (
9
9
"io/fs"
10
10
"os"
11
11
"path/filepath"
12
+ "regexp"
12
13
"strings"
13
14
"testing"
14
15
15
16
"github.com/google/go-cmp/cmp"
17
+ "go.jetify.com/devbox/internal/devbox/devopt"
16
18
"go.jetify.com/devbox/internal/envir"
17
19
"go.jetify.com/devbox/internal/shellgen"
18
20
)
@@ -105,3 +107,61 @@ If the new shellrc is correct, you can update the golden file with:
105
107
})
106
108
}
107
109
}
110
+
111
+ func TestShellPath (t * testing.T ) {
112
+ tests := []struct {
113
+ name string
114
+ envOpts devopt.EnvOptions
115
+ expected string
116
+ env map [string ]string
117
+ }{
118
+ {
119
+ name : "pure mode enabled" ,
120
+ envOpts : devopt.EnvOptions {
121
+ Pure : true ,
122
+ },
123
+ expected : `^/nix/store/.*/bin/bash$` ,
124
+ },
125
+ {
126
+ name : "pure mode disabled" ,
127
+ envOpts : devopt.EnvOptions {
128
+ Pure : false ,
129
+ },
130
+ env : map [string ]string {
131
+ envir .Shell : "/usr/local/bin/bash" ,
132
+ },
133
+ expected : "^/usr/local/bin/bash$" ,
134
+ },
135
+ }
136
+
137
+ for _ , test := range tests {
138
+ t .Run (test .name , func (t * testing.T ) {
139
+ for k , v := range test .env {
140
+ t .Setenv (k , v )
141
+ }
142
+ tmpDir := t .TempDir ()
143
+ err := InitConfig (tmpDir )
144
+ if err != nil {
145
+ t .Fatal ("Got InitConfig error:" , err )
146
+ }
147
+ d , err := Open (& devopt.Opts {
148
+ Dir : tmpDir ,
149
+ Stderr : os .Stderr ,
150
+ })
151
+ if err != nil {
152
+ t .Fatal ("Got Open error:" , err )
153
+ }
154
+ gotPath , err := d .shellPath (test .envOpts )
155
+ if err != nil {
156
+ t .Fatal ("Got shellPath error:" , err )
157
+ }
158
+ matched , err := regexp .MatchString (test .expected , gotPath )
159
+ if err != nil {
160
+ t .Fatal ("Got regexp.MatchString error:" , err )
161
+ }
162
+ if ! matched {
163
+ t .Errorf ("Expected shell path %s, but got %s" , test .expected , gotPath )
164
+ }
165
+ })
166
+ }
167
+ }
0 commit comments