Add "ru" entry for the hashtable *index-file-name*
[maxima.git] / tests / command-line-options.el
blob1355470f18037034cd7c6096eff9320eefee57ee
1 ;;; command-line-options.el --- Regression tests for Maxima's command-line options -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2024 Leo Butler
5 ;; Author: Leo Butler <leo.butler@umanitoba.ca>
6 ;; Maintainer: Leo Butler <leo.butler@umanitoba.ca>
7 ;; Created: 15 Jul 2024
8 ;; Keywords: command-line options; regression tests
9 ;; Package-Requires: (ert maxima)
10 ;; URL: https://maxima.sourceforge.io/
12 ;; This file is part of Maxima.
14 ;; This file is free software. It is released under the terms of the
15 ;; GPLv2. For more information, see <https://www.gnu.org/licenses/>.
17 ;;; Commentary:
18 ;; Exercise various command-line options with various
19 ;; Lisps. Command-line options are defined in
20 ;; `maxima-cli--tests'. `maxima-cli-deftest' defines a single set of
21 ;; tests, one per Lisp; `maxima-cli-deftests' defines all tests.
23 ;; To execute the tests, do the following (in an *ielm* buffer, for
24 ;; example):
25 ;; (maxima-cli-deftests maxima-cli--tests) ;; define tests
26 ;; (ert t)
28 ;; Note that `ert' is an Emacs command, so M-x ert RET also works.
30 ;; Currently, a bug in GCL, which prevents newlines from being printed
31 ;; in some cases, causes two test failures. See the definition of
32 ;; `maxima-cli-tests'.
34 ;;; Code:
35 (require 'ert)
36 (require 'maxima)
38 (defvar maxima-cli--filter-regexps
39 '("^;;; Loading #P" ;; ECL -- (setq *load-verbose* nil) creates its own problems
40 "^$" ;; ECL -- blank lines
42 "Regexps to remove extraneous lines from Maxima's output.")
44 (defun maxima-cli--output-filter (line)
45 "Filter empty or undesired lines from Maxima output.
46 Return nil if LINE is zero-length or it matches a regexp in
47 `org-babel-maxima--output-filter'; otherwise, return LINE."
48 (unless (or (= 0 (length line))
49 (cl-some #'(lambda(r) (string-match r line))
50 maxima-cli--filter-regexps))
51 line))
53 (defun maxima-cli--buffer-string (buffer)
54 (with-current-buffer buffer
55 (string-join
56 (delq nil
57 (mapcar #'maxima-cli--output-filter
58 (string-split
59 (buffer-substring-no-properties (point-min) (point-max))
60 "[\r\n]")))
61 "\n")))
63 (defun maxima-cli-run-test (cmd)
64 (let ((stdout (get-buffer-create " *maxima-cli-test-out*" t))
65 (stderr (get-buffer-create " *maxima-cli-test-err*" t)))
66 (with-current-buffer stdout (erase-buffer))
67 (with-current-buffer stderr (erase-buffer))
68 (shell-command cmd stdout stderr)
69 (list (maxima-cli--buffer-string stdout) (maxima-cli--buffer-string stderr))))
71 (defun maxima-cli-deftest (plist &optional lisps)
72 (let* ((name (car plist))
73 (plist (cadr plist))
74 (lisps (or (plist-get plist :lisps) lisps))
75 (results (or (plist-get plist :results) lisps)))
76 (mapcar #'eval
77 (cl-map 'list #'(lambda(lisp result)
78 `(ert-deftest ,(intern (format "%s-%s" name lisp)) ()
79 ,@(if (null result) '(:expected-result :failed) nil)
80 (let* ((cmd ,(format (plist-get plist :cmd) maxima-command lisp))
81 (results (maxima-cli-run-test cmd)))
82 (should (equal (car results) ,(plist-get plist :stdout)))
83 (should (equal (cadr results) ,(plist-get plist :stderr))))))
84 lisps results))))
86 (defun maxima-cli-deftests (tests)
87 (let (results)
88 (cl-do ((test tests (cddr test)))
89 ((null test) results)
90 (setq results (cons (maxima-cli-deftest test) results)))))
92 (defvar maxima-cli--tests
93 '(maxima-cli--vvq+batch-string
94 (:cmd "%s --lisp=%s --very-very-quiet --no-init --batch-string='printf(true, \"HELLO~%%\");1/0;printf(true,\"Integral xdx = ~a~%%\",integrate(x,x));';"
95 :stdout "HELLO\nIntegral xdx = x^2/2" :stderr "expt: undefined: 0 to a negative exponent.\n -- an error. To debug this try: debugmode(true);"
96 :exit 0 :lisps (gcl sbcl ecl clisp) :results (nil t t t))
97 maxima-cli--vvq+batch-string2
98 (:cmd "%s --lisp=%s --quit-on-error --very-very-quiet --no-init --batch-string='printf(true, \"HELLO~%%\");1/0;printf(true,\"Integral xdx = ~a~%%\",integrate(x,x));';"
99 :stdout "HELLO" :stderr "expt: undefined: 0 to a negative exponent.\n -- an error. To debug this try: debugmode(true);"
100 :exit 1 :lisps (gcl sbcl ecl clisp) :results (nil t t t))
101 maxima-cli--vq+batch-string-question
102 (:cmd "%s --lisp=%s --very-quiet --no-init --batch-string='(display2d:false, integrate(x^n,x)); y;'"
103 :stdout "(display2d:false,integrate(x^n,x))\nlog(x)" :stderr ""
104 :exit 1 :lisps (gcl sbcl ecl clisp) :results (t t t t))
106 "List of tests of command-line switches.
108 A list of property lists of the form (:cmd MAXIMA-COMMAND :stdout
109 EXPECTED-OUTPUT :stderr EXPECTED-ERROR-OUPUT :exit
110 EXPECTED-EXIT-CODE :lisps LIST-OF-LISPS :results
111 LIST-OF-EXPECTED-RESULTS). To indicate an expected test failure,
112 place NIL in LIST-OF-EXPECTED-RESULTS; otherwise, place T.")
114 ;;; command-line-options.el ends here