;;; 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 . ;; ---------- ;; 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 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