aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2017-04-10 17:22:13 +0200
committerMichael Albinus2017-04-10 17:22:13 +0200
commitdd42ca427cf8a890678f574de43685ae70416491 (patch)
tree4e8a3671b805dd1841ff31ac176c2d287fc221ce
parent375bfbde06031d7e9ce363a6695b22b47c6a2798 (diff)
downloademacs-dd42ca427cf8a890678f574de43685ae70416491.tar.gz
emacs-dd42ca427cf8a890678f574de43685ae70416491.zip
Add Tramp tests
* lisp/net/tramp.el (tramp-syntax): Adapt docstring. * test/lisp/net/tramp-tests.el (tramp-test01-file-name-syntax-simplified) (tramp-test01-file-name-syntax-separate) (tramp-test02-file-name-dissect-simplified) (tramp-test02-file-name-dissect-separate): New tests.
-rw-r--r--lisp/net/tramp.el5
-rw-r--r--test/lisp/net/tramp-tests.el786
2 files changed, 790 insertions, 1 deletions
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index eb32bd6e0ed..12169d473e4 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -669,7 +669,10 @@ It can have the following values:
669 669
670 `default' -- Default syntax 670 `default' -- Default syntax
671 `simplified' -- Ange-FTP like syntax 671 `simplified' -- Ange-FTP like syntax
672 `separate' -- Syntax as defined for XEmacs originally." 672 `separate' -- Syntax as defined for XEmacs originally
673
674Do not change the value by `setq', it must be changed only by
675`custom-set-variables'. See also `tramp-change-syntax'."
673 :group 'tramp 676 :group 'tramp
674 :version "26.1" 677 :version "26.1"
675 :package-version '(Tramp . "2.3.2") 678 :package-version '(Tramp . "2.3.2")
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index ba00a96cfda..9dcb3ec9767 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -213,6 +213,115 @@ handled properly. BODY shall not contain a timeout."
213 (should (tramp-tramp-file-p "/-:h:/path/to/file")) 213 (should (tramp-tramp-file-p "/-:h:/path/to/file"))
214 (should (tramp-tramp-file-p "/m::/path/to/file")))) 214 (should (tramp-tramp-file-p "/m::/path/to/file"))))
215 215
216(ert-deftest tramp-test01-file-name-syntax-simplified ()
217 "Check simplified file name syntax."
218 :tags '(:expensive-test)
219 (let ((syntax tramp-syntax))
220 (unwind-protect
221 (progn
222 (tramp-change-syntax 'simplified)
223 ;; Simple cases.
224 (should (tramp-tramp-file-p "/host:"))
225 (should (tramp-tramp-file-p "/user@:"))
226 (should (tramp-tramp-file-p "/user@host:"))
227 (should (tramp-tramp-file-p "/user@email@host:"))
228
229 ;; Using a port.
230 (should (tramp-tramp-file-p "/host#1234:"))
231 (should (tramp-tramp-file-p "/user@host#1234:"))
232
233 ;; Using an IPv4 address.
234 (should (tramp-tramp-file-p "/1.2.3.4:"))
235 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
236
237 ;; Using an IPv6 address.
238 (should (tramp-tramp-file-p "/[::1]:"))
239 (should (tramp-tramp-file-p "/user@[::1]:"))
240
241 ;; Local file name part.
242 (should (tramp-tramp-file-p "/host::"))
243 (should (tramp-tramp-file-p "/host:/:"))
244 (should (tramp-tramp-file-p "/host:/path/to/file"))
245 (should (tramp-tramp-file-p "/host:/:/path/to/file"))
246 (should (tramp-tramp-file-p "/host:file"))
247 (should (tramp-tramp-file-p "/host:/:file"))
248
249 ;; Multihop.
250 (should (tramp-tramp-file-p "/host1|host2:"))
251 (should (tramp-tramp-file-p "/user1@host1|user2@host2:"))
252 (should (tramp-tramp-file-p "/user1@host1|user2@host2|user3@host3:"))
253
254 ;; No strings.
255 (should-not (tramp-tramp-file-p nil))
256 (should-not (tramp-tramp-file-p 'symbol))
257 ;; Quote with "/:" suppresses file name handlers.
258 (should-not (tramp-tramp-file-p "/::"))
259 (should-not (tramp-tramp-file-p "/:@:"))
260 (should-not (tramp-tramp-file-p "/:[]:")))
261
262 ;; Exit.
263 (tramp-change-syntax syntax))))
264
265(ert-deftest tramp-test01-file-name-syntax-separate ()
266 "Check separate file name syntax."
267 :tags '(:expensive-test)
268 (let ((syntax tramp-syntax))
269 (unwind-protect
270 (progn
271 (tramp-change-syntax 'separate)
272 ;; Simple cases.
273 (should (tramp-tramp-file-p "/[method/]"))
274 (should (tramp-tramp-file-p "/[method/host]"))
275 (should (tramp-tramp-file-p "/[method/user@]"))
276 (should (tramp-tramp-file-p "/[method/user@host]"))
277 (should (tramp-tramp-file-p "/[method/user@email@host]"))
278
279 ;; Using a port.
280 (should (tramp-tramp-file-p "/[method/host#1234]"))
281 (should (tramp-tramp-file-p "/[method/user@host#1234]"))
282
283 ;; Using an IPv4 address.
284 (should (tramp-tramp-file-p "/[method/1.2.3.4]"))
285 (should (tramp-tramp-file-p "/[method/user@1.2.3.4]"))
286
287 ;; Using an IPv6 address.
288 (should (tramp-tramp-file-p "/[method/::1]"))
289 (should (tramp-tramp-file-p "/[method/user@::1]"))
290
291 ;; Local file name part.
292 (should (tramp-tramp-file-p "/[method/]"))
293 (should (tramp-tramp-file-p "/[method/]/:"))
294 (should (tramp-tramp-file-p "/[method/]/path/to/file"))
295 (should (tramp-tramp-file-p "/[method/]/:/path/to/file"))
296 (should (tramp-tramp-file-p "/[method/]file"))
297 (should (tramp-tramp-file-p "/[method/]/:file"))
298
299 ;; Multihop.
300 (should (tramp-tramp-file-p "/[method1/|method2/]"))
301 (should (tramp-tramp-file-p "/[method1/host1|method2/host2]"))
302 (should
303 (tramp-tramp-file-p
304 "/[method1/user1@host1|method2/user2@host2]"))
305 (should
306 (tramp-tramp-file-p
307 "/[method1/user1@host1|method2/user2@host2|method3/user3@host3]"))
308
309 ;; No strings.
310 (should-not (tramp-tramp-file-p nil))
311 (should-not (tramp-tramp-file-p 'symbol))
312 ;; Ange-ftp syntax.
313 (should-not (tramp-tramp-file-p "/host:"))
314 (should-not (tramp-tramp-file-p "/user@host:"))
315 (should-not (tramp-tramp-file-p "/1.2.3.4:"))
316 (should-not (tramp-tramp-file-p "/host:/:"))
317 (should-not (tramp-tramp-file-p "/host1|host2:"))
318 (should-not (tramp-tramp-file-p "/user1@host1|user2@host2:"))
319 ;; Quote with "/:" suppresses file name handlers.
320 (should-not (tramp-tramp-file-p "/:[]")))
321
322 ;; Exit.
323 (tramp-change-syntax syntax))))
324
216(ert-deftest tramp-test02-file-name-dissect () 325(ert-deftest tramp-test02-file-name-dissect ()
217 "Check remote file name components." 326 "Check remote file name components."
218 (let ((tramp-default-method "default-method") 327 (let ((tramp-default-method "default-method")
@@ -569,6 +678,683 @@ handled properly. BODY shall not contain a timeout."
569 (format "%s:%s@%s|%s:%s@%s|" 678 (format "%s:%s@%s|%s:%s@%s|"
570 "method1" "user1" "host1" "method2" "user2" "host2"))))) 679 "method1" "user1" "host1" "method2" "user2" "host2")))))
571 680
681(ert-deftest tramp-test02-file-name-dissect-simplified ()
682 "Check simplified file name components."
683 :tags '(:expensive-test)
684 (let ((tramp-default-method "default-method")
685 (tramp-default-user "default-user")
686 (tramp-default-host "default-host")
687 (syntax tramp-syntax))
688 (unwind-protect
689 (progn
690 (tramp-change-syntax 'simplified)
691 ;; Expand `tramp-default-method' and `tramp-default-user'.
692 (should (string-equal
693 (file-remote-p "/host:")
694 (format "/%s@%s:" "default-user" "host")))
695 (should (string-equal
696 (file-remote-p "/host:" 'method) "default-method"))
697 (should (string-equal (file-remote-p "/host:" 'user) "default-user"))
698 (should (string-equal (file-remote-p "/host:" 'host) "host"))
699 (should (string-equal (file-remote-p "/host:" 'localname) ""))
700 (should (string-equal (file-remote-p "/host:" 'hop) nil))
701
702 ;; Expand `tramp-default-method' and `tramp-default-host'.
703 (should (string-equal
704 (file-remote-p "/user@:")
705 (format "/%s@%s:" "user" "default-host")))
706 (should (string-equal
707 (file-remote-p "/user@:" 'method) "default-method"))
708 (should (string-equal (file-remote-p "/user@:" 'user) "user"))
709 (should (string-equal (file-remote-p "/user@:" 'host) "default-host"))
710 (should (string-equal (file-remote-p "/user@:" 'localname) ""))
711 (should (string-equal (file-remote-p "/user@:" 'hop) nil))
712
713 ;; Expand `tramp-default-method'.
714 (should (string-equal
715 (file-remote-p "/user@host:")
716 (format "/%s@%s:" "user" "host")))
717 (should (string-equal
718 (file-remote-p "/user@host:" 'method) "default-method"))
719 (should (string-equal (file-remote-p "/user@host:" 'user) "user"))
720 (should (string-equal (file-remote-p "/user@host:" 'host) "host"))
721 (should (string-equal (file-remote-p "/user@host:" 'localname) ""))
722 (should (string-equal (file-remote-p "/user@host:" 'hop) nil))
723
724 ;; No expansion.
725 (should (string-equal
726 (file-remote-p "/user@email@host:")
727 (format "/%s@%s:" "user@email" "host")))
728 (should (string-equal
729 (file-remote-p
730 "/user@email@host:" 'method) "default-method"))
731 (should (string-equal
732 (file-remote-p "/user@email@host:" 'user) "user@email"))
733 (should (string-equal
734 (file-remote-p "/user@email@host:" 'host) "host"))
735 (should (string-equal
736 (file-remote-p "/user@email@host:" 'localname) ""))
737 (should (string-equal
738 (file-remote-p "/user@email@host:" 'hop) nil))
739
740 ;; Expand `tramp-default-method' and `tramp-default-user'.
741 (should (string-equal
742 (file-remote-p "/host#1234:")
743 (format "/%s@%s:" "default-user" "host#1234")))
744 (should (string-equal
745 (file-remote-p "/host#1234:" 'method) "default-method"))
746 (should (string-equal
747 (file-remote-p "/host#1234:" 'user) "default-user"))
748 (should (string-equal
749 (file-remote-p "/host#1234:" 'host) "host#1234"))
750 (should (string-equal (file-remote-p "/host#1234:" 'localname) ""))
751 (should (string-equal (file-remote-p "/host#1234:" 'hop) nil))
752
753 ;; Expand `tramp-default-method'.
754 (should (string-equal
755 (file-remote-p "/user@host#1234:")
756 (format "/%s@%s:" "user" "host#1234")))
757 (should (string-equal
758 (file-remote-p "/user@host#1234:" 'method) "default-method"))
759 (should (string-equal
760 (file-remote-p "/user@host#1234:" 'user) "user"))
761 (should (string-equal
762 (file-remote-p "/user@host#1234:" 'host) "host#1234"))
763 (should (string-equal
764 (file-remote-p "/user@host#1234:" 'localname) ""))
765 (should (string-equal (file-remote-p "/user@host#1234:" 'hop) nil))
766
767 ;; Expand `tramp-default-method' and `tramp-default-user'.
768 (should (string-equal
769 (file-remote-p "/1.2.3.4:")
770 (format "/%s@%s:" "default-user" "1.2.3.4")))
771 (should (string-equal
772 (file-remote-p "/1.2.3.4:" 'method) "default-method"))
773 (should (string-equal
774 (file-remote-p "/1.2.3.4:" 'user) "default-user"))
775 (should (string-equal (file-remote-p "/1.2.3.4:" 'host) "1.2.3.4"))
776 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname) ""))
777 (should (string-equal (file-remote-p "/1.2.3.4:" 'hop) nil))
778
779 ;; Expand `tramp-default-method'.
780 (should (string-equal
781 (file-remote-p "/user@1.2.3.4:")
782 (format "/%s@%s:" "user" "1.2.3.4")))
783 (should (string-equal
784 (file-remote-p "/user@1.2.3.4:" 'method) "default-method"))
785 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user) "user"))
786 (should (string-equal
787 (file-remote-p "/user@1.2.3.4:" 'host) "1.2.3.4"))
788 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname) ""))
789 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'hop) nil))
790
791 ;; Expand `tramp-default-method', `tramp-default-user' and
792 ;; `tramp-default-host'.
793 (should (string-equal
794 (file-remote-p "/[]:")
795 (format
796 "/%s@%s:" "default-user" "default-host")))
797 (should (string-equal
798 (file-remote-p "/[]:" 'method) "default-method"))
799 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
800 (should (string-equal (file-remote-p "/[]:" 'host) "default-host"))
801 (should (string-equal (file-remote-p "/[]:" 'localname) ""))
802 (should (string-equal (file-remote-p "/[]:" 'hop) nil))
803
804 ;; Expand `tramp-default-method' and `tramp-default-user'.
805 (let ((tramp-default-host "::1"))
806 (should (string-equal
807 (file-remote-p "/[]:")
808 (format "/%s@%s:" "default-user" "[::1]")))
809 (should (string-equal
810 (file-remote-p "/[]:" 'method) "default-method"))
811 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
812 (should (string-equal (file-remote-p "/[]:" 'host) "::1"))
813 (should (string-equal (file-remote-p "/[]:" 'localname) ""))
814 (should (string-equal (file-remote-p "/[]:" 'hop) nil)))
815
816 ;; Expand `tramp-default-method' and `tramp-default-user'.
817 (should (string-equal
818 (file-remote-p "/[::1]:")
819 (format "/%s@%s:" "default-user" "[::1]")))
820 (should (string-equal
821 (file-remote-p "/[::1]:" 'method) "default-method"))
822 (should (string-equal (file-remote-p "/[::1]:" 'user) "default-user"))
823 (should (string-equal (file-remote-p "/[::1]:" 'host) "::1"))
824 (should (string-equal (file-remote-p "/[::1]:" 'localname) ""))
825 (should (string-equal (file-remote-p "/[::1]:" 'hop) nil))
826
827 ;; Expand `tramp-default-method'.
828 (should (string-equal
829 (file-remote-p "/user@[::1]:")
830 (format "/%s@%s:" "user" "[::1]")))
831 (should (string-equal
832 (file-remote-p "/user@[::1]:" 'method) "default-method"))
833 (should (string-equal (file-remote-p "/user@[::1]:" 'user) "user"))
834 (should (string-equal (file-remote-p "/user@[::1]:" 'host) "::1"))
835 (should (string-equal (file-remote-p "/user@[::1]:" 'localname) ""))
836 (should (string-equal (file-remote-p "/user@[::1]:" 'hop) nil))
837
838 ;; Local file name part.
839 (should (string-equal (file-remote-p "/host:/:" 'localname) "/:"))
840 (should (string-equal (file-remote-p "/host::" 'localname) ":"))
841 (should (string-equal (file-remote-p "/host: " 'localname) " "))
842 (should (string-equal (file-remote-p "/host:file" 'localname) "file"))
843 (should (string-equal
844 (file-remote-p "/host:/path/to/file" 'localname)
845 "/path/to/file"))
846
847 ;; Multihop.
848 (should
849 (string-equal
850 (file-remote-p "/user1@host1|user2@host2:/path/to/file")
851 (format "/%s@%s|%s@%s:" "user1" "host1" "user2" "host2")))
852 (should
853 (string-equal
854 (file-remote-p
855 "/user1@host1|user2@host2:/path/to/file" 'method)
856 "default-method"))
857 (should
858 (string-equal
859 (file-remote-p
860 "/user1@host1|user2@host2:/path/to/file" 'user)
861 "user2"))
862 (should
863 (string-equal
864 (file-remote-p
865 "/user1@host1|user2@host2:/path/to/file" 'host)
866 "host2"))
867 (should
868 (string-equal
869 (file-remote-p
870 "/user1@host1|user2@host2:/path/to/file" 'localname)
871 "/path/to/file"))
872 (should
873 (string-equal
874 (file-remote-p
875 "/user1@host1|user2@host2:/path/to/file" 'hop)
876 (format "%s@%s|" "user1" "host1")))
877
878 (should
879 (string-equal
880 (file-remote-p
881 (concat
882 "/user1@host1"
883 "|user2@host2"
884 "|user3@host3:/path/to/file"))
885 (format "/%s@%s|%s@%s|%s@%s:"
886 "user1" "host1"
887 "user2" "host2"
888 "user3" "host3")))
889 (should
890 (string-equal
891 (file-remote-p
892 (concat
893 "/user1@host1"
894 "|user2@host2"
895 "|user3@host3:/path/to/file")
896 'method)
897 "default-method"))
898 (should
899 (string-equal
900 (file-remote-p
901 (concat
902 "/user1@host1"
903 "|user2@host2"
904 "|user3@host3:/path/to/file")
905 'user)
906 "user3"))
907 (should
908 (string-equal
909 (file-remote-p
910 (concat
911 "/user1@host1"
912 "|user2@host2"
913 "|user3@host3:/path/to/file")
914 'host)
915 "host3"))
916 (should
917 (string-equal
918 (file-remote-p
919 (concat
920 "/user1@host1"
921 "|user2@host2"
922 "|user3@host3:/path/to/file")
923 'localname)
924 "/path/to/file"))
925 (should
926 (string-equal
927 (file-remote-p
928 (concat
929 "/user1@host1"
930 "|user2@host2"
931 "|user3@host3:/path/to/file")
932 'hop)
933 (format "%s@%s|%s@%s|"
934 "user1" "host1" "user2" "host2"))))
935
936 ;; Exit.
937 (tramp-change-syntax syntax))))
938
939(ert-deftest tramp-test02-file-name-dissect-separate ()
940 "Check separate file name components."
941 :tags '(:expensive-test)
942 (let ((tramp-default-method "default-method")
943 (tramp-default-user "default-user")
944 (tramp-default-host "default-host")
945 (syntax tramp-syntax))
946 (unwind-protect
947 (progn
948 (tramp-change-syntax 'separate)
949 ;; Expand `tramp-default-user' and `tramp-default-host'.
950 (should (string-equal
951 (file-remote-p "/[method/]")
952 (format
953 "/[%s/%s@%s]" "method" "default-user" "default-host")))
954 (should (string-equal (file-remote-p "/[method/]" 'method) "method"))
955 (should (string-equal
956 (file-remote-p "/[method/]" 'user) "default-user"))
957 (should (string-equal
958 (file-remote-p "/[method/]" 'host) "default-host"))
959 (should (string-equal (file-remote-p "/[method/]" 'localname) ""))
960 (should (string-equal (file-remote-p "/[method/]" 'hop) nil))
961
962 ;; Expand `tramp-default-method' and `tramp-default-user'.
963 (should (string-equal
964 (file-remote-p "/[-/host]")
965 (format
966 "/[%s/%s@%s]" "default-method" "default-user" "host")))
967 (should (string-equal
968 (file-remote-p "/[-/host]" 'method) "default-method"))
969 (should (string-equal
970 (file-remote-p "/[-/host]" 'user) "default-user"))
971 (should (string-equal (file-remote-p "/[-/host]" 'host) "host"))
972 (should (string-equal (file-remote-p "/[-/host]" 'localname) ""))
973 (should (string-equal (file-remote-p "/[-/host]" 'hop) nil))
974
975 ;; Expand `tramp-default-method' and `tramp-default-host'.
976 (should (string-equal
977 (file-remote-p "/[-/user@]")
978 (format
979 "/[%s/%s@%s]" "default-method" "user" "default-host")))
980 (should (string-equal
981 (file-remote-p "/[-/user@]" 'method) "default-method"))
982 (should (string-equal (file-remote-p "/[-/user@]" 'user) "user"))
983 (should (string-equal
984 (file-remote-p "/[-/user@]" 'host) "default-host"))
985 (should (string-equal (file-remote-p "/[-/user@]" 'localname) ""))
986 (should (string-equal (file-remote-p "/[-/user@]" 'hop) nil))
987
988 ;; Expand `tramp-default-method'.
989 (should (string-equal
990 (file-remote-p "/[-/user@host]")
991 (format "/[%s/%s@%s]" "default-method" "user" "host")))
992 (should (string-equal
993 (file-remote-p "/[-/user@host]" 'method) "default-method"))
994 (should (string-equal (file-remote-p "/[-/user@host]" 'user) "user"))
995 (should (string-equal (file-remote-p "/[-/user@host]" 'host) "host"))
996 (should (string-equal (file-remote-p "/[-/user@host]" 'localname) ""))
997 (should (string-equal (file-remote-p "/[-/user@host]" 'hop) nil))
998
999 ;; Expand `tramp-default-user'.
1000 (should (string-equal
1001 (file-remote-p "/[method/host]")
1002 (format "/[%s/%s@%s]" "method" "default-user" "host")))
1003 (should (string-equal
1004 (file-remote-p "/[method/host]" 'method) "method"))
1005 (should (string-equal
1006 (file-remote-p "/[method/host]" 'user) "default-user"))
1007 (should (string-equal (file-remote-p "/[method/host]" 'host) "host"))
1008 (should (string-equal (file-remote-p "/[method/host]" 'localname) ""))
1009 (should (string-equal (file-remote-p "/[method/host]" 'hop) nil))
1010
1011 ;; Expand `tramp-default-host'.
1012 (should (string-equal
1013 (file-remote-p "/[method/user@]")
1014 (format "/[%s/%s@%s]" "method" "user" "default-host")))
1015 (should (string-equal
1016 (file-remote-p "/[method/user@]" 'method) "method"))
1017 (should (string-equal (file-remote-p "/[method/user@]" 'user) "user"))
1018 (should (string-equal
1019 (file-remote-p "/[method/user@]" 'host) "default-host"))
1020 (should (string-equal
1021 (file-remote-p "/[method/user@]" 'localname) ""))
1022 (should (string-equal (file-remote-p "/[method/user@]" 'hop) nil))
1023
1024 ;; No expansion.
1025 (should (string-equal
1026 (file-remote-p "/[method/user@host]")
1027 (format "/[%s/%s@%s]" "method" "user" "host")))
1028 (should (string-equal
1029 (file-remote-p "/[method/user@host]" 'method) "method"))
1030 (should (string-equal
1031 (file-remote-p "/[method/user@host]" 'user) "user"))
1032 (should (string-equal
1033 (file-remote-p "/[method/user@host]" 'host) "host"))
1034 (should (string-equal
1035 (file-remote-p "/[method/user@host]" 'localname) ""))
1036 (should (string-equal
1037 (file-remote-p "/[method/user@host]" 'hop) nil))
1038
1039 ;; No expansion.
1040 (should (string-equal
1041 (file-remote-p "/[method/user@email@host]")
1042 (format "/[%s/%s@%s]" "method" "user@email" "host")))
1043 (should (string-equal
1044 (file-remote-p
1045 "/[method/user@email@host]" 'method) "method"))
1046 (should (string-equal
1047 (file-remote-p
1048 "/[method/user@email@host]" 'user) "user@email"))
1049 (should (string-equal
1050 (file-remote-p "/[method/user@email@host]" 'host) "host"))
1051 (should (string-equal
1052 (file-remote-p "/[method/user@email@host]" 'localname) ""))
1053 (should (string-equal
1054 (file-remote-p "/[method/user@email@host]" 'hop) nil))
1055
1056 ;; Expand `tramp-default-method' and `tramp-default-user'.
1057 (should (string-equal
1058 (file-remote-p "/[-/host#1234]")
1059 (format
1060 "/[%s/%s@%s]" "default-method" "default-user" "host#1234")))
1061 (should (string-equal
1062 (file-remote-p "/[-/host#1234]" 'method) "default-method"))
1063 (should (string-equal
1064 (file-remote-p "/[-/host#1234]" 'user) "default-user"))
1065 (should (string-equal
1066 (file-remote-p "/[-/host#1234]" 'host) "host#1234"))
1067 (should (string-equal (file-remote-p "/[-/host#1234]" 'localname) ""))
1068 (should (string-equal (file-remote-p "/[-/host#1234]" 'hop) nil))
1069
1070 ;; Expand `tramp-default-method'.
1071 (should (string-equal
1072 (file-remote-p "/[-/user@host#1234]")
1073 (format "/[%s/%s@%s]" "default-method" "user" "host#1234")))
1074 (should (string-equal
1075 (file-remote-p
1076 "/[-/user@host#1234]" 'method) "default-method"))
1077 (should (string-equal
1078 (file-remote-p
1079 "/[-/user@host#1234]" 'user) "user"))
1080 (should (string-equal
1081 (file-remote-p "/[-/user@host#1234]" 'host) "host#1234"))
1082 (should (string-equal
1083 (file-remote-p "/[-/user@host#1234]" 'localname) ""))
1084 (should (string-equal (file-remote-p "/[-/user@host#1234]" 'hop) nil))
1085
1086 ;; Expand `tramp-default-user'.
1087 (should (string-equal
1088 (file-remote-p "/[method/host#1234]")
1089 (format "/[%s/%s@%s]" "method" "default-user" "host#1234")))
1090 (should (string-equal
1091 (file-remote-p "/[method/host#1234]" 'method) "method"))
1092 (should (string-equal
1093 (file-remote-p "/[method/host#1234]" 'user) "default-user"))
1094 (should (string-equal
1095 (file-remote-p "/[method/host#1234]" 'host) "host#1234"))
1096 (should (string-equal
1097 (file-remote-p "/[method/host#1234]" 'localname) ""))
1098 (should (string-equal (file-remote-p "/[method/host#1234]" 'hop) nil))
1099
1100 ;; No expansion.
1101 (should (string-equal
1102 (file-remote-p "/[method/user@host#1234]")
1103 (format "/[%s/%s@%s]" "method" "user" "host#1234")))
1104 (should (string-equal
1105 (file-remote-p "/[method/user@host#1234]" 'method) "method"))
1106 (should (string-equal
1107 (file-remote-p "/[method/user@host#1234]" 'user) "user"))
1108 (should (string-equal
1109 (file-remote-p
1110 "/[method/user@host#1234]" 'host) "host#1234"))
1111 (should (string-equal
1112 (file-remote-p "/[method/user@host#1234]" 'localname) ""))
1113 (should (string-equal
1114 (file-remote-p "/[method/user@host#1234]" 'hop) nil))
1115
1116 ;; Expand `tramp-default-method' and `tramp-default-user'.
1117 (should (string-equal
1118 (file-remote-p "/[-/1.2.3.4]")
1119 (format
1120 "/[%s/%s@%s]" "default-method" "default-user" "1.2.3.4")))
1121 (should (string-equal
1122 (file-remote-p "/[-/1.2.3.4]" 'method) "default-method"))
1123 (should (string-equal
1124 (file-remote-p "/[-/1.2.3.4]" 'user) "default-user"))
1125 (should (string-equal
1126 (file-remote-p "/[-/1.2.3.4]" 'host) "1.2.3.4"))
1127 (should (string-equal (file-remote-p "/[-/1.2.3.4]" 'localname) ""))
1128 (should (string-equal (file-remote-p "/[-/1.2.3.4]" 'hop) nil))
1129
1130 ;; Expand `tramp-default-method'.
1131 (should (string-equal
1132 (file-remote-p "/[-/user@1.2.3.4]")
1133 (format "/[%s/%s@%s]" "default-method" "user" "1.2.3.4")))
1134 (should (string-equal
1135 (file-remote-p
1136 "/[-/user@1.2.3.4]" 'method) "default-method"))
1137 (should (string-equal
1138 (file-remote-p "/[-/user@1.2.3.4]" 'user) "user"))
1139 (should (string-equal
1140 (file-remote-p "/[-/user@1.2.3.4]" 'host) "1.2.3.4"))
1141 (should (string-equal
1142 (file-remote-p "/[-/user@1.2.3.4]" 'localname) ""))
1143 (should (string-equal (file-remote-p "/[-/user@1.2.3.4]" 'hop) nil))
1144
1145 ;; Expand `tramp-default-user'.
1146 (should (string-equal
1147 (file-remote-p "/[method/1.2.3.4]")
1148 (format "/[%s/%s@%s]" "method" "default-user" "1.2.3.4")))
1149 (should (string-equal
1150 (file-remote-p "/[method/1.2.3.4]" 'method) "method"))
1151 (should (string-equal
1152 (file-remote-p "/[method/1.2.3.4]" 'user) "default-user"))
1153 (should (string-equal
1154 (file-remote-p "/[method/1.2.3.4]" 'host) "1.2.3.4"))
1155 (should (string-equal
1156 (file-remote-p "/[method/1.2.3.4]" 'localname) ""))
1157 (should (string-equal (file-remote-p "/[method/1.2.3.4]" 'hop) nil))
1158
1159 ;; No expansion.
1160 (should (string-equal
1161 (file-remote-p "/[method/user@1.2.3.4]")
1162 (format "/[%s/%s@%s]" "method" "user" "1.2.3.4")))
1163 (should (string-equal
1164 (file-remote-p "/[method/user@1.2.3.4]" 'method) "method"))
1165 (should (string-equal
1166 (file-remote-p "/[method/user@1.2.3.4]" 'user) "user"))
1167 (should (string-equal
1168 (file-remote-p "/[method/user@1.2.3.4]" 'host) "1.2.3.4"))
1169 (should (string-equal
1170 (file-remote-p "/[method/user@1.2.3.4]" 'localname) ""))
1171 (should (string-equal
1172 (file-remote-p "/[method/user@1.2.3.4]" 'hop) nil))
1173
1174 ;; Expand `tramp-default-method', `tramp-default-user' and
1175 ;; `tramp-default-host'.
1176 (should (string-equal
1177 (file-remote-p "/[-/]")
1178 (format
1179 "/[%s/%s@%s]"
1180 "default-method" "default-user" "default-host")))
1181 (should (string-equal
1182 (file-remote-p "/[-/]" 'method) "default-method"))
1183 (should (string-equal (file-remote-p "/[-/]" 'user) "default-user"))
1184 (should (string-equal (file-remote-p "/[-/]" 'host) "default-host"))
1185 (should (string-equal (file-remote-p "/[-/]" 'localname) ""))
1186 (should (string-equal (file-remote-p "/[-/]" 'hop) nil))
1187
1188 ;; Expand `tramp-default-method' and `tramp-default-user'.
1189 (let ((tramp-default-host "::1"))
1190 (should (string-equal
1191 (file-remote-p "/[-/]")
1192 (format
1193 "/[%s/%s@%s]"
1194 "default-method" "default-user" "::1")))
1195 (should (string-equal
1196 (file-remote-p "/[-/]" 'method) "default-method"))
1197 (should (string-equal (file-remote-p "/[-/]" 'user) "default-user"))
1198 (should (string-equal (file-remote-p "/[-/]" 'host) "::1"))
1199 (should (string-equal (file-remote-p "/[-/]" 'localname) ""))
1200 (should (string-equal (file-remote-p "/[-/]" 'hop) nil)))
1201
1202 ;; Expand `tramp-default-method' and `tramp-default-user'.
1203 (should (string-equal
1204 (file-remote-p "/[-/::1]")
1205 (format
1206 "/[%s/%s@%s]" "default-method" "default-user" "::1")))
1207 (should (string-equal
1208 (file-remote-p "/[-/::1]" 'method) "default-method"))
1209 (should (string-equal
1210 (file-remote-p "/[-/::1]" 'user) "default-user"))
1211 (should (string-equal (file-remote-p "/[-/::1]" 'host) "::1"))
1212 (should (string-equal (file-remote-p "/[-/::1]" 'localname) ""))
1213 (should (string-equal (file-remote-p "/[-/::1]" 'hop) nil))
1214
1215 ;; Expand `tramp-default-method'.
1216 (should (string-equal
1217 (file-remote-p "/[-/user@::1]")
1218 (format "/[%s/%s@%s]" "default-method" "user" "::1")))
1219 (should (string-equal
1220 (file-remote-p "/[-/user@::1]" 'method) "default-method"))
1221 (should (string-equal (file-remote-p "/[-/user@::1]" 'user) "user"))
1222 (should (string-equal (file-remote-p "/[-/user@::1]" 'host) "::1"))
1223 (should (string-equal (file-remote-p "/[-/user@::1]" 'localname) ""))
1224 (should (string-equal (file-remote-p "/[-/user@::1]" 'hop) nil))
1225
1226 ;; Expand `tramp-default-user'.
1227 (should (string-equal
1228 (file-remote-p "/[method/::1]")
1229 (format "/[%s/%s@%s]" "method" "default-user" "::1")))
1230 (should (string-equal
1231 (file-remote-p "/[method/::1]" 'method) "method"))
1232 (should (string-equal
1233 (file-remote-p "/[method/::1]" 'user) "default-user"))
1234 (should (string-equal (file-remote-p "/[method/::1]" 'host) "::1"))
1235 (should (string-equal (file-remote-p "/[method/::1]" 'localname) ""))
1236 (should (string-equal (file-remote-p "/[method/::1]" 'hop) nil))
1237
1238 ;; No expansion.
1239 (should (string-equal
1240 (file-remote-p "/[method/user@::1]")
1241 (format "/[%s/%s@%s]" "method" "user" "::1")))
1242 (should (string-equal
1243 (file-remote-p "/[method/user@::1]" 'method) "method"))
1244 (should (string-equal
1245 (file-remote-p "/[method/user@::1]" 'user) "user"))
1246 (should (string-equal
1247 (file-remote-p "/[method/user@::1]" 'host) "::1"))
1248 (should (string-equal
1249 (file-remote-p "/[method/user@::1]" 'localname) ""))
1250 (should (string-equal (file-remote-p "/[method/user@::1]" 'hop) nil))
1251
1252 ;; Local file name part.
1253 (should (string-equal (file-remote-p "/[-/host]/:" 'localname) "/:"))
1254 (should (string-equal (file-remote-p "/[method/]:" 'localname) ":"))
1255 (should (string-equal (file-remote-p "/[method/] " 'localname) " "))
1256 (should (string-equal
1257 (file-remote-p "/[method/]file" 'localname) "file"))
1258 (should (string-equal
1259 (file-remote-p "/[method/]/path/to/file" 'localname)
1260 "/path/to/file"))
1261
1262 ;; Multihop.
1263 (should
1264 (string-equal
1265 (file-remote-p
1266 "/[method1/user1@host1|method2/user2@host2]/path/to/file")
1267 (format "/[%s/%s@%s|%s/%s@%s]"
1268 "method1" "user1" "host1" "method2" "user2" "host2")))
1269 (should
1270 (string-equal
1271 (file-remote-p
1272 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'method)
1273 "method2"))
1274 (should
1275 (string-equal
1276 (file-remote-p
1277 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'user)
1278 "user2"))
1279 (should
1280 (string-equal
1281 (file-remote-p
1282 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'host)
1283 "host2"))
1284 (should
1285 (string-equal
1286 (file-remote-p
1287 "/[method1/user1@host1|method2/user2@host2]/path/to/file"
1288 'localname)
1289 "/path/to/file"))
1290 (should
1291 (string-equal
1292 (file-remote-p
1293 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'hop)
1294 (format "%s/%s@%s|"
1295 "method1" "user1" "host1")))
1296
1297 (should
1298 (string-equal
1299 (file-remote-p
1300 (concat
1301 "/[method1/user1@host1"
1302 "|method2/user2@host2"
1303 "|method3/user3@host3]/path/to/file"))
1304 (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
1305 "method1" "user1" "host1"
1306 "method2" "user2" "host2"
1307 "method3" "user3" "host3")))
1308 (should
1309 (string-equal
1310 (file-remote-p
1311 (concat
1312 "/[method1/user1@host1"
1313 "|method2/user2@host2"
1314 "|method3/user3@host3]/path/to/file")
1315 'method)
1316 "method3"))
1317 (should
1318 (string-equal
1319 (file-remote-p
1320 (concat
1321 "/[method1/user1@host1"
1322 "|method2/user2@host2"
1323 "|method3/user3@host3]/path/to/file")
1324 'user)
1325 "user3"))
1326 (should
1327 (string-equal
1328 (file-remote-p
1329 (concat
1330 "/[method1/user1@host1"
1331 "|method2/user2@host2"
1332 "|method3/user3@host3]/path/to/file")
1333 'host)
1334 "host3"))
1335 (should
1336 (string-equal
1337 (file-remote-p
1338 (concat
1339 "/[method1/user1@host1"
1340 "|method2/user2@host2"
1341 "|method3/user3@host3]/path/to/file")
1342 'localname)
1343 "/path/to/file"))
1344 (should
1345 (string-equal
1346 (file-remote-p
1347 (concat
1348 "/[method1/user1@host1"
1349 "|method2/user2@host2"
1350 "|method3/user3@host3]/path/to/file")
1351 'hop)
1352 (format "%s/%s@%s|%s/%s@%s|"
1353 "method1" "user1" "host1" "method2" "user2" "host2"))))
1354
1355 ;; Exit.
1356 (tramp-change-syntax syntax))))
1357
572(ert-deftest tramp-test03-file-name-defaults () 1358(ert-deftest tramp-test03-file-name-defaults ()
573 "Check default values for some methods." 1359 "Check default values for some methods."
574 ;; Default values in tramp-adb.el. 1360 ;; Default values in tramp-adb.el.