|
@@ -6498,8 +6498,9 @@ Paragraph<point>"
|
|
(org-show-set-visibility 'minimal)
|
|
(org-show-set-visibility 'minimal)
|
|
(org-invisible-p2))))
|
|
(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
|
|
(should
|
|
(string= "#+BIND: variable value
|
|
(string= "#+BIND: variable value
|
|
#+DESCRIPTION: l2
|
|
#+DESCRIPTION: l2
|
|
@@ -6509,18 +6510,12 @@ Paragraph<point>"
|
|
#+PROPERTY: a 1
|
|
#+PROPERTY: a 1
|
|
" (org-file-contents (expand-file-name "setupfile3.org"
|
|
" (org-file-contents (expand-file-name "setupfile3.org"
|
|
(concat org-test-dir "examples/")))))
|
|
(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
|
|
(should
|
|
(string= "foo"
|
|
(string= "foo"
|
|
(let ((buffer (generate-new-buffer "url-retrieve-output")))
|
|
(let ((buffer (generate-new-buffer "url-retrieve-output")))
|
|
@@ -6533,45 +6528,42 @@ Paragraph<point>"
|
|
buffer)))
|
|
buffer)))
|
|
(org-file-contents "http://some-valid-url"))
|
|
(org-file-contents "http://some-valid-url"))
|
|
(kill-buffer buffer)))))
|
|
(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)
|
|
(provide 'test-org)
|