all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 476e5b1e4192ba2815136578ce7e2e037852b0f4 6753 bytes (raw)
name: testing/lisp/test-ob-matlab.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
 
;;; test-ob-matlab.el --- tests for ob-matlab.el  -*- lexical-binding: t; -*-

;;; Commentary:

;; Copyright 2024 Free Software Foundation
;; Authors: John Ciolfi

;; 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 <https://www.gnu.org/licenses/>.

;; ----------
;; Code blocks reside in: ../examples/ob-matlab-test.org
;; To run test-ob-matlab.el using latest matlab-mode and org-mode:
;; 1. Download and build latest org-mode, https://orgmode.org/worg/org-contribute.html
;;    Example:
;;      cd ~/github
;;      git clone https://git.sv.gnu.org/git/emacs/org-mode.git
;;      make -C org-mode compile -j32 && make prefix=~/github/org-mode-install install
;; 2. Download and build latest matlab-mode, https://github.com/MathWorks/Emacs-MATLAB-Mode
;;    Example:
;;      cd ~/github
;;      git clone https://github.com/mathworks/Emacs-MATLAB-Mode.git
;;      make -C Emacs-MATLAB-Mode -j32
;; 3. Test uses matlab-shell which requires that "matlab" is on the PATH:
;;    Example:
;;      cd ~/github/org-mode
;;      env PATH=/path/to/MATLAB-INSTALL/bin:$PATH \
;;          make -j32 test \
;;          BTEST_POST="-L ~/github/Emacs-MATLAB-Mode -l ~/Emacs-MATLAB-Mode/matlab-autoload.el"

;;; Code:

(require 'ob-core)

(org-test-for-executable "matlab")

(unless (fboundp 'matlab-shell)
  (signal 'missing-test-dependency '("Support for MATLAB code blocks")))

;;-------------------------------;;
;; Basic ":results output" tests ;;
;;-------------------------------;;
(ert-deftest ob-matlab/results-output ()
  "Test matlab :results output code block."
  (let ((expected "\
The results are:

a =

     1     2
     3     4

b =

     2     4
     6     8
"))
    (org-test-at-id "99332277-5e0e-4834-a3ad-ebcaddb855ab"
                    (org-babel-next-src-block)
                    (should (equal expected (org-babel-execute-src-block))))))

(ert-deftest ob-matlab/results-output-preserve-whitespace ()
  "Test matlab :results output code block preserves whitespace."
  (let ((expected "\
  +---+
  |one|
  +---+

    1

  +---+
  |two|
  +---+

    2
"))
    (org-test-at-id "99332277-5e0e-4834-a3ad-ebcaddb855ab"
                    (org-babel-next-src-block 2)
                    (should (equal expected (org-babel-execute-src-block))))))

;;------------------------------------------------;;
;; MATLAB workspace reuse tests (:results output) ;;
;;------------------------------------------------;;

(ert-deftest ob-matlab/results-output-reuse-a ()
  "Test matlab :results output defining variable, a."
  (let ((expected "\
a =

   123
"))
    (org-test-at-id "a68db9ff-efdf-42b9-85fc-174015cd1f77"
                    (org-babel-next-src-block)
                    (should (equal expected (org-babel-execute-src-block))))))

(ert-deftest ob-matlab/results-output-reuse-b ()
  "Test matlab :results output reusing variable, a, to compute variable, b."
  (let ((expected "\
b =

        1123
"))
    (org-test-at-id "a68db9ff-efdf-42b9-85fc-174015cd1f77"
                    (org-babel-next-src-block 2)
                    (should (equal expected (org-babel-execute-src-block))))))

(ert-deftest ob-matlab/results-output-reuse-clear ()
  "Test matlab :results output with clear resulting in error.
Also validates that we strip the </?ERRORTXT> matlab-shell indicators."
  (let ((expected "\
Unrecognized function or variable 'b'.
"))
    (org-test-at-id "a68db9ff-efdf-42b9-85fc-174015cd1f77"
                    (org-babel-next-src-block 3)
                    (should (equal expected (org-babel-execute-src-block))))))

;;---------------------------;;
;; ":results verbatim" tests ;;
;;---------------------------;;
(ert-deftest ob-matlab/results-verbatim ()
  "Test matlab :results verbatim."
  (let ((expected '((17 24 1 8 15)
                    (23 5 7 14 16)
                    (4 6 13 20 22)
                    (10 12 19 21 3)
                    (11 18 25 2 9))))
    (org-test-at-id "278047b6-4b87-4852-9050-e3e99fcaabb8"
                    (org-babel-next-src-block)
                    (should (equal expected (org-babel-execute-src-block))))))

;;-------------------------------;;
;; ":results output latex" tests ;;
;;-------------------------------;;

(ert-deftest ob-matlab/results-output-latex ()
  "Test matlab :results output latex."
  (let ((expected "\
\\left(\\begin{array}{cc} 4\\,\\pi  & 3\\,\\pi \\\\ 2\\,\\pi  & \\pi  \\end{array}\\right)
"))
    (org-test-at-id "7a8190be-d674-4944-864e-6fdaa7362585"
                    (org-babel-next-src-block)
                    (let ((got (org-babel-execute-src-block)))
                      (should (equal expected got))))))


;;--------------------------------;;
;; ":results file graphics" tests ;;
;;--------------------------------;;

(ert-deftest ob-matlab/results-file-graphics ()
  "Test matlab :results file graphics."
  (let ((code-block (org-test-get-code-block "5bee8841-a898-4135-b44b-f1bd5465ceed"))
        (temp-file-png (make-temp-file "test-ob-matlab-" nil ".png")))
    (setq code-block (replace-regexp-in-string "NAME\\.png" temp-file-png code-block))
    (unwind-protect
        (org-test-with-temp-text
         code-block
         (org-babel-execute-src-block)
         (should (search-forward (format "[[file:%s]]" temp-file-png) nil nil))
         (should (file-readable-p temp-file-png)))
      (delete-file temp-file-png))))

(ert-deftest ob-matlab/results-file-graphics-with-space ()
  "Test matlab :results file graphics using a file name with a space."
  (let ((code-block (org-test-get-code-block "5bee8841-a898-4135-b44b-f1bd5465ceed"))
        (temp-file-png (make-temp-file "test ob-matlab-" nil ".png")))
    (setq code-block (replace-regexp-in-string "NAME\\.png" temp-file-png code-block))
    (unwind-protect
        (org-test-with-temp-text
         code-block
         (org-babel-execute-src-block)
         (should (search-forward (format "[[file:%s]]" temp-file-png) nil nil))
         (should (file-readable-p temp-file-png)))
      (delete-file temp-file-png))))

(provide 'test-ob-matlab)
;;; test-ob-matlab.el ends here (emacs-lisp-checkdoc)

;; LocalWords:  fboundp ebcaddb efdf fc ERRORTXT fcaabb fdaa ceed setq env BTEST

debug log:

solving 476e5b1e4 ...
found 476e5b1e4 in https://yhetil.org/emacs/CACb3vdSc2ypq5hdd3Kgb3K+wek-0LDwUqUPugzUr2tt5yyg23Q@mail.gmail.com/

applying [1/1] https://yhetil.org/emacs/CACb3vdSc2ypq5hdd3Kgb3K+wek-0LDwUqUPugzUr2tt5yyg23Q@mail.gmail.com/
diff --git a/testing/lisp/test-ob-matlab.el b/testing/lisp/test-ob-matlab.el
new file mode 100644
index 000000000..476e5b1e4

Checking patch testing/lisp/test-ob-matlab.el...
Applied patch testing/lisp/test-ob-matlab.el cleanly.

index at:
100644 476e5b1e4192ba2815136578ce7e2e037852b0f4	testing/lisp/test-ob-matlab.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.