emacs-buttercup icon indicating copy to clipboard operation
emacs-buttercup copied to clipboard

More matchers for file-systems

Open Fuco1 opened this issue 9 years ago • 3 comments

Hi.

While I was implementing the mock-file system I wrote tests for it, obviously using buttercup itself. I wrote new matchers which I think might be quite useful in general

(buttercup-define-matcher :to-be-file (file)
  (if (file-regular-p file)
      (cons t (format "Expected %S not to be a file" file))
    (cons nil (format "Expected %S to be a file" file))))

(buttercup-define-matcher :to-be-directory (dir)
  (if (file-directory-p dir)
      (cons t (format "Expected %S not to be a directory" dir))
    (cons nil (format "Expected %S to be a directory" dir))))

(buttercup-define-matcher :to-contain (file content)
  (if (with-temp-buffer
        (insert-file-contents file)
        (equal (buffer-string) content))
      (cons t (format "Expected the content of %S not to `equal' %S" file content))
    (cons nil (format "Expected the content of %S to `equal' %S" file content))))

You give it a string representing the name of the file/directory etc... straight forward. I wanted a matcher where it would do a regexp match but the syntax "file" :to-match "foo" seems too much like the filename should match, and not the content. Ideally, we would say ":the-content-of "file" :to-match "foo". Maybe adding a feature which would skip all the : prefixed tokens before the first real argument would help us create a bit nicer language?

Anyway... should I do a PR? Maybe we want to prefix these somehow to indicate they deal with the fs?

Fuco1 avatar Jan 27 '16 19:01 Fuco1

Very nice! What do you think about :contents-to-match as the matcher name?

Also, this is starting to look like a bigger thing. Maybe we can put all the file system related functionality into a separate file, like buttercup-filesystem.el? Does that sound reasonable?

jorgenschaefer avatar Jan 28 '16 09:01 jorgenschaefer

Re separate file, yep, definitely a good idea. I remember ecukes also had tons of these "topic" files with predicates/matchers for all sorts of things (buffer related, strings, filesystem etc.)

Re name, sounds good: :content-to-match, :name-to-match would be the filename variant.

I move a bit slowly no as I'm super loaded with $stuff, but we're getting there :) Thanks for the patience!

Fuco1 avatar Jan 28 '16 10:01 Fuco1

We're all volunteers using our spare time here, take as long as you need – thank you very much for working on this at all!

jorgenschaefer avatar Jan 28 '16 10:01 jorgenschaefer