[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#66546: 30.0.50; save-buffer to write-protected file without backup f
From: |
Eli Zaretskii |
Subject: |
bug#66546: 30.0.50; save-buffer to write-protected file without backup fails |
Date: |
Thu, 02 Nov 2023 08:47:14 +0200 |
> From: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
> Cc: 66546@debbugs.gnu.org
> Date: Wed, 01 Nov 2023 20:06:36 +0100
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > Sure, addition to the test suite are always welcome.
>
> Please review attached test. I hope I haven't been overperforming.
Thanks, a few comments below:
> + (cl-letf* (;; Define convenience functions.
> + ((symbol-function 'file-contents)
> + (lambda (file)
> + (if (file-exists-p file)
> + (condition-case err
> + (with-temp-buffer
> + (insert-file-contents file)
> + (buffer-string))
> + ((error err)))
> + 'missing)))
> [...]
> + (should (equal (file-contents file) "foo\n"))
If you want to make sure the file's contents is _exactly_ some text,
you need to write the buffer text to the file with no encoding
conversions, and you need then to visit the file with
insert-file-contents-literally, to avoid decoding conversions.
Otherwise you might get false positives and false negatives due to
encoding/decoding of text and of EOLs.
Also, compiling the new test I get byte-compiler warnings:
In toplevel form:
lisp/files-tests.el:1748:39: Warning: Unused lexical variable `err'
lisp/files-tests.el:1763:17: Warning: `local-write-file-hooks' is an obsolete
variable (as of 22.1); use `write-file-functions' instead.
In end of data:
lisp/files-tests.el:1802:29: Warning: the function `file-contents' is not
known to be defined.