فهرست منبع

Fix failing test

* testing/lisp/test-org.el (test-org/file-contents): New test.  Merge
  from `test-org/org-file-contents-file' and
  `test-org/org-file-contents-url'.
Nicolas Goaziou 7 سال پیش
والد
کامیت
d8eaa8396d
1فایلهای تغییر یافته به همراه45 افزوده شده و 53 حذف شده
  1. 45 53
      testing/lisp/test-org.el

+ 45 - 53
testing/lisp/test-org.el

@@ -6498,8 +6498,9 @@ Paragraph<point>"
      (org-show-set-visibility 'minimal)
      (org-invisible-p2))))
 
-(ert-deftest test-org/org-file-contents-file ()
-  "Test `org-file-contents' with a file as input."
+(ert-deftest test-org/file-contents ()
+  "Test `org-file-contents' specifications."
+  ;; Open files.
   (should
    (string= "#+BIND: variable value
 #+DESCRIPTION: l2
@@ -6509,18 +6510,12 @@ Paragraph<point>"
 #+PROPERTY: a 1
 " (org-file-contents (expand-file-name "setupfile3.org"
 				       (concat org-test-dir "examples/")))))
-  
-  (let ((invalid-file "this-file-must-not-exist"))
-    ;; Throw error when trying to access an invalid file.
-    (should-error
-     (org-file-contents invalid-file))
-    ;; Try to access an invalid file, but do not throw an error.
-    (should
-     (string-match-p "\\`Opening input file: No such file or directory"
-		     (org-file-contents invalid-file :noerror)))))
-
-(ert-deftest test-org/org-file-contents-url ()
-  "Test `org-file-contents' with a URL as input."
+  ;; Throw error when trying to access an invalid file.
+  (should-error (org-file-contents "this-file-must-not-exist"))
+  ;; Try to access an invalid file, but do not throw an error.
+  (should
+   (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
+  ;; Open URL.
   (should
    (string= "foo"
 	    (let ((buffer (generate-new-buffer "url-retrieve-output")))
@@ -6533,45 +6528,42 @@ Paragraph<point>"
 			       buffer)))
 		    (org-file-contents "http://some-valid-url"))
 		(kill-buffer buffer)))))
-
-  (let ((invalid-url "http://this-url-must-not-exist"))
-    ;; Throw error when trying to access an invalid URL.
-    (should-error
-     (let ((buffer (generate-new-buffer "url-retrieve-output")))
-       (unwind-protect
-	   ;; Simulate unsuccessful retrieval of a URL.
-	   (cl-letf (((symbol-function 'url-retrieve-synchronously)
-		      (lambda (&rest_)
-			(with-current-buffer buffer
-			  (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
-			buffer)))
-	     (org-file-contents invalid-url))
-	 (kill-buffer buffer))))
-    ;; Try to access an invalid URL, but do not throw an error.
-    (should-error
-     (let ((buffer (generate-new-buffer "url-retrieve-output")))
-       (unwind-protect
-	   ;; Simulate unsuccessful retrieval of a URL.
-	   (cl-letf (((symbol-function 'url-retrieve-synchronously)
-		      (lambda (&rest_)
-			(with-current-buffer buffer
-			  (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
-			buffer)))
-	     (org-file-contents invalid-url))
-	 (kill-buffer buffer))))
-    (should
-     (string=
-      (format "Unable to fetch file from \"%s\"" invalid-url)
-      (let ((buffer (generate-new-buffer "url-retrieve-output")))
-	(unwind-protect
-	    ;; Simulate unsuccessful retrieval of a URL.
-	    (cl-letf (((symbol-function 'url-retrieve-synchronously)
-		       (lambda (&rest_)
-			 (with-current-buffer buffer
-			   (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
-			 buffer)))
-	      (org-file-contents invalid-url :noerror))
-	  (kill-buffer buffer)))))))
+  ;; Throw error when trying to access an invalid URL.
+  (should-error
+   (let ((buffer (generate-new-buffer "url-retrieve-output")))
+     (unwind-protect
+	 ;; Simulate unsuccessful retrieval of a URL.
+	 (cl-letf (((symbol-function 'url-retrieve-synchronously)
+		    (lambda (&rest_)
+		      (with-current-buffer buffer
+			(insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
+		      buffer)))
+	   (org-file-contents "http://this-url-must-not-exist"))
+       (kill-buffer buffer))))
+  ;; Try to access an invalid URL, but do not throw an error.
+  (should-error
+   (let ((buffer (generate-new-buffer "url-retrieve-output")))
+     (unwind-protect
+	 ;; Simulate unsuccessful retrieval of a URL.
+	 (cl-letf (((symbol-function 'url-retrieve-synchronously)
+		    (lambda (&rest_)
+		      (with-current-buffer buffer
+			(insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
+		      buffer)))
+	   (org-file-contents "http://this-url-must-not-exist"))
+       (kill-buffer buffer))))
+  (should
+   (let ((buffer (generate-new-buffer "url-retrieve-output")))
+     (unwind-protect
+	 ;; Simulate unsuccessful retrieval of a URL.
+	 (cl-letf (((symbol-function 'url-retrieve-synchronously)
+		    (lambda (&rest_)
+		      (with-current-buffer buffer
+			(insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
+		      buffer)))
+	   (org-file-contents "http://this-url-must-not-exist" :noerror))
+       (kill-buffer buffer))
+     t)))
 
 
 (provide 'test-org)