From 47ab6c237e703cf4b5bbcd3c301e324e0deb1173 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Tue, 10 Dec 2019 12:55:34 +0100 Subject: [PATCH] Add some testing for dynamic scope * test/src/comp-test-funcs-dyn.el: New file. * test/src/comp-tests.el (comp-tests-dynamic-ffuncall): Add new tests. --- test/src/comp-test-funcs-dyn.el | 40 ++++++++++++++++++++++++++++ test/src/comp-tests.el | 46 ++++++++++++++++++++++++++++++--- 2 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 test/src/comp-test-funcs-dyn.el diff --git a/test/src/comp-test-funcs-dyn.el b/test/src/comp-test-funcs-dyn.el new file mode 100644 index 00000000000..0e342a39d3e --- /dev/null +++ b/test/src/comp-test-funcs-dyn.el @@ -0,0 +1,40 @@ +;;; comp-test-funcs.el --- compilation unit tested by comp-tests.el -*- lexical-binding: nil; -*- + +;; Copyright (C) 2020 Free Software Foundation, Inc. + +;; Author: Andrea Corallo + +;; 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 . + +;;; Commentary: + +;;; Code: + +(defun comp-tests-ffuncall-callee-dyn-f (a b) + (list a b)) + +(defun comp-tests-ffuncall-callee-opt-dyn-f (a b &optional c d) + (list a b c d)) + +(defun comp-tests-ffuncall-callee-rest-dyn-f (a b &rest c) + (list a b c)) + +(defun comp-tests-ffuncall-callee-opt-rest-dyn-f (a b &optional c &rest d) + (list a b c d)) + +(provide 'comp-test-dyn-funcs) + +;;; comp-test-funcs-dyn.el ends here diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index 3e40dba10b4..ee96d5656e7 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el @@ -34,8 +34,14 @@ (defconst comp-test-src (concat comp-test-directory "comp-test-funcs.el")) -(message "Compiling %s" comp-test-src) +(defconst comp-test-dyn-src + (concat comp-test-directory "comp-test-funcs-dyn.el")) + +(message "Compiling tests...") (load (native-compile comp-test-src)) +(load (native-compile comp-test-dyn-src)) + + (ert-deftest comp-tests-bootstrap () "Compile the compiler and load it to compile it-self. @@ -353,9 +359,9 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-03/msg00914.html." (should (eq (comp-test-40187-2-f) 'bar))) -;;;;;;;;;;;;;;;;;;;; -;; Tromey's tests ;; -;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;; +;; Tromey's tests. ;; +;;;;;;;;;;;;;;;;;;;;; (ert-deftest comp-consp () (should-not (comp-test-consp 23)) @@ -520,4 +526,36 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-03/msg00914.html." nil)) (should (eq comp-test-up-val 999))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Tests for dynamic scope. ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(ert-deftest comp-tests-dynamic-ffuncall () + "Test calling convention for dynamic binding." + + (should (equal (comp-tests-ffuncall-callee-dyn-f 1 2) + '(1 2))) + + (should (equal (comp-tests-ffuncall-callee-opt-dyn-f 1 2 3 4) + '(1 2 3 4))) + (should (equal (comp-tests-ffuncall-callee-opt-dyn-f 1 2 3) + '(1 2 3 nil))) + (should (equal (comp-tests-ffuncall-callee-opt-dyn-f 1 2) + '(1 2 nil nil))) + + (should (equal (comp-tests-ffuncall-callee-rest-dyn-f 1 2) + '(1 2 nil))) + (should (equal (comp-tests-ffuncall-callee-rest-dyn-f 1 2 3) + '(1 2 (3)))) + (should (equal (comp-tests-ffuncall-callee-rest-dyn-f 1 2 3 4) + '(1 2 (3 4)))) + + (should (equal (comp-tests-ffuncall-callee-opt-rest-dyn-f 1 2) + '(1 2 nil nil))) + (should (equal (comp-tests-ffuncall-callee-opt-rest-dyn-f 1 2 3) + '(1 2 3 nil))) + (should (equal (comp-tests-ffuncall-callee-opt-rest-dyn-f 1 2 3 4) + '(1 2 3 (4))))) + ;;; comp-tests.el ends here -- 2.39.5