[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)
- [elpa] externals/assess 3cf57afcaf 26/95: Merge pull request #1 from syohex/fix, (continued)
- [elpa] externals/assess 3cf57afcaf 26/95: Merge pull request #1 from syohex/fix, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 00c794a516 29/95: Add package support., ELPA Syncer, 2022/07/19
- [elpa] externals/assess f490f18a18 32/95: Merge branch 'master' of github.com:phillord/sisyphus, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 0d079db1a7 34/95: Completed documentation., ELPA Syncer, 2022/07/19
- [elpa] externals/assess cab9fea7b8 28/95: Documentation for everything, ELPA Syncer, 2022/07/19
- [elpa] externals/assess f521db4101 36/95: Add sisyphus-discover, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 46290f163d 37/95: Add tests for discover., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 38fc7829bc 42/95: Interpret nil to mean no faces., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 818cf77258 27/95: Merge pull request #2 from syohex/minimum, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 880d519d6b 35/95: Update readme, add infojs., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 216adb069c 47/95: Add assess-call.el,
ELPA Syncer <=
- [elpa] externals/assess 07bd7f8915 58/95: Doc fixes, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 739661405b 59/95: Add assess-robot.el and tests, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 9521b07480 71/95: Fix and Publish documentation statically, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 5aee8d7500 81/95: Mark some tests as failed on earlier emacs, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 0a3e94477a 78/95: Support all of Emacs 24 series, ELPA Syncer, 2022/07/19
- [elpa] externals/assess e5b0415126 85/95: Update README and release number, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 7a3189a587 86/95: Remove types and replace with convertors, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 5bac045b27 94/95: Update version, ELPA Syncer, 2022/07/19
- [elpa] externals/assess ac8ff1f928 39/95: Change all file names to assess., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 4bf702a08a 43/95: Re-order to put macros first., ELPA Syncer, 2022/07/19