@@ -116,11 +116,65 @@ func TestDotfiles(t *testing.T) {
116
116
require .NoError (t ,staterr )
117
117
require .True (t ,stat .IsDir ())
118
118
})
119
+ t .Run ("SymlinkBackup" ,func (t * testing.T ) {
120
+ t .Parallel ()
121
+ _ ,root := clitest .New (t )
122
+ testRepo := testGitRepo (t ,root )
123
+
124
+ // nolint:gosec
125
+ err := os .WriteFile (filepath .Join (testRepo ,".bashrc" ), []byte ("wow" ),0o750 )
126
+ require .NoError (t ,err )
127
+
128
+ // add a conflicting file at destination
129
+ // nolint:gosec
130
+ err = os .WriteFile (filepath .Join (string (root ),".bashrc" ), []byte ("backup" ),0o750 )
131
+ require .NoError (t ,err )
132
+
133
+ c := exec .Command ("git" ,"add" ,".bashrc" )
134
+ c .Dir = testRepo
135
+ err = c .Run ()
136
+ require .NoError (t ,err )
137
+
138
+ c = exec .Command ("git" ,"commit" ,"-m" ,`"add .bashrc"` )
139
+ c .Dir = testRepo
140
+ out ,err := c .CombinedOutput ()
141
+ require .NoError (t ,err ,string (out ))
142
+
143
+ inv ,_ := clitest .New (t ,"dotfiles" ,"--global-config" ,string (root ),"--symlink-dir" ,string (root ),"-y" ,testRepo )
144
+ err = inv .Run ()
145
+ require .NoError (t ,err )
146
+
147
+ b ,err := os .ReadFile (filepath .Join (string (root ),".bashrc" ))
148
+ require .NoError (t ,err )
149
+ require .Equal (t ,string (b ),"wow" )
150
+
151
+ // check for backup file
152
+ b ,err = os .ReadFile (filepath .Join (string (root ),".bashrc.bak" ))
153
+ require .NoError (t ,err )
154
+ require .Equal (t ,string (b ),"backup" )
155
+
156
+ // check for idempotency
157
+ inv ,_ = clitest .New (t ,"dotfiles" ,"--global-config" ,string (root ),"--symlink-dir" ,string (root ),"-y" ,testRepo )
158
+ err = inv .Run ()
159
+ require .NoError (t ,err )
160
+ b ,err = os .ReadFile (filepath .Join (string (root ),".bashrc" ))
161
+ require .NoError (t ,err )
162
+ require .Equal (t ,string (b ),"wow" )
163
+ b ,err = os .ReadFile (filepath .Join (string (root ),".bashrc.bak" ))
164
+ require .NoError (t ,err )
165
+ require .Equal (t ,string (b ),"backup" )
166
+ })
167
+ }
168
+
169
+ func TestDotfilesInstallScriptUnix (t * testing.T ) {
170
+ t .Parallel ()
171
+
172
+ if runtime .GOOS == "windows" {
173
+ t .Skip ()
174
+ }
175
+
119
176
t .Run ("InstallScript" ,func (t * testing.T ) {
120
177
t .Parallel ()
121
- if runtime .GOOS == "windows" {
122
- t .Skip ("install scripts on windows require sh and aren't very practical" )
123
- }
124
178
_ ,root := clitest .New (t )
125
179
testRepo := testGitRepo (t ,root )
126
180
@@ -149,9 +203,6 @@ func TestDotfiles(t *testing.T) {
149
203
150
204
t .Run ("NestedInstallScript" ,func (t * testing.T ) {
151
205
t .Parallel ()
152
- if runtime .GOOS == "windows" {
153
- t .Skip ("install scripts on windows require sh and aren't very practical" )
154
- }
155
206
_ ,root := clitest .New (t )
156
207
testRepo := testGitRepo (t ,root )
157
208
@@ -183,9 +234,6 @@ func TestDotfiles(t *testing.T) {
183
234
184
235
t .Run ("InstallScriptChangeBranch" ,func (t * testing.T ) {
185
236
t .Parallel ()
186
- if runtime .GOOS == "windows" {
187
- t .Skip ("install scripts on windows require sh and aren't very practical" )
188
- }
189
237
_ ,root := clitest .New (t )
190
238
testRepo := testGitRepo (t ,root )
191
239
@@ -227,53 +275,43 @@ func TestDotfiles(t *testing.T) {
227
275
require .NoError (t ,err )
228
276
require .Equal (t ,string (b ),"wow\n " )
229
277
})
230
- t .Run ("SymlinkBackup" ,func (t * testing.T ) {
278
+ }
279
+
280
+ func TestDotfilesInstallScriptWindows (t * testing.T ) {
281
+ t .Parallel ()
282
+
283
+ if runtime .GOOS != "windows" {
284
+ t .Skip ()
285
+ }
286
+
287
+ t .Run ("InstallScript" ,func (t * testing.T ) {
231
288
t .Parallel ()
232
289
_ ,root := clitest .New (t )
233
290
testRepo := testGitRepo (t ,root )
234
291
235
292
// nolint:gosec
236
- err := os .WriteFile (filepath .Join (testRepo ,".bashrc " ), []byte ("wow" ),0o750 )
293
+ err := os .WriteFile (filepath .Join (testRepo ,"install.ps1 " ), []byte ("echo \" hello, computer! \" > " + filepath . Join ( string ( root ), "greeting.txt" ) ),0o750 )
237
294
require .NoError (t ,err )
238
295
239
- // add a conflicting file at destination
240
- // nolint:gosec
241
- err = os .WriteFile (filepath .Join (string (root ),".bashrc" ), []byte ("backup" ),0o750 )
242
- require .NoError (t ,err )
243
-
244
- c := exec .Command ("git" ,"add" ,".bashrc" )
296
+ c := exec .Command ("git" ,"add" ,"install.ps1" )
245
297
c .Dir = testRepo
246
298
err = c .Run ()
247
299
require .NoError (t ,err )
248
300
249
- c = exec .Command ("git" ,"commit" ,"-m" ,`"add.bashrc "` )
301
+ c = exec .Command ("git" ,"commit" ,"-m" ,`"addinstall.ps1 "` )
250
302
c .Dir = testRepo
251
- out , err : =c .CombinedOutput ()
252
- require .NoError (t ,err , string ( out ) )
303
+ err = c .Run ()
304
+ require .NoError (t ,err )
253
305
254
306
inv ,_ := clitest .New (t ,"dotfiles" ,"--global-config" ,string (root ),"--symlink-dir" ,string (root ),"-y" ,testRepo )
255
307
err = inv .Run ()
256
308
require .NoError (t ,err )
257
309
258
- b ,err := os .ReadFile (filepath .Join (string (root ),".bashrc" ))
259
- require .NoError (t ,err )
260
- require .Equal (t ,string (b ),"wow" )
261
-
262
- // check for backup file
263
- b ,err = os .ReadFile (filepath .Join (string (root ),".bashrc.bak" ))
310
+ b ,err := os .ReadFile (filepath .Join (string (root ),"greeting.txt" ))
264
311
require .NoError (t ,err )
265
- require .Equal (t ,string (b ),"backup" )
266
-
267
- // check for idempotency
268
- inv ,_ = clitest .New (t ,"dotfiles" ,"--global-config" ,string (root ),"--symlink-dir" ,string (root ),"-y" ,testRepo )
269
- err = inv .Run ()
270
- require .NoError (t ,err )
271
- b ,err = os .ReadFile (filepath .Join (string (root ),".bashrc" ))
272
- require .NoError (t ,err )
273
- require .Equal (t ,string (b ),"wow" )
274
- b ,err = os .ReadFile (filepath .Join (string (root ),".bashrc.bak" ))
275
- require .NoError (t ,err )
276
- require .Equal (t ,string (b ),"backup" )
312
+ // If you squint, it does in fact say "hello, computer!" in here, but in
313
+ // UTF-16 and with a byte-order-marker at the beginning. Windows!
314
+ require .Equal (t ,b , []byte ("\xff \xfe h\x00 e\x00 l\x00 l\x00 o\x00 ,\x00 \x00 c\x00 o\x00 m\x00 p\x00 u\x00 t\x00 e\x00 r\x00 !\x00 \r \x00 \n \x00 " ))
277
315
})
278
316
}
279
317