162162T [" Files utils" ][" get_mimetype" ] = new_set ()
163163T [" Files utils" ][" get_mimetype" ][" can invoke `file`" ] = function ()
164164 local orig_system = vim .system
165+ local orig_executable = vim .fn .executable
165166 local _cmd , _opts , _cb = nil , nil , nil
166167 --- @diagnostic disable-next-line : duplicate-set-field
167168 vim .system = function (cmds , opts , cb )
@@ -175,14 +176,24 @@ T["Files utils"]["get_mimetype"]["can invoke `file`"] = function()
175176 }
176177 end
177178
179+ vim .fn .executable = function (s )
180+ if s == " file" then
181+ return 1
182+ else
183+ return orig_executable (s )
184+ end
185+ end
186+
178187 local _type = files .get_mimetype (" some_file.txt" )
179188 h .eq ({ " file" , " --mime-type" , " some_file.txt" }, _cmd )
180189 h .eq (" text/plain" , _type )
181190 vim .system = orig_system
191+ vim .fn .executable = orig_executable
182192end
183193
184194T [" Files utils" ][" get_mimetype" ][" works without `file`" ] = function ()
185195 local orig_system = vim .system
196+ local orig_executable = vim .fn .executable
186197
187198 local _cmd , _opts , _cb = nil , nil , nil
188199 --- @diagnostic disable-next-line : duplicate-set-field
@@ -197,10 +208,19 @@ T["Files utils"]["get_mimetype"]["works without `file`"] = function()
197208 }
198209 end
199210
211+ vim .fn .executable = function (s )
212+ if s == " file" then
213+ return 0
214+ else
215+ return orig_executable (s )
216+ end
217+ end
218+
200219 local _type = files .get_mimetype (" some_file.png" )
201- h .eq ({ " file " , " --mime-type " , " some_file.png " } , _cmd )
220+ h .eq (nil , _cmd )
202221 h .eq (" image/png" , _type )
203222 vim .system = orig_system
223+ vim .fn .executable = orig_executable
204224end
205225
206226return T
0 commit comments