* admin/automerge: Quieten initial pull if start with reset.
[emacs.git] / test / src / fileio-tests.el
blob5d12685fa190c1fca39a21db9eebb297919f844c
1 ;;; unit tests for src/fileio.c -*- lexical-binding: t; -*-
3 ;; Copyright 2017-2018 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
20 (require 'ert)
22 (defun try-link (target link)
23 (make-symbolic-link target link)
24 (let* ((read-link (file-symlink-p link))
25 (failure (unless (string-equal target read-link)
26 (list 'string-equal target read-link))))
27 (delete-file link)
28 failure))
30 (defun fileio-tests--symlink-failure ()
31 (let* ((dir (make-temp-file "fileio" t))
32 (link (expand-file-name "link" dir)))
33 (unwind-protect
34 (let (failure
35 (char 0))
36 (while (and (not failure) (< char 127))
37 (setq char (1+ char))
38 (when (and (eq system-type 'cygwin) (eq char 92))
39 (setq char (1+ char)))
40 (setq failure (try-link (string char) link)))
41 (or failure
42 (try-link "/:" link)))
43 (delete-directory dir t))))
45 (ert-deftest fileio-tests--odd-symlink-chars ()
46 "Check that any non-NULL ASCII character can appear in a symlink.
47 Also check that an encoding error can appear in a symlink."
48 ;; Some Windows versions don't support symlinks, and those which do
49 ;; will pop up UAC elevation prompts, so we disable this test on
50 ;; MS-Windows.
51 (skip-unless (not (eq system-type 'windows-nt)))
52 (should (equal nil (fileio-tests--symlink-failure))))
54 (ert-deftest fileio-tests--directory-file-name ()
55 (should (equal (directory-file-name "/") "/"))
56 (should (equal (directory-file-name "//") "//"))
57 (should (equal (directory-file-name "///") "/"))
58 (should (equal (directory-file-name "////") "/"))
59 (should (equal (directory-file-name "/abc") "/abc"))
60 (should (equal (directory-file-name "/abc/") "/abc"))
61 (should (equal (directory-file-name "/abc//") "/abc")))
63 (ert-deftest fileio-tests--directory-file-name-dos-nt ()
64 "Like fileio-tests--directory-file-name, but for DOS_NT systems."
65 (skip-unless (memq system-type '(ms-dos windows-nt)))
66 (should (equal (directory-file-name "d:/") "d:/"))
67 (should (equal (directory-file-name "d://") "d:/"))
68 (should (equal (directory-file-name "d:///") "d:/"))
69 (should (equal (directory-file-name "d:////") "d:/"))
70 (should (equal (directory-file-name "d:/abc") "d:/abc"))
71 (should (equal (directory-file-name "d:/abc/") "d:/abc"))
72 (should (equal (directory-file-name "d:/abc//") "d:/abc")))
74 (ert-deftest fileio-tests--file-name-as-directory ()
75 (should (equal (file-name-as-directory "") "./"))
76 (should (equal (file-name-as-directory "/") "/"))
77 (should (equal (file-name-as-directory "//") "//"))
78 (should (equal (file-name-as-directory "///") "///"))
79 (should (equal (file-name-as-directory "////") "////"))
80 (should (equal (file-name-as-directory "/abc") "/abc/"))
81 (should (equal (file-name-as-directory "/abc/") "/abc/"))
82 (should (equal (file-name-as-directory "/abc//") "/abc//")))
84 (ert-deftest fileio-tests--file-name-as-directory-dos-nt ()
85 "Like fileio-tests--file-name-as-directory, but for DOS_NT systems."
86 (skip-unless (memq system-type '(ms-dos windows-nt)))
87 (should (equal (file-name-as-directory "d:/") "d:/"))
88 (should (equal (file-name-as-directory "d:\\") "d:/"))
89 (should (equal (file-name-as-directory "d://") "d://"))
90 (should (equal (file-name-as-directory "d:///") "d:///"))
91 (should (equal (file-name-as-directory "d:////") "d:////"))
92 (should (equal (file-name-as-directory "d:\\\\\\\\") "d:////"))
93 (should (equal (file-name-as-directory "d:/abc") "d:/abc/"))
94 (should (equal (file-name-as-directory "D:\\abc") "d:/abc/"))
95 (should (equal (file-name-as-directory "d:/abc/") "d:/abc/"))
96 (should (equal (file-name-as-directory "D:\\abc/") "d:/abc/"))
97 (should (equal (file-name-as-directory "D:/abc//") "d:/abc//")))