org-mode/testing/lisp/test-org-attach-git.el
Gustav Wikström ae9cd4370b org-attach*, org, org-manual, org-news, ox-html, testing/*
* lisp/org-attach.el

Changed the way attachments deal with property-inheritance.  It now
adheres to the =org-use-property-inheritance= setting by default but
it can be customized if needed (I recommend to enable it!).
The property ATTACH_DIR is deprecated in favour of the shorter and simpler
property DIR.

Added an explicit option to =org-attach= for unsetting
attachment-directories (i.e. remove DIR property and deal with the
attachments by interaction).

Added attachment link type with the prefix "attachment:".

Added customizations:
- org-attach-dir-relative
- org-attach-preferred-new-method
- org-attach-use-inheritance
- org-attach-id-to-path-function

Hooks added:
- org-attach-after-change-hook
- org-attach-open-hook

A new linktype "attachment" is added in order to reduce
link-duplication when wanting to link to files in attached folders of
nodes.  This works for both ID and DIR properties.  The goal is to
make the functionality for attachment links mirror the functionality
for file links.

* lisp/org-attach-git.el

New file, existing functionality.  Code here has been factored out
from org-attach.el and if GIT-functionality is to be used this module
needs to be required sepatately.  It extends org-attach by use of its
hooks.

Activating git functionality in org-attach is done by loading
org-attach-git from now on, instead of customizing a variable.

Naming of both functions and tests has been modified to match the move
of functionality into its own module.

* lisp/org.el

Inline images are shown also using attachment-links, exactly the same
as it works for file-links today.

Make org-open-at-point respect ARG when opening attachment-dir.

* lisp/org-compat.el

org-attach-directory has been deprecated in favour for
org-attach-id-dir.  The new name matches its purpose better.

* lisp/ox-html.el

Export attachment links to images as inline images, in the same way as
file links work today.

* etc/ORG-NEWS

Mention the changes in this patch.

* doc/org-manual.org

The chapter "Refile, Copy, Archive" has been split into two separate
chapters.
- "Refile, Copy and Archiving" for information related to moving
  existing data around.

- "Capture, Attachments, RSS Feeds and Protocols" for information
  related to working with external data.

The attachment-part has been rewritten and extended to match the
changes in this patch.

The new attachment link type is mentioned both inside the attachments
chapter and in the chapter dealing with links.

Documentation related to external links has been improved.

* testing/lisp/test-org-attach-annex.el

Require org-attach-git instead of org-attach, since this file tests
the GIT-functionality.

* testing/lisp/test-org-attach.el

Add tests for org-attach.

* testing/org-test.el

Define a symbol for a file to test attachments with.

* testing/examples/*

A bunch of new example files and folders are created and are used in
testing of org-attach to verify its functionality.
2019-07-07 19:55:49 +02:00

96 lines
3.8 KiB
EmacsLisp

;;; test-org-annex-attach.el --- Tests for Org Attach with git-annex
;;
;; Copyright (c) 2016, 2019 Erik Hetzner
;; Authors: Erik Hetzner
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
(org-test-for-executable "git-annex")
(require 'org-attach-git)
(require 'cl-lib)
(defmacro test-org-attach-git/with-annex (&rest body)
`(let ((tmpdir (make-temp-file "org-annex-test" t "/")))
(unwind-protect
(let ((default-directory tmpdir)
(org-attach-id-dir tmpdir))
(shell-command "git init")
(shell-command "git annex init")
,@body))))
(ert-deftest test-org-attach-git/use-annex ()
(test-org-attach-annex/with-annex
(let ((org-attach-git-annex-cutoff 1))
(should (org-attach-use-annex)))
(let ((org-attach-git-annex-cutoff nil))
(should-not (org-attach-use-annex))))
;; test with non annex directory
(let ((tmpdir (make-temp-file "org-annex-test" t "/")))
(unwind-protect
(let ((default-directory tmpdir)
(org-attach-id-dir tmpdir))
(shell-command "git init")
(should-not (org-attach-use-annex)))
(delete-directory tmpdir 'recursive))))
(ert-deftest test-org-attach-git/get-maybe ()
(test-org-attach-annex/with-annex
(let ((path (expand-file-name "test-file"))
(annex-dup (make-temp-file "org-annex-test" t "/")))
(with-temp-buffer
(insert "hello world\n")
(write-file path))
(shell-command "git annex add test-file")
(shell-command "git annex sync")
;; Set up remote & copy files there
(let ((annex-original default-directory)
(default-directory annex-dup))
(shell-command (format "git clone %s ." (shell-quote-argument annex-original)))
(shell-command "git annex init dup")
(shell-command (format "git remote add original %s" (shell-quote-argument annex-original)))
(shell-command "git annex get test-file")
(shell-command "git annex sync"))
(shell-command (format "git remote add dup %s" (shell-quote-argument annex-dup)))
(shell-command "git annex sync")
(shell-command "git annex drop --force test-file")
;; test getting the file from the dup when we should ALWAYS get
(should (not (file-exists-p (file-symlink-p (expand-file-name "test-file")))))
(let ((org-attach-annex-auto-get t))
(org-attach-annex-get-maybe (expand-file-name "test-file"))
;; check that the file has the right contents
(with-temp-buffer
(insert-file-contents path)
(should (string-equal "hello world\n" (buffer-string)))))
;; test getting the file from the dup when we should NEVER get
(shell-command "git annex drop --force test-file")
(let ((org-attach-annex-auto-get nil))
(should-error (org-attach-annex-get-maybe (expand-file-name "test-file"))))
(let ((org-attach-annex-auto-get 'ask)
(called nil))
(cl-letf (((symbol-function 'y-or-n-p)
(lambda (_) (setq called 'was-called) t)))
(org-attach-annex-get-maybe (expand-file-name "test-file"))
;; check that the file has the right contents
(with-temp-buffer
(insert-file-contents path)
(should (string-equal "hello world\n" (buffer-string))))
(should (eq called 'was-called)))))))
;;; test-org-attach-annex.el ends here