@@ -99,11 +99,7 @@ func TestDiff(t *testing.T) {
9999 "README.md" ,
100100 }
101101
102- got , err := diff (`echo services/foo/serverless.yml
103- services/bar/config.yml
104-
105- ops/bar/config.yml
106- README.md` )
102+ got , err := diff (`printf 'services/foo/serverless.yml\nservices/bar/config.yml\n\nops/bar/config.yml\nREADME.md\n'` )
107103
108104 assert .NoError (t , err )
109105 assert .Equal (t , want , got )
@@ -114,7 +110,7 @@ func TestDiffWithSubshell(t *testing.T) {
114110 "user-service/infrastructure/cloudfront.yaml" ,
115111 "user-service/serverless.yaml" ,
116112 }
117- got , err := diff ("echo $( cat e2e/multiple-paths) " )
113+ got , err := diff ("cat e2e/multiple-paths" )
118114 assert .NoError (t , err )
119115 assert .Equal (t , want , got )
120116}
@@ -124,7 +120,43 @@ func TestDiffWithQuotedPaths(t *testing.T) {
124120 "projects/test/pages/17_🪁_testfile.py" ,
125121 "normal/file.txt" ,
126122 }
127- got , err := diff (`printf '"projects/test/pages/17_\360\237\252\201_testfile.py" normal/file.txt'` )
123+ got , err := diff (`printf '"projects/test/pages/17_\360\237\252\201_testfile.py"\nnormal/file.txt\n'` )
124+ assert .NoError (t , err )
125+ assert .Equal (t , want , got )
126+ }
127+
128+ func TestDiffWithSpacesInFilenames (t * testing.T ) {
129+ // Simulates git diff --name-only output with one filename per line,
130+ // where some filenames contain spaces.
131+ want := []string {
132+ "directory/File Name With Spaces.md" ,
133+ "another dir/some file.txt" ,
134+ "no-spaces.go" ,
135+ }
136+
137+ // printf produces newline-separated output, just like git diff --name-only
138+ got , err := diff (`printf 'directory/File Name With Spaces.md\nanother dir/some file.txt\nno-spaces.go\n'` )
139+ assert .NoError (t , err )
140+ assert .Equal (t , want , got )
141+ }
142+
143+ func TestDiffSingleFile (t * testing.T ) {
144+ want := []string {
145+ "services/foo/serverless.yml" ,
146+ }
147+
148+ got , err := diff (`printf 'services/foo/serverless.yml\n'` )
149+ assert .NoError (t , err )
150+ assert .Equal (t , want , got )
151+ }
152+
153+ func TestDiffWithSpacesInFilenamesSingleFile (t * testing.T ) {
154+ want := []string {
155+ "directory/File Name With Spaces.md" ,
156+ }
157+
158+ // printf produces newline-separated output, just like git diff --name-only
159+ got , err := diff (`printf 'directory/File Name With Spaces.md\n'` )
128160 assert .NoError (t , err )
129161 assert .Equal (t , want , got )
130162}
0 commit comments