diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lisp/elide-head-tests.el | 106 | ||||
-rw-r--r-- | test/lisp/emacs-lisp/bytecomp-tests.el | 117 | ||||
-rw-r--r-- | test/lisp/emacs-lisp/cl-lib-tests.el | 5 | ||||
-rw-r--r-- | test/lisp/eshell/em-alias-tests.el | 9 | ||||
-rw-r--r-- | test/lisp/eshell/em-extpipe-tests.el | 2 | ||||
-rw-r--r-- | test/lisp/eshell/em-script-tests.el | 32 | ||||
-rw-r--r-- | test/lisp/eshell/em-tramp-tests.el | 75 | ||||
-rw-r--r-- | test/lisp/eshell/esh-io-tests.el | 61 | ||||
-rw-r--r-- | test/lisp/eshell/esh-var-tests.el | 74 | ||||
-rw-r--r-- | test/lisp/net/tramp-tests.el | 15 | ||||
-rw-r--r-- | test/lisp/proced-tests.el | 105 | ||||
-rw-r--r-- | test/lisp/url/url-future-tests.el | 2 | ||||
-rw-r--r-- | test/manual/noverlay/itree-tests.c | 182 |
13 files changed, 636 insertions, 149 deletions
diff --git a/test/lisp/elide-head-tests.el b/test/lisp/elide-head-tests.el index 429ef266572..3d6e7686935 100644 --- a/test/lisp/elide-head-tests.el +++ b/test/lisp/elide-head-tests.el @@ -180,6 +180,90 @@ ;; along with Mentor. If not, see <https://www.gnu.org/licenses>. " "Mentor is distributed in the hope that") +;; from GnuTLS [has a line break in snail mail address] +(elide-head--add-test gpl3-6 "\ +# This file is part of GnuTLS. +# +# 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, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +# USA +" "This program is distributed in the hope that") + +;; from GnuTLS [has a different line break in snail mail address] +(elide-head--add-test gpl3-7 "\ +# This file is part of GnuTLS. +# +# The GnuTLS is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 of +# the License, or (at your option) any later version. +# +# The GnuTLS 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with GnuTLS; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA +" "The GnuTLS is distributed in the hope that") + +;; from GnuTLS [has a typo in the 02111-1301 part] +(elide-head--add-test gpl3-8 "\ +/* nettle, low-level cryptographics library + * + * Copyright (C) 2002 Niels Möller + * Copyright (C) 2014 Red Hat + *\s\s + * The nettle library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + *\s + * The nettle library 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 Lesser General Public + * License for more details. + *\s + * You should have received a copy of the GNU Lesser General Public License + * along with the nettle library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02111-1301, USA. + */ +" "The nettle library is distributed in the hope that") + +;; from GnuTLS-EXTRA [has a different line break in snail mail address] +(elide-head--add-test gpl3-9 "\ +# This file is part of GnuTLS-EXTRA. +# +# GnuTLS-extra 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. +# +# GnuTLS-extra 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 GnuTLS-EXTRA; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +" "GnuTLS-extra is distributed in the hope that") + ;;; GPLv2 @@ -201,6 +285,28 @@ " "This program is distributed in the hope that") +;;; Apache License + +(elide-head--add-test apache1-1 "\ +/* + * Copyright 2011-2016 The Pkcs11Interop Project + * + * Licensed under the Apache License, Version 2.0 (the \"License\"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an \"AS IS\" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +" "Unless required by applicable law") + + + ;;; Obsolete (with-suppressed-warnings ((obsolete elide-head) diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index e7c308213e4..47200de7a02 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el @@ -704,6 +704,59 @@ inner loops respectively." (let ((bytecomp-tests--xx 1)) (set (make-local-variable 'bytecomp-tests--xx) 2) bytecomp-tests--xx) + + ;; Check for-effect optimisation of `condition-case' body form. + ;; With `condition-case' in for-effect context: + (let ((x (bytecomp-test-identity ?A)) + (r nil)) + (condition-case e + (characterp x) ; value (:success, var) + (error (setq r 'bad)) + (:success (setq r (list 'good e)))) + r) + (let ((x (bytecomp-test-identity ?B)) + (r nil)) + (condition-case nil + (characterp x) ; for-effect (:success, no var) + (error (setq r 'bad)) + (:success (setq r 'good))) + r) + (let ((x (bytecomp-test-identity ?C)) + (r nil)) + (condition-case e + (characterp x) ; for-effect (no :success, var) + (error (setq r (list 'bad e)))) + r) + (let ((x (bytecomp-test-identity ?D)) + (r nil)) + (condition-case nil + (characterp x) ; for-effect (no :success, no var) + (error (setq r 'bad))) + r) + ;; With `condition-case' in value context: + (let ((x (bytecomp-test-identity ?E))) + (condition-case e + (characterp x) ; for-effect (:success, var) + (error (list 'bad e)) + (:success (list 'good e)))) + (let ((x (bytecomp-test-identity ?F))) + (condition-case nil + (characterp x) ; for-effect (:success, no var) + (error 'bad) + (:success 'good))) + (let ((x (bytecomp-test-identity ?G))) + (condition-case e + (characterp x) ; value (no :success, var) + (error (list 'bad e)))) + (let ((x (bytecomp-test-identity ?H))) + (condition-case nil + (characterp x) ; value (no :success, no var) + (error 'bad))) + + (condition-case nil + (bytecomp-test-identity 3) + (error 'bad) + (:success)) ; empty handler ) "List of expressions for cross-testing interpreted and compiled code.") @@ -833,13 +886,19 @@ byte-compiled. Run with dynamic binding." ;; Should not warn that mt--test2 is not known to be defined. (should-not (re-search-forward "my--test2" nil t)))) -(defmacro bytecomp--with-warning-test (re-warning &rest form) +(defmacro bytecomp--with-warning-test (re-warning form) (declare (indent 1)) `(with-current-buffer (get-buffer-create "*Compile-Log*") (let ((inhibit-read-only t)) (erase-buffer)) - (byte-compile ,@form) - (ert-info ((prin1-to-string (buffer-string)) :prefix "buffer: ") - (should (re-search-forward ,(string-replace " " "[ \n]+" re-warning)))))) + (let ((text-quoting-style 'grave) + (macroexp--warned + (make-hash-table :test #'equal :weakness 'key)) ; oh dear + (form ,form)) + (ert-info ((prin1-to-string form) :prefix "form: ") + (byte-compile form) + (ert-info ((prin1-to-string (buffer-string)) :prefix "buffer: ") + (should (re-search-forward + (string-replace " " "[ \n]+" ,re-warning)))))))) (ert-deftest bytecomp-warn-wrong-args () (bytecomp--with-warning-test "remq.*3.*2" @@ -863,6 +922,56 @@ byte-compiled. Run with dynamic binding." (bytecomp--with-warning-test "defvar.*foo.*wider than.*characters" `(defvar foo t ,bytecomp-tests--docstring))) +(ert-deftest bytecomp-warn-dodgy-args-eq () + (dolist (fn '(eq eql)) + (cl-flet ((msg (type arg) + (format + "`%s' called with literal %s that may never match (arg %d)" + fn type arg))) + (bytecomp--with-warning-test (msg "list" 1) `(,fn '(a) 'x)) + (bytecomp--with-warning-test (msg "string" 2) `(,fn 'x "a")) + (bytecomp--with-warning-test (msg "vector" 2) `(,fn 'x [a])) + (bytecomp--with-warning-test (msg "function" 2) `(,fn 'x (lambda () 1))) + (bytecomp--with-warning-test (msg "function" 2) `(,fn 'x #'(lambda () 1))) + (unless (eq fn 'eql) + (bytecomp--with-warning-test (msg "integer" 2) `(,fn 'x #x10000000000)) + (bytecomp--with-warning-test (msg "float" 2) `(,fn 'x 1.0)))))) + +(ert-deftest bytecomp-warn-dodgy-args-memq () + (dolist (fn '(memq memql remq delq assq rassq)) + (cl-labels + ((msg1 (type) + (format + "`%s' called with literal %s that may never match (arg 1)" + fn type)) + (msg2 (type) + (format + "`%s' called with literal %s that may never match (element 2 of arg 2)" + fn type)) + (lst (elt) + (cond ((eq fn 'assq) `((a . 1) (,elt . 2) (c . 3))) + ((eq fn 'rassq) `((1 . a) (2 . ,elt) (3 . c))) + (t `(a ,elt c)))) + (form2 (elt) + `(,fn 'x ',(lst elt)))) + + (bytecomp--with-warning-test (msg1 "list") `(,fn '(a) '(x))) + (bytecomp--with-warning-test (msg1 "string") `(,fn "a" '(x))) + (bytecomp--with-warning-test (msg1 "vector") `(,fn [a] '(x))) + (bytecomp--with-warning-test (msg1 "function") `(,fn (lambda () 1) '(x))) + (bytecomp--with-warning-test (msg1 "function") `(,fn #'(lambda () 1) '(x))) + (unless (eq fn 'memql) + (bytecomp--with-warning-test (msg1 "integer") `(,fn #x10000000000 '(x))) + (bytecomp--with-warning-test (msg1 "float") `(,fn 1.0 '(x)))) + + (bytecomp--with-warning-test (msg2 "list") (form2 '(b))) + (bytecomp--with-warning-test (msg2 "list") (form2 ''b)) + (bytecomp--with-warning-test (msg2 "string") (form2 "b")) + (bytecomp--with-warning-test (msg2 "vector") (form2 [b])) + (unless (eq fn 'memql) + (bytecomp--with-warning-test (msg2 "integer") (form2 #x10000000000)) + (bytecomp--with-warning-test (msg2 "float") (form2 1.0)))))) + (defmacro bytecomp--define-warning-file-test (file re-warning &optional reverse) `(ert-deftest ,(intern (format "bytecomp/%s" file)) () (with-current-buffer (get-buffer-create "*Compile-Log*") diff --git a/test/lisp/emacs-lisp/cl-lib-tests.el b/test/lisp/emacs-lisp/cl-lib-tests.el index b19494af746..759138569e4 100644 --- a/test/lisp/emacs-lisp/cl-lib-tests.el +++ b/test/lisp/emacs-lisp/cl-lib-tests.el @@ -404,7 +404,7 @@ (ert-deftest cl-lib-nth-value-test-multiple-values () "While CL multiple values are an alias to list, these won't work." :expected-result :failed - (should (eq (cl-nth-value 0 '(2 3)) '(2 3))) + (should (equal (cl-nth-value 0 '(2 3)) '(2 3))) (should (= (cl-nth-value 0 1) 1)) (should (null (cl-nth-value 1 1))) (should-error (cl-nth-value -1 (cl-values 2 3)) :type 'args-out-of-range) @@ -431,7 +431,8 @@ (should (eq nums (cdr (cl-adjoin 3 nums)))) ;; add only when not already there (should (eq nums (cl-adjoin 2 nums))) - (should (equal '(2 1 (2)) (cl-adjoin 2 '(1 (2))))) + (with-suppressed-warnings ((suspicious eq)) + (should (equal '(2 1 (2)) (cl-adjoin 2 '(1 (2)))))) ;; default test function is eql (should (equal '(1.0 1 2) (cl-adjoin 1.0 nums))) ;; own :test function - returns true if match diff --git a/test/lisp/eshell/em-alias-tests.el b/test/lisp/eshell/em-alias-tests.el index aca622220e3..0a26e8d2011 100644 --- a/test/lisp/eshell/em-alias-tests.el +++ b/test/lisp/eshell/em-alias-tests.el @@ -72,6 +72,15 @@ (eshell-match-command-output "show-all-args a" "a\n") (eshell-match-command-output "show-all-args a b c" "a\nb\nc\n"))) +(ert-deftest em-alias-test/alias-all-args-var-splice () + "Test alias with splicing the $* variable" + (with-temp-eshell + (eshell-insert-command "alias show-all-args 'echo args: $@*'") + (eshell-match-command-output "show-all-args" "args:\n") + (eshell-match-command-output "show-all-args a" "(\"args:\" \"a\")\n") + (eshell-match-command-output "show-all-args a b c" + "(\"args:\" \"a\" \"b\" \"c\")\n"))) + (ert-deftest em-alias-test/alias-all-args-var-indices () "Test alias with the $* variable using indices" (with-temp-eshell diff --git a/test/lisp/eshell/em-extpipe-tests.el b/test/lisp/eshell/em-extpipe-tests.el index 04e78279427..a2646a0296b 100644 --- a/test/lisp/eshell/em-extpipe-tests.el +++ b/test/lisp/eshell/em-extpipe-tests.el @@ -42,7 +42,7 @@ (shell-command-switch "-c")) ;; Strip `eshell-trap-errors'. (should (equal ,expected - (cadr (eshell-parse-command input)))))) + (cadadr (eshell-parse-command input)))))) (with-substitute-for-temp (&rest body) ;; Substitute name of an actual temporary file and/or ;; buffer into `input'. The substitution logic is diff --git a/test/lisp/eshell/em-script-tests.el b/test/lisp/eshell/em-script-tests.el index b837d464ccd..f720f697c67 100644 --- a/test/lisp/eshell/em-script-tests.el +++ b/test/lisp/eshell/em-script-tests.el @@ -35,21 +35,43 @@ ;;; Tests: (ert-deftest em-script-test/source-script () - "Test sourcing script with no argumentss" + "Test sourcing a simple script." (ert-with-temp-file temp-file :text "echo hi" (with-temp-eshell (eshell-match-command-output (format "source %s" temp-file) "hi\n")))) -(ert-deftest em-script-test/source-script-arg-vars () - "Test sourcing script with $0, $1, ... variables" +(ert-deftest em-script-test/source-script/redirect () + "Test sourcing a script and redirecting its output." + (ert-with-temp-file temp-file + :text "echo hi\necho bye" + (eshell-with-temp-buffer bufname "old" + (with-temp-eshell + (eshell-match-command-output + (format "source %s > #<%s>" temp-file bufname) + "\\`\\'")) + (should (equal (buffer-string) "hibye"))))) + +(ert-deftest em-script-test/source-script/redirect/dev-null () + "Test sourcing a script and redirecting its output, including to /dev/null." + (ert-with-temp-file temp-file + :text "echo hi\necho bad > /dev/null\necho bye" + (eshell-with-temp-buffer bufname "old" + (with-temp-eshell + (eshell-match-command-output + (format "source %s > #<%s>" temp-file bufname) + "\\`\\'")) + (should (equal (buffer-string) "hibye"))))) + +(ert-deftest em-script-test/source-script/arg-vars () + "Test sourcing script with $0, $1, ... variables." (ert-with-temp-file temp-file :text "printnl $0 \"$1 $2\"" (with-temp-eshell (eshell-match-command-output (format "source %s one two" temp-file) (format "%s\none two\n" temp-file))))) -(ert-deftest em-script-test/source-script-all-args-var () - "Test sourcing script with the $* variable" +(ert-deftest em-script-test/source-script/all-args-var () + "Test sourcing script with the $* variable." (ert-with-temp-file temp-file :text "printnl $*" (with-temp-eshell (eshell-match-command-output (format "source %s" temp-file) diff --git a/test/lisp/eshell/em-tramp-tests.el b/test/lisp/eshell/em-tramp-tests.el index 6cc35ecdb1b..982a1eba279 100644 --- a/test/lisp/eshell/em-tramp-tests.el +++ b/test/lisp/eshell/em-tramp-tests.el @@ -27,21 +27,23 @@ "Test Eshell `su' command with no arguments." (should (equal (catch 'eshell-replace-command (eshell/su)) - `(eshell-trap-errors - (eshell-named-command - "cd" - (list ,(format "/su:root@%s:%s" - tramp-default-host default-directory))))))) + `(eshell-with-copied-handles + (eshell-trap-errors + (eshell-named-command + "cd" + (list ,(format "/su:root@%s:%s" + tramp-default-host default-directory)))))))) (ert-deftest em-tramp-test/su-user () "Test Eshell `su' command with USER argument." (should (equal (catch 'eshell-replace-command (eshell/su "USER")) - `(eshell-trap-errors - (eshell-named-command - "cd" - (list ,(format "/su:USER@%s:%s" - tramp-default-host default-directory))))))) + `(eshell-with-copied-handles + (eshell-trap-errors + (eshell-named-command + "cd" + (list ,(format "/su:USER@%s:%s" + tramp-default-host default-directory)))))))) (ert-deftest em-tramp-test/su-login () "Test Eshell `su' command with -/-l/--login option." @@ -50,10 +52,11 @@ ("-"))) (should (equal (catch 'eshell-replace-command (apply #'eshell/su args)) - `(eshell-trap-errors - (eshell-named-command - "cd" - (list ,(format "/su:root@%s:~/" tramp-default-host)))))))) + `(eshell-with-copied-handles + (eshell-trap-errors + (eshell-named-command + "cd" + (list ,(format "/su:root@%s:~/" tramp-default-host))))))))) (defun mock-eshell-named-command (&rest args) "Dummy function to test Eshell `sudo' command rewriting." @@ -91,21 +94,23 @@ ("-s"))) (should (equal (catch 'eshell-replace-command (apply #'eshell/sudo args)) - `(eshell-trap-errors - (eshell-named-command - "cd" - (list ,(format "/sudo:root@%s:%s" - tramp-default-host default-directory)))))))) + `(eshell-with-copied-handles + (eshell-trap-errors + (eshell-named-command + "cd" + (list ,(format "/sudo:root@%s:%s" + tramp-default-host default-directory))))))))) (ert-deftest em-tramp-test/sudo-user-shell () "Test Eshell `sudo' command with -s and -u options." (should (equal (catch 'eshell-replace-command (eshell/sudo "-u" "USER" "-s")) - `(eshell-trap-errors - (eshell-named-command - "cd" - (list ,(format "/sudo:USER@%s:%s" - tramp-default-host default-directory))))))) + `(eshell-with-copied-handles + (eshell-trap-errors + (eshell-named-command + "cd" + (list ,(format "/sudo:USER@%s:%s" + tramp-default-host default-directory)))))))) (ert-deftest em-tramp-test/doas-basic () "Test Eshell `doas' command with default user." @@ -144,20 +149,22 @@ ("-s"))) (should (equal (catch 'eshell-replace-command (apply #'eshell/doas args)) - `(eshell-trap-errors - (eshell-named-command - "cd" - (list ,(format "/doas:root@%s:%s" - tramp-default-host default-directory)))))))) + `(eshell-with-copied-handles + (eshell-trap-errors + (eshell-named-command + "cd" + (list ,(format "/doas:root@%s:%s" + tramp-default-host default-directory))))))))) (ert-deftest em-tramp-test/doas-user-shell () "Test Eshell `doas' command with -s and -u options." (should (equal (catch 'eshell-replace-command (eshell/doas "-u" "USER" "-s")) - `(eshell-trap-errors - (eshell-named-command - "cd" - (list ,(format "/doas:USER@%s:%s" - tramp-default-host default-directory))))))) + `(eshell-with-copied-handles + (eshell-trap-errors + (eshell-named-command + "cd" + (list ,(format "/doas:USER@%s:%s" + tramp-default-host default-directory)))))))) ;;; em-tramp-tests.el ends here diff --git a/test/lisp/eshell/esh-io-tests.el b/test/lisp/eshell/esh-io-tests.el index 37b234eaf06..9a3c14f365f 100644 --- a/test/lisp/eshell/esh-io-tests.el +++ b/test/lisp/eshell/esh-io-tests.el @@ -146,6 +146,45 @@ (should (equal (buffer-string) "new")) (should (equal eshell-test-value "new"))))) +(ert-deftest esh-io-test/redirect-subcommands () + "Check that redirecting subcommands applies to all subcommands." + (eshell-with-temp-buffer bufname "old" + (with-temp-eshell + (eshell-insert-command (format "{echo foo; echo bar} > #<%s>" bufname))) + (should (equal (buffer-string) "foobar")))) + +(ert-deftest esh-io-test/redirect-subcommands/override () + "Check that redirecting subcommands applies to all subcommands. +Include a redirect to another location in the subcommand to +ensure only its statement is redirected." + (eshell-with-temp-buffer bufname "old" + (eshell-with-temp-buffer bufname-2 "also old" + (with-temp-eshell + (eshell-insert-command + (format "{echo foo; echo bar > #<%s>; echo baz} > #<%s>" + bufname-2 bufname))) + (should (equal (buffer-string) "bar"))) + (should (equal (buffer-string) "foobaz")))) + +(ert-deftest esh-io-test/redirect-subcommands/dev-null () + "Check that redirecting subcommands applies to all subcommands. +Include a redirect to /dev/null to ensure it only applies to its +statement." + (eshell-with-temp-buffer bufname "old" + (with-temp-eshell + (eshell-insert-command + (format "{echo foo; echo bar > /dev/null; echo baz} > #<%s>" + bufname))) + (should (equal (buffer-string) "foobaz")))) + +(ert-deftest esh-io-test/redirect-subcommands/interpolated () + "Check that redirecting interpolated subcommands applies to all subcommands." + (eshell-with-temp-buffer bufname "old" + (with-temp-eshell + (eshell-insert-command + (format "echo ${echo foo; echo bar} > #<%s>" bufname))) + (should (equal (buffer-string) "foobar")))) + ;; Redirecting specific handles @@ -274,12 +313,30 @@ stdout originally pointed (the terminal)." ;; Virtual targets -(ert-deftest esh-io-test/virtual-dev-eshell () +(ert-deftest esh-io-test/virtual/dev-null () + "Check that redirecting to /dev/null works." + (with-temp-eshell + (eshell-match-command-output "echo hi > /dev/null" "\\`\\'"))) + +(ert-deftest esh-io-test/virtual/dev-null/multiple () + "Check that redirecting to /dev/null works alongside other redirections." + (eshell-with-temp-buffer bufname "old" + (with-temp-eshell + (eshell-match-command-output + (format "echo new > /dev/null > #<%s>" bufname) "\\`\\'")) + (should (equal (buffer-string) "new"))) + (eshell-with-temp-buffer bufname "old" + (with-temp-eshell + (eshell-match-command-output + (format "echo new > #<%s> > /dev/null" bufname) "\\`\\'")) + (should (equal (buffer-string) "new")))) + +(ert-deftest esh-io-test/virtual/dev-eshell () "Check that redirecting to /dev/eshell works." (with-temp-eshell (eshell-match-command-output "echo hi > /dev/eshell" "hi"))) -(ert-deftest esh-io-test/virtual-dev-kill () +(ert-deftest esh-io-test/virtual/dev-kill () "Check that redirecting to /dev/kill works." (with-temp-eshell (eshell-insert-command "echo one > /dev/kill") diff --git a/test/lisp/eshell/esh-var-tests.el b/test/lisp/eshell/esh-var-tests.el index 96fde026a54..d95669fdaf8 100644 --- a/test/lisp/eshell/esh-var-tests.el +++ b/test/lisp/eshell/esh-var-tests.el @@ -60,6 +60,18 @@ (eshell-command-result-equal "echo $\"user-login-name\"-foo" (concat user-login-name "-foo"))) +(ert-deftest esh-var-test/interp-list-var () + "Interpolate list variable" + (let ((eshell-test-value '(1 2 3))) + (eshell-command-result-equal "echo $eshell-test-value" + '(1 2 3)))) + +(ert-deftest esh-var-test/interp-list-var-concat () + "Interpolate and concat list variable" + (let ((eshell-test-value '(1 2 3))) + (eshell-command-result-equal "echo a$'eshell-test-value'z" + '("a1" 2 "3z")))) + (ert-deftest esh-var-test/interp-var-indices () "Interpolate list variable with indices" (let ((eshell-test-value '("zero" "one" "two" "three" "four"))) @@ -131,6 +143,26 @@ (eshell-command-result-equal "echo $#eshell-test-value" 1) (eshell-command-result-equal "echo $#eshell-test-value[foo]" 3))) +(ert-deftest esh-var-test/interp-var-splice () + "Splice-interpolate list variable" + (let ((eshell-test-value '(1 2 3))) + (eshell-command-result-equal "echo a $@eshell-test-value z" + '("a" 1 2 3 "z")))) + +(ert-deftest esh-var-test/interp-var-splice-concat () + "Splice-interpolate and concat list variable" + (let ((eshell-test-value '(1 2 3))) + (eshell-command-result-equal "echo it is a$@'eshell-test-value'z" + '("it" "is" "a1" 2 "3z")) + ;; This is a tricky case. We're concatenating a spliced list and + ;; a non-spliced list. The general rule is that splicing should + ;; work as though the user typed "$X[0] $X[1] ... $X[N]". That + ;; means that the last value of our splice should get concatenated + ;; into the first value of the non-spliced list. + (eshell-command-result-equal + "echo it is $@'eshell-test-value'$eshell-test-value" + '("it" "is" 1 2 (31 2 3))))) + (ert-deftest esh-var-test/interp-lisp () "Interpolate Lisp form evaluation" (eshell-command-result-equal "+ $(+ 1 2) 3" 6)) @@ -197,6 +229,9 @@ (eshell-match-command-output "echo ${echo hi}-${*echo there}" "hi-there\n"))) + +;; Quoted variable interpolation + (ert-deftest esh-var-test/quoted-interp-var () "Interpolate variable inside double-quotes" (eshell-command-result-equal "echo \"$user-login-name\"" @@ -209,6 +244,18 @@ (eshell-command-result-equal "echo \"hi, $\\\"user-login-name\\\"\"" (concat "hi, " user-login-name))) +(ert-deftest esh-var-test/quoted-interp-list-var () + "Interpolate list variable inside double-quotes" + (let ((eshell-test-value '(1 2 3))) + (eshell-command-result-equal "echo \"$eshell-test-value\"" + "(1 2 3)"))) + +(ert-deftest esh-var-test/quoted-interp-list-var-concat () + "Interpolate and concat list variable inside double-quotes" + (let ((eshell-test-value '(1 2 3))) + (eshell-command-result-equal "echo \"a$'eshell-test-value'z\"" + "a(1 2 3)z"))) + (ert-deftest esh-var-test/quoted-interp-var-indices () "Interpolate string variable with indices inside double-quotes" (let ((eshell-test-value '("zero" "one" "two" "three" "four"))) @@ -291,6 +338,18 @@ inside double-quotes" (eshell-command-result-equal "echo \"$#eshell-test-value[foo]\"" "3"))) +(ert-deftest esh-var-test/quoted-interp-var-splice () + "Splice-interpolate list variable inside double-quotes" + (let ((eshell-test-value '(1 2 3))) + (eshell-command-result-equal "echo a \"$@eshell-test-value\" z" + '("a" "1 2 3" "z")))) + +(ert-deftest esh-var-test/quoted-interp-var-splice-concat () + "Splice-interpolate and concat list variable inside double-quotes" + (let ((eshell-test-value '(1 2 3))) + (eshell-command-result-equal "echo \"a$@'eshell-test-value'z\"" + "a1 2 3z"))) + (ert-deftest esh-var-test/quoted-interp-lisp () "Interpolate Lisp form evaluation inside double-quotes" (eshell-command-result-equal "echo \"hi $(concat \\\"the\\\" \\\"re\\\")\"" @@ -325,6 +384,21 @@ inside double-quotes" "foo\nbar baz")) +;; Interpolating commands + +(ert-deftest esh-var-test/command-interp () + "Interpolate a variable as a command name" + (let ((eshell-test-value "printnl")) + (eshell-command-result-equal "$eshell-test-value hello there" + "hello\nthere\n"))) + +(ert-deftest esh-var-test/command-interp-splice () + "Interpolate a splice variable as a command name with arguments" + (let ((eshell-test-value '("printnl" "hello" "there"))) + (eshell-command-result-equal "$@eshell-test-value" + "hello\nthere\n"))) + + ;; Interpolated variable conversion (ert-deftest esh-var-test/interp-convert-var-number () diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 79b2fc803d6..d7f4576335c 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -2857,6 +2857,7 @@ This checks also `file-name-as-directory', `file-name-directory', This tests also `file-directory-p' and `file-accessible-directory-p'." (skip-unless (tramp--test-enabled)) + ;; Since Emacs 29.1, `make-directory' has defined return values. (dolist (quoted (if (tramp--test-expensive-test-p) '(nil t) '(nil))) (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted)) (tmp-name2 (expand-file-name "foo/bar" tmp-name1)) @@ -2865,7 +2866,9 @@ This tests also `file-directory-p' and `file-accessible-directory-p'." (unwind-protect (progn (with-file-modes unusual-file-mode-1 - (make-directory tmp-name1)) + (if (tramp--test-emacs29-p) + (should-not (make-directory tmp-name1)) + (make-directory tmp-name1))) (should-error (make-directory tmp-name1) :type 'file-already-exists) @@ -2878,15 +2881,19 @@ This tests also `file-directory-p' and `file-accessible-directory-p'." (make-directory tmp-name2) :type 'file-error) (with-file-modes unusual-file-mode-2 - (make-directory tmp-name2 'parents)) + (if (tramp--test-emacs29-p) + (should-not (make-directory tmp-name2 'parents)) + (make-directory tmp-name2 'parents))) (should (file-directory-p tmp-name2)) (should (file-accessible-directory-p tmp-name2)) (when (tramp--test-supports-set-file-modes-p) (should (equal (format "%#o" unusual-file-mode-2) (format "%#o" (file-modes tmp-name2))))) ;; If PARENTS is non-nil, `make-directory' shall not - ;; signal an error when DIR exists already. - (make-directory tmp-name2 'parents)) + ;; signal an error when DIR exists already. It returns t. + (if (tramp--test-emacs29-p) + (should (make-directory tmp-name2 'parents)) + (make-directory tmp-name2 'parents))) ;; Cleanup. (ignore-errors (delete-directory tmp-name1 'recursive)))))) diff --git a/test/lisp/proced-tests.el b/test/lisp/proced-tests.el new file mode 100644 index 00000000000..3c1f5493e74 --- /dev/null +++ b/test/lisp/proced-tests.el @@ -0,0 +1,105 @@ +;;; proced-tests.el --- Test suite for proced.el -*- lexical-binding: t -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: +(require 'ert) +(require 'proced) +(require 'thingatpt) + +(cl-defmacro proced--within-buffer (format filter &body body) + "Execute BODY within a proced buffer using format FORMAT and filter FILTER." + `(let ((proced-format ,format) + (proced-filter ,filter) + (proced-auto-update-flag nil) + (inhibit-message t)) + (proced) + (unwind-protect + (with-current-buffer "*Proced*" + ,@body) + (kill-buffer "*Proced*")))) + +(defun proced--assert-emacs-pid-in-buffer () + "Fail unless the process ID of the current Emacs process exists in buffer." + (should (string-match-p + (number-to-string (emacs-pid)) + (buffer-substring-no-properties (point-min) (point-max))))) + +(defun proced--move-to-column (attribute) + "Move to the column under ATTRIBUTE in the current proced buffer." + (move-to-column (string-match attribute proced-header-line))) + +(ert-deftest proced-format-test () + (dolist (format '(short medium long verbose)) + (proced--within-buffer + format + 'user + (proced--assert-emacs-pid-in-buffer)))) + +(ert-deftest proced-update-test () + (proced--within-buffer + 'short + 'user + (proced-update) + (proced--assert-emacs-pid-in-buffer))) + +(ert-deftest proced-revert-test () + (proced--within-buffer + 'short + 'user + (proced-revert) + (proced--assert-emacs-pid-in-buffer))) + +(ert-deftest proced-color-test () + (let ((proced-enable-color-flag t)) + (proced--within-buffer + 'short + 'user + (proced--assert-emacs-pid-in-buffer)))) + +(ert-deftest proced-refine-test () + ;;(skip-unless (memq system-type '(gnu/linux gnu/kfreebsd darwin))) + (proced--within-buffer + 'medium + 'user + ;; When refining on PID for process A, a process is kept if and only + ;; if its PID are the same as process A, which more or less guarentees + ;; the refinement will remove some processes. + (proced--move-to-column "PID") + (let ((pid (word-at-point))) + (proced-refine) + (while (not (eobp)) + (proced--move-to-column "PID") + (should (string= pid (word-at-point))) + (forward-line))))) + +(ert-deftest proced-refine-with-update-test () + (proced--within-buffer + 'medium + 'user + (proced--move-to-column "PID") + (let ((pid (word-at-point))) + (proced-refine) + (proced-update t) + (while (not (eobp)) + (proced--move-to-column "PID") + (should (string= pid (word-at-point))) + (forward-line))))) + +(provide 'proced-tests) +;;; proced-tests.el ends here diff --git a/test/lisp/url/url-future-tests.el b/test/lisp/url/url-future-tests.el index 5083fc5abae..ec1796f7670 100644 --- a/test/lisp/url/url-future-tests.el +++ b/test/lisp/url/url-future-tests.el @@ -52,7 +52,7 @@ (should (equal (url-future-cancel tocancel) tocancel)) (should-error (url-future-call tocancel)) (should (null url-future-tests--saver)) - (should (url-future-cancelled-p tocancel)))) + (should (url-future-canceled-p tocancel)))) (provide 'url-future-tests) diff --git a/test/manual/noverlay/itree-tests.c b/test/manual/noverlay/itree-tests.c index 278e65f9bf7..8cab7bf84d4 100644 --- a/test/manual/noverlay/itree-tests.c +++ b/test/manual/noverlay/itree-tests.c @@ -26,7 +26,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #include "emacs-compat.h" #define EMACS_LISP_H /* lisp.h inclusion guard */ -#define ITREE_DEBUG 1 #define ITREE_TESTING #include "itree.c" @@ -53,7 +52,7 @@ test_insert1_setup (void) enum { N = 6 }; const int values[N] = {50, 30, 20, 10, 15, 5}; struct itree_node *nodes[N] = {&N_50, &N_30, &N_20, &N_10, &N_15, &N_05}; - interval_tree_init (&tree); + itree_init (&tree); for (int i = 0; i < N; ++i) { nodes[i]->begin = nodes[i]->end = values[i]; @@ -67,7 +66,7 @@ START_TEST (test_insert_1) * [50] */ - interval_tree_insert (&tree, &N_50); + itree_insert_node (&tree, &N_50); ck_assert (! N_50.red); ck_assert_ptr_eq (&N_50, tree.root); } @@ -81,8 +80,8 @@ START_TEST (test_insert_2) * (30) */ - interval_tree_insert (&tree, &N_50); - interval_tree_insert (&tree, &N_30); + itree_insert_node (&tree, &N_50); + itree_insert_node (&tree, &N_30); ck_assert (! N_50.red); ck_assert (N_30.red); ck_assert_ptr_eq (&N_50, tree.root); @@ -102,9 +101,9 @@ START_TEST (test_insert_3) * (20) (50) */ - interval_tree_insert (&tree, &N_50); - interval_tree_insert (&tree, &N_30); - interval_tree_insert (&tree, &N_20); + itree_insert_node (&tree, &N_50); + itree_insert_node (&tree, &N_30); + itree_insert_node (&tree, &N_20); ck_assert (N_50.red); ck_assert (! N_30.red); ck_assert (N_20.red); @@ -128,10 +127,10 @@ START_TEST (test_insert_4) * (10) */ - interval_tree_insert (&tree, &N_50); - interval_tree_insert (&tree, &N_30); - interval_tree_insert (&tree, &N_20); - interval_tree_insert (&tree, &N_10); + itree_insert_node (&tree, &N_50); + itree_insert_node (&tree, &N_30); + itree_insert_node (&tree, &N_20); + itree_insert_node (&tree, &N_10); ck_assert (! N_50.red); ck_assert (! N_30.red); ck_assert (! N_20.red); @@ -159,11 +158,11 @@ START_TEST (test_insert_5) * (10) (20) */ - interval_tree_insert (&tree, &N_50); - interval_tree_insert (&tree, &N_30); - interval_tree_insert (&tree, &N_20); - interval_tree_insert (&tree, &N_10); - interval_tree_insert (&tree, &N_15); + itree_insert_node (&tree, &N_50); + itree_insert_node (&tree, &N_30); + itree_insert_node (&tree, &N_20); + itree_insert_node (&tree, &N_10); + itree_insert_node (&tree, &N_15); ck_assert (! N_50.red); ck_assert (! N_30.red); ck_assert (N_20.red); @@ -197,12 +196,12 @@ START_TEST (test_insert_6) * (5) */ - interval_tree_insert (&tree, &N_50); - interval_tree_insert (&tree, &N_30); - interval_tree_insert (&tree, &N_20); - interval_tree_insert (&tree, &N_10); - interval_tree_insert (&tree, &N_15); - interval_tree_insert (&tree, &N_05); + itree_insert_node (&tree, &N_50); + itree_insert_node (&tree, &N_30); + itree_insert_node (&tree, &N_20); + itree_insert_node (&tree, &N_10); + itree_insert_node (&tree, &N_15); + itree_insert_node (&tree, &N_05); ck_assert (! N_50.red); ck_assert (! N_30.red); ck_assert (! N_20.red); @@ -238,7 +237,7 @@ test_insert2_setup (void) enum { N = 6 }; const int values[] = {50, 70, 80, 90, 85, 95}; struct itree_node *nodes[N] = {&N_50, &N_70, &N_80, &N_90, &N_85, &N_95}; - interval_tree_init (&tree); + itree_init (&tree); for (int i = 0; i < N; ++i) { nodes[i]->begin = nodes[i]->end = values[i]; @@ -252,7 +251,7 @@ START_TEST (test_insert_7) * [50] */ - interval_tree_insert (&tree, &N_50); + itree_insert_node (&tree, &N_50); ck_assert (! N_50.red); ck_assert_ptr_eq (&N_50, tree.root); } @@ -266,8 +265,8 @@ START_TEST (test_insert_8) * (70) */ - interval_tree_insert (&tree, &N_50); - interval_tree_insert (&tree, &N_70); + itree_insert_node (&tree, &N_50); + itree_insert_node (&tree, &N_70); ck_assert (! N_50.red); ck_assert (N_70.red); ck_assert_ptr_eq (&N_50, tree.root); @@ -287,9 +286,9 @@ START_TEST (test_insert_9) * (50) (80) */ - interval_tree_insert (&tree, &N_50); - interval_tree_insert (&tree, &N_70); - interval_tree_insert (&tree, &N_80); + itree_insert_node (&tree, &N_50); + itree_insert_node (&tree, &N_70); + itree_insert_node (&tree, &N_80); ck_assert (N_50.red); ck_assert (! N_70.red); ck_assert (N_80.red); @@ -313,10 +312,10 @@ START_TEST (test_insert_10) * (90) */ - interval_tree_insert (&tree, &N_50); - interval_tree_insert (&tree, &N_70); - interval_tree_insert (&tree, &N_80); - interval_tree_insert (&tree, &N_90); + itree_insert_node (&tree, &N_50); + itree_insert_node (&tree, &N_70); + itree_insert_node (&tree, &N_80); + itree_insert_node (&tree, &N_90); ck_assert (! N_50.red); ck_assert (! N_70.red); ck_assert (! N_80.red); @@ -344,11 +343,11 @@ START_TEST (test_insert_11) * (80) (90) */ - interval_tree_insert (&tree, &N_50); - interval_tree_insert (&tree, &N_70); - interval_tree_insert (&tree, &N_80); - interval_tree_insert (&tree, &N_90); - interval_tree_insert (&tree, &N_85); + itree_insert_node (&tree, &N_50); + itree_insert_node (&tree, &N_70); + itree_insert_node (&tree, &N_80); + itree_insert_node (&tree, &N_90); + itree_insert_node (&tree, &N_85); ck_assert (! N_50.red); ck_assert (! N_70.red); ck_assert (N_80.red); @@ -383,12 +382,12 @@ START_TEST (test_insert_12) * (95) */ - interval_tree_insert (&tree, &N_50); - interval_tree_insert (&tree, &N_70); - interval_tree_insert (&tree, &N_80); - interval_tree_insert (&tree, &N_90); - interval_tree_insert (&tree, &N_85); - interval_tree_insert (&tree, &N_95); + itree_insert_node (&tree, &N_50); + itree_insert_node (&tree, &N_70); + itree_insert_node (&tree, &N_80); + itree_insert_node (&tree, &N_90); + itree_insert_node (&tree, &N_85); + itree_insert_node (&tree, &N_95); ck_assert (! N_50.red); ck_assert (! N_70.red); ck_assert (! N_80.red); @@ -419,7 +418,7 @@ START_TEST (test_insert_13) enum { N = 4 }; const int values[N] = {10, 20, 30, 40}; struct itree_node *nodes[N] = {&N_10, &N_20, &N_30, &N_40}; - interval_tree_init (&tree); + itree_init (&tree); for (int i = 0; i < N; ++i) itree_insert (&tree, nodes[i], values[i], values[i]); @@ -437,13 +436,13 @@ END_TEST START_TEST (test_insert_14) { enum { N = 3 }; - struct itree_node nodes[N]; - interval_tree_init (&tree); + struct itree_node nodes[N] = {0}; + itree_init (&tree); for (int i = 0; i < N; ++i) itree_insert (&tree, &nodes[i], 10, 10); for (int i = 0; i < N; ++i) - ck_assert (interval_tree_contains (&tree, &nodes[i])); + ck_assert (itree_contains (&tree, &nodes[i])); } END_TEST @@ -458,7 +457,7 @@ END_TEST static void test_remove1_setup (void) { - interval_tree_init (&tree); + itree_init (&tree); tree.root = &B; A.parent = &B; B.parent = NULL; C.parent = &D; D.parent = &B; E.parent = &D; A.left = A.right = C.left = C.right = E.left = E.right = NULL; @@ -480,7 +479,7 @@ START_TEST (test_remove_1) { B.red = A.red = C.red = E.red = false; D.red = true; - interval_tree_remove_fix (&tree, &A, &B); + itree_remove_fix (&tree, &A, &B); ck_assert (! A.red); ck_assert (! B.red); @@ -502,7 +501,7 @@ END_TEST START_TEST (test_remove_2) { B.red = D.red = A.red = C.red = E.red = false; - interval_tree_remove_fix (&tree, &A, &B); + itree_remove_fix (&tree, &A, &B); ck_assert (! A.red); ck_assert (! B.red); @@ -523,7 +522,7 @@ START_TEST (test_remove_3) { D.red = A.red = E.red = false; B.red = C.red = true; - interval_tree_remove_fix (&tree, &A, &B); + itree_remove_fix (&tree, &A, &B); ck_assert (! A.red); ck_assert (! B.red); @@ -546,7 +545,7 @@ START_TEST (test_remove_4) { B.red = C.red = E.red = true; A.red = D.red = false; - interval_tree_remove_fix (&tree, &A, &B); + itree_remove_fix (&tree, &A, &B); ck_assert (! A.red); ck_assert (! B.red); @@ -569,7 +568,7 @@ END_TEST static void test_remove2_setup (void) { - interval_tree_init (&tree); + itree_init (&tree); tree.root = &B; A.parent = &B; B.parent = NULL; C.parent = &D; D.parent = &B; E.parent = &D; A.right = A.left = C.right = C.left = E.right = E.left = NULL; @@ -589,7 +588,7 @@ START_TEST (test_remove_5) { B.red = A.red = C.red = E.red = false; D.red = true; - interval_tree_remove_fix (&tree, &A, &B); + itree_remove_fix (&tree, &A, &B); ck_assert (! A.red); ck_assert (! B.red); @@ -611,7 +610,7 @@ END_TEST START_TEST (test_remove_6) { B.red = D.red = A.red = C.red = E.red = false; - interval_tree_remove_fix (&tree, &A, &B); + itree_remove_fix (&tree, &A, &B); ck_assert (! A.red); ck_assert (! B.red); @@ -632,7 +631,7 @@ START_TEST (test_remove_7) { D.red = A.red = E.red = false; B.red = C.red = true; - interval_tree_remove_fix (&tree, &A, &B); + itree_remove_fix (&tree, &A, &B); ck_assert (! A.red); ck_assert (! B.red); @@ -655,7 +654,7 @@ START_TEST (test_remove_8) { B.red = C.red = E.red = true; A.red = D.red = false; - interval_tree_remove_fix (&tree, &A, &B); + itree_remove_fix (&tree, &A, &B); ck_assert (! A.red); ck_assert (! B.red); @@ -676,7 +675,7 @@ START_TEST (test_remove_9) enum { N = 4 }; const int values[N] = {10, 20, 30, 40}; struct itree_node *nodes[N] = {&N_10, &N_20, &N_30, &N_40}; - interval_tree_init (&tree); + itree_init (&tree); for (int i = 0; i < N; ++i) itree_insert (&tree, nodes[i], values[i], values[i]); @@ -722,8 +721,8 @@ START_TEST (test_remove_10) srand (42); shuffle (index, N); - interval_tree_init (&tree); - struct itree_node nodes[N]; + itree_init (&tree); + struct itree_node nodes[N] = {0}; for (int i = 0; i < N; ++i) { ptrdiff_t pos = (i + 1) * 10; @@ -733,10 +732,10 @@ START_TEST (test_remove_10) shuffle (index, N); for (int i = 0; i < N; ++i) { - ck_assert (interval_tree_contains (&tree, &nodes[index[i]])); + ck_assert (itree_contains (&tree, &nodes[index[i]])); itree_remove (&tree, &nodes[index[i]]); } - ck_assert_ptr_null (tree.root); + ck_assert (itree_empty_p (&tree)); ck_assert_int_eq (tree.size, 0); } END_TEST @@ -748,12 +747,12 @@ END_TEST START_TEST (test_generator_1) { - struct itree_node node, *n; - struct itree_iterator *g; - interval_tree_init (&tree); + struct itree_node node = {0}, *n; + struct itree_iterator it, *g; + itree_init (&tree); itree_insert (&tree, &node, 10, 20); - g = itree_iterator_start (&tree, 0, 30, ITREE_ASCENDING, NULL, 0); + g = itree_iterator_start (&it, &tree, 0, 30, ITREE_ASCENDING); n = itree_iterator_next (g); ck_assert_ptr_eq (n, &node); ck_assert_int_eq (n->begin, 10); @@ -761,13 +760,11 @@ START_TEST (test_generator_1) ck_assert_ptr_null (itree_iterator_next (g)); ck_assert_ptr_null (itree_iterator_next (g)); ck_assert_ptr_null (itree_iterator_next (g)); - itree_iterator_finish (g); - g = itree_iterator_start (&tree, 30, 50, ITREE_ASCENDING, NULL, 0); + g = itree_iterator_start (&it, &tree, 30, 50, ITREE_ASCENDING); ck_assert_ptr_null (itree_iterator_next (g)); ck_assert_ptr_null (itree_iterator_next (g)); ck_assert_ptr_null (itree_iterator_next (g)); - itree_iterator_finish (g); } END_TEST @@ -777,8 +774,8 @@ test_check_generator (struct itree_tree *tree, int n, ...) { va_list ap; - struct itree_iterator *g = - itree_iterator_start (tree, begin, end, ITREE_ASCENDING, NULL, 0); + struct itree_iterator it, *g = + itree_iterator_start (&it, tree, begin, end, ITREE_ASCENDING); va_start (ap, n); for (int i = 0; i < n; ++i) @@ -790,13 +787,12 @@ test_check_generator (struct itree_tree *tree, va_end (ap); ck_assert_ptr_null (itree_iterator_next (g)); ck_assert_ptr_null (itree_iterator_next (g)); - itree_iterator_finish (g); } START_TEST (test_generator_2) { - interval_tree_init (&tree); - struct itree_node nodes[3]; + itree_init (&tree); + struct itree_node nodes[3] = {0}; for (int i = 0; i < 3; ++i) itree_insert (&tree, &nodes[i], 10 * (i + 1), 10 * (i + 2)); @@ -830,7 +826,7 @@ test_create_tree (struct itree_node *nodes, int n, bool doshuffle) shuffle (index, n); } - interval_tree_init (&tree); + itree_init (&tree); for (int i = 0; i < n; ++i) { struct itree_node *node = &nodes[index[i]]; @@ -862,8 +858,8 @@ START_TEST (test_generator_5) {.begin = 30, .end = 50}, {.begin = 40, .end = 60}}; test_create_tree (nodes, N, false); - struct itree_iterator *g = - itree_iterator_start (&tree, 0, 100, ITREE_PRE_ORDER, NULL, 0); + struct itree_iterator it, *g = + itree_iterator_start (&it, &tree, 0, 100, ITREE_PRE_ORDER); for (int i = 0; i < N; ++i) { struct itree_node *n = itree_iterator_next (g); @@ -876,7 +872,6 @@ START_TEST (test_generator_5) case 3: ck_assert_int_eq (40, n->begin); break; } } - itree_iterator_finish (g); } END_TEST @@ -888,8 +883,8 @@ START_TEST (test_generator_6) {.begin = 30, .end = 50}, {.begin = 40, .end = 60}}; test_create_tree (nodes, N, true); - struct itree_iterator *g = - itree_iterator_start (&tree, 0, 100, ITREE_ASCENDING, NULL, 0); + struct itree_iterator it, *g = + itree_iterator_start (&it, &tree, 0, 100, ITREE_ASCENDING); for (int i = 0; i < N; ++i) { struct itree_node *n = itree_iterator_next (g); @@ -902,7 +897,6 @@ START_TEST (test_generator_6) case 3: ck_assert_int_eq (40, n->begin); break; } } - itree_iterator_finish (g); } END_TEST @@ -914,8 +908,8 @@ START_TEST (test_generator_7) {.begin = 30, .end = 50}, {.begin = 40, .end = 60}}; test_create_tree (nodes, N, true); - struct itree_iterator *g = - itree_iterator_start (&tree, 0, 100, ITREE_DESCENDING, NULL, 0); + struct itree_iterator it, *g = + itree_iterator_start (&it, &tree, 0, 100, ITREE_DESCENDING); for (int i = 0; i < N; ++i) { struct itree_node *n = itree_iterator_next (g); @@ -928,7 +922,6 @@ START_TEST (test_generator_7) case 3: ck_assert_int_eq (10, n->begin); break; } } - itree_iterator_finish (g); } END_TEST @@ -938,14 +931,13 @@ START_TEST (test_generator_8) struct itree_node nodes[N] = {{.begin = 20, .end = 30}, {.begin = 40, .end = 50}}; test_create_tree (nodes, N, false); - struct itree_iterator *g = - itree_iterator_start (&tree, 1, 60, ITREE_DESCENDING, NULL, 0); + struct itree_iterator it, *g = + itree_iterator_start (&it, &tree, 1, 60, ITREE_DESCENDING); struct itree_node *n = itree_iterator_next (g); ck_assert_int_eq (n->begin, 40); itree_iterator_narrow (g, 50, 60); n = itree_iterator_next (g); ck_assert_ptr_null (n); - itree_iterator_finish (g); } END_TEST @@ -955,14 +947,13 @@ START_TEST (test_generator_9) struct itree_node nodes[N] = {{.begin = 25, .end = 25}, {.begin = 20, .end = 30}}; test_create_tree (nodes, N, false); - struct itree_iterator *g = - itree_iterator_start (&tree, 1, 30, ITREE_DESCENDING, NULL, 0); + struct itree_iterator it, *g = + itree_iterator_start (&it, &tree, 1, 30, ITREE_DESCENDING); struct itree_node *n = itree_iterator_next (g); ck_assert_int_eq (n->begin, 25); itree_iterator_narrow (g, 25, 30); n = itree_iterator_next (g); ck_assert_int_eq (n->begin, 20); - itree_iterator_finish (g); } END_TEST @@ -981,7 +972,7 @@ static void test_setup_gap_node (ptrdiff_t begin, ptrdiff_t end, bool front_advance, bool rear_advance) { - interval_tree_init (&gap_tree); + itree_init (&gap_tree); gap_node.front_advance = front_advance; gap_node.rear_advance = rear_advance; itree_insert (&gap_tree, &gap_node, begin, end); @@ -1281,9 +1272,8 @@ main (void) Suite *s = basic_suite (); SRunner *sr = srunner_create (s); - init_itree (); srunner_run_all (sr, CK_ENV); - int nfailed = srunner_ntests_failed (sr); + int failed = srunner_ntests_failed (sr); srunner_free (sr); - return (nfailed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return failed ? EXIT_FAILURE : EXIT_SUCCESS; } |