emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/assess 216adb069c 47/95: Add assess-call.el


From: ELPA Syncer
Subject: [elpa] externals/assess 216adb069c 47/95: Add assess-call.el
Date: Tue, 19 Jul 2022 15:57:32 -0400 (EDT)

branch: externals/assess
commit 216adb069ced3904750e0fd8609d2e662d9f22c1
Author: Phillip Lord <phillip.lord@russet.org.uk>
Commit: Phillip Lord <phillip.lord@russet.org.uk>

    Add assess-call.el
    
    A new package for capturing parameters and return values.
---
 assess-call.el           | 54 ++++++++++++++++++++++++++++++++++++++
 test/assess-call-test.el | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+)

diff --git a/assess-call.el b/assess-call.el
new file mode 100644
index 0000000000..69f3c83a7e
--- /dev/null
+++ b/assess-call.el
@@ -0,0 +1,54 @@
+;;; assess-call.el --- Call and Return -*- lexical-binding: t -*-
+
+;;; Header:
+
+;; This file is not part of Emacs
+
+;; Author: Phillip Lord <phillip.lord@russet.org.uk>
+;; Maintainer: Phillip Lord <phillip.lord@russet.org.uk>
+;; Version: 0.1
+;; Package-Requires: ((emacs "24.4")(m-buffer "0.14")(dash "2.12.0"))
+
+;; The contents of this file are subject to the GPL License, Version 3.0.
+
+;; Copyright (C) 2016, Phillip Lord
+
+;; 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 <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Capture calls to functions, checking parameters and return values.
+
+;;; Code:
+
+;; #+begin_src emacs-lisp
+(defvar assess-call--capture-store nil)
+
+(defun assess-call--capture-advice (fn &rest args)
+  (let ((rtn (apply fn args)))
+    (setq assess-call--capture-store
+          (cons (cons args rtn)
+                assess-call--capture-store))
+    rtn))
+
+(defun assess-call-capture (sym-fn fn)
+  (setq assess-call--capture-store nil)
+  (advice-add sym-fn :around #'assess-call--capture-advice)
+  (funcall fn)
+  (advice-remove sym-fn #'siyphus-call--capture-advice)
+  assess-call--capture-store)
+
+(provide 'assess-call)
+;;; assess-call.el ends here
+;; #+end_src
diff --git a/test/assess-call-test.el b/test/assess-call-test.el
new file mode 100644
index 0000000000..9c61ab2a4e
--- /dev/null
+++ b/test/assess-call-test.el
@@ -0,0 +1,68 @@
+;;; assess-call-test.el --- Tests for assess-call.el -*- lexical-binding: t -*-
+
+;;; Header:
+
+;; The contents of this file are subject to the GPL License, Version 3.0.
+
+;; Copyright (C) 2015, Phillip Lord, Newcastle University
+
+;; 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 <http://www.gnu.org/licenses/>.
+
+
+;;; Code:
+
+;; ** Requires
+
+;; #+begin_src emacs-lisp
+(require 'ert)
+(require 'assess-call)
+
+(defun assess-call-return-car (&rest args)
+  (car args))
+
+(defun assess-call-call-return-car (&rest args)
+  (apply #'assess-call-return-car args))
+
+(ert-deftest call-capture ()
+  (should
+   (equal
+    '(((10 11 12) . 10))
+    (assess-call-capture
+     'assess-call-return-car
+     (lambda ()
+       (assess-call-return-car 10 11 12))))))
+
+(ert-deftest call-capture-deep ()
+  (should
+   (equal
+    '(((20 21 22) . 20))
+    (assess-call-capture
+     'assess-call-return-car
+     (lambda ()
+       (assess-call-call-return-car 20 21 22))))))
+
+(defun call-capture-multiply (a b)
+  (* a b))
+
+(ert-deftest call-capture-twice ()
+  (should
+   (equal
+    '(((3 4) . 12) ((1 2) . 2))
+    (assess-call-capture
+     'call-capture-multiply
+     (lambda ()
+       (call-capture-multiply 1 2)
+       (call-capture-multiply 3 4))))))
+
+(provide 'assess-call-test)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]