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

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

[elpa] externals/assess 41a297b066 01/95: Initial Checkin


From: ELPA Syncer
Subject: [elpa] externals/assess 41a297b066 01/95: Initial Checkin
Date: Tue, 19 Jul 2022 15:57:28 -0400 (EDT)

branch: externals/assess
commit 41a297b0668c18af9731ba95abb6f809e3d8201b
Author: Phillip Lord <phillip.lord@newcastle.ac.uk>
Commit: Phillip Lord <phillip.lord@newcastle.ac.uk>

    Initial Checkin
---
 .dir-locals.el        |   5 ++
 .ert-runner           |   1 +
 .gitignore            |   2 +
 .travis.yml           |  15 ++++
 Cask                  |   7 ++
 Makefile              |  15 ++++
 README.md             |   6 ++
 sisyphus.el           | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++
 test/Makefile         |   6 ++
 test/sisyphus-test.el |  58 +++++++++++++++
 10 files changed, 313 insertions(+)

diff --git a/.dir-locals.el b/.dir-locals.el
new file mode 100644
index 0000000000..42753331cc
--- /dev/null
+++ b/.dir-locals.el
@@ -0,0 +1,5 @@
+;;; Directory Local Variables
+;;; For more information see (info "(emacs) Directory Variables")
+
+((emacs-lisp-mode
+  (lentic-init . lentic-orgel-org-init)))
diff --git a/.ert-runner b/.ert-runner
new file mode 100644
index 0000000000..b4e59470d5
--- /dev/null
+++ b/.ert-runner
@@ -0,0 +1 @@
+--load sisyphus.el
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000..70590b848b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/.cask
+/sisyphus.org
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000000..7d3a37fab9
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,15 @@
+language: generic
+sudo: no
+env:
+  - EVM_EMACS=emacs-24.1-travis
+  - EVM_EMACS=emacs-24.2-travis
+  - EVM_EMACS=emacs-24.3-travis
+  - EVM_EMACS=emacs-24.4-travis
+  - EVM_EMACS=emacs-24.5-travis
+install:
+  - curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw > 
travis.sh && source ./travis.sh
+  - evm install $EVM_EMACS --use --skip
+  - cask
+script:
+  - emacs --version
+  - make
\ No newline at end of file
diff --git a/Cask b/Cask
new file mode 100644
index 0000000000..7430091a46
--- /dev/null
+++ b/Cask
@@ -0,0 +1,7 @@
+(source gnu)
+(source melpa-stable)
+
+(package-file "sisyphus.el")
+
+(development
+ (depends-on "ert-runner"))
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000000..6d34bef733
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,15 @@
+EMACS ?= emacs
+CASK ?= cask
+
+all: install test
+
+install:
+       cask install
+
+just-test:
+       cask exec ert-runner
+
+test: install just-test
+
+
+.PHONY: test
diff --git a/README.md b/README.md
new file mode 100644
index 0000000000..7d2bf8a2bc
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+Sisyphus
+========
+
+Sisyphus provides additional support for testing Emacs packages.
+
+It is quite early stages at the moment.
diff --git a/sisyphus.el b/sisyphus.el
new file mode 100644
index 0000000000..35dae33437
--- /dev/null
+++ b/sisyphus.el
@@ -0,0 +1,198 @@
+;;; sisyphus.el --- Test support functions -*- 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: ((m-buffer "0.13"))
+
+;; The contents of this file are subject to the GPL License, Version 3.0.
+
+;; Copyright (C) 2015, 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:
+
+;; This file will provide functions to support ert, including a set of
+;; predicates, some nicer reporter functions and so forth.
+
+;;; Thoughts:
+
+;; Really, all the functions in here should be tested. But some of the tests 
are
+;; really, realy hard to test because they depend on the output of ert test,
+;; wh
+
+
+
+
+;;; Code:
+
+;; ** Require
+
+;; #+begin_src emacs-lisp
+(require 'pp)
+(require 'ert)
+;; #+end_src
+
+;; ** Advice
+
+
+;; #+begin_src emacs-lisp
+(defun sisyphus--ert-pp-with-indentation-and-newline (orig object)
+  (let ((pp-escape-newlines nil))
+    (funcall orig object)))
+
+(advice-add
+ 'ert--pp-with-indentation-and-newline
+ :around
+ #'sisyphus--ert-pp-with-indentation-and-newline)
+;; #+end_src
+
+
+;; ** Explainers
+
+;; Explainer functions add "explainations" for things that fail. We can use 
this
+;; to make `string=' work properly. Can we do this without diff?
+
+;; This is critical because most of our comparitors depend on this.
+
+;; So this works but the output is printed out as a string with slash-n's
+;; rather than as a multi-line string. Bollocks
+
+;; Think it is ert--pp-with-indentation-and-newline which is the evil function
+;; causing the problem. Which in turn backs onto pp.
+
+;; pp has a variable pp-escape-newlines which set to nil solves the problem.
+
+;; How do do this cleanly? Apply patch to ert.el?
+
+;; *** String Comparision
+
+;; #+begin_src emacs-lisp
+(defun sisyphus--explainer-diff-string= (a b)
+  "Compare strings using diff output."
+  (let* ((diff
+          (executable-find "diff"))
+         (a-buffer
+          (generate-new-buffer "a"))
+         (b-buffer
+          (generate-new-buffer "b"))
+         (a-file
+          (make-temp-file
+           (buffer-name a-buffer)))
+         (b-file
+          (make-temp-file
+           (buffer-name b-buffer))))
+    (with-current-buffer
+        a-buffer
+      (insert a)
+      (write-file a-file))
+    (with-current-buffer
+        b-buffer
+      (insert b)
+      (write-file b-file))
+    (prog1
+        (format "Strings:\n%s\nand\n%s\nDiffer at:%s\n"
+                a b
+                (with-temp-buffer
+                  (call-process
+                   diff
+                   ;; no infile
+                   nil
+                   ;; dump to current buffer
+                   t
+                   nil
+                   "-c"
+                   a-file
+                   b-file)
+                  (buffer-string)))
+      (kill-buffer a-buffer)
+      (kill-buffer b-buffer))))
+
+(defun sisyphus--explainer-simple-string= (a b)
+  "Compare strings for first difference."
+  ;; We could do a bit more here.
+  (format "String :%s:%s: are not equal."))
+
+(defun sisyphus-explain-string= (a b)
+  "Compare strings and return an explanation."
+  (cond
+   ((string= a b)
+    t)
+   ((executable-find "diff")
+    (sisyphus--explainer-diff-string= a b))
+   (t
+    (sisyphus--explainer-simple-string= a b))))
+
+(put 'string= 'ert-explainer 'sisyphus-explain-string=)
+;; #+end_src
+
+;;; *** String to buffer
+
+;; #+begin_src emacs-lisp
+(defun sisyphus-buffer-string= (buffer string)
+  (string=
+   (m-buffer-at-substring buffer)
+   string))
+
+;; #+end_src
+
+;; Compare string to buffer
+
+;; Compare buffer to buffer
+
+;; Compare string to file
+
+;; Compare buffer to file
+
+;; Compare file to file.
+
+;; ** Create buffers
+
+;; Need to think carefully about this, but would like to create buffers. Temp
+;; buffers are generally a good option but what if we have a named buffer, but
+;; the named buffer is already open. What happens if a test creates a buffer? 
Can
+;; we detect the buffer creation and close them again?
+;; "with-protected-buffer-list" perhaps, or "save-buffer-list-excursion".
+
+;; ** Open files
+
+;; Again, same issues -- what if the file is already open. Especially if are
+;; going to save it.
+
+;; ** Indentation functions
+
+;; Set mode, indent normally, then compare
+
+;; ** Font-lock support functions
+
+;; Set up a buffer from string or file, font-lock it, test it.
+
+;; ** Pre/post command support functions
+
+;; Not sure how I can test these better -- but worth thinking about -- I guess 
do
+;; some set up, then and buffer-local pre or post command, run some stuff, 
compare.
+
+;; #+begin_src emacs-lisp
+(provide 'sisyphus)
+;; #+end_src
+
+
+;; #+begin_src emacs-lisp
+;;; sisyphus.el ends here
+;; #+end_src
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000000..84066464ee
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,6 @@
+## what ever we called, don't do it here
+default:
+       $(MAKE) -C ..
+
+$(MAKECMDGOALS):
+       $(MAKE) -C .. $(MAKECMDGOALS)
diff --git a/test/sisyphus-test.el b/test/sisyphus-test.el
new file mode 100644
index 0000000000..a68d3f6b8d
--- /dev/null
+++ b/test/sisyphus-test.el
@@ -0,0 +1,58 @@
+;; 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/>.
+
+(require 'sisyphus)
+
+(defun sisyphus-test--plist-from-test (result)
+  (cdadr
+   (ert-test-result-with-condition-condition result)))
+
+(ert-deftest plist-extraction ()
+  (should
+   (equal
+    (sisyphus-test--plist-from-test
+     (ert-run-test
+      (make-ert-test
+       :body
+       (lambda ()
+         (should
+          (eq 1 2))))))
+    '(:form (eq 1 2) :value nil))))
+
+(defun sisyphus-test--explanation-from-test (result)
+  (plist-get
+   (sisyphus-test--plist-from-test result)
+   :explanation))
+
+(ert-deftest explanation-extraction ()
+  "Test that explanation is extractable from failing test.
+This also tests the advice on string=."
+  (should
+   (sisyphus-test--explanation-from-test
+    (ert-run-test
+     (make-ert-test
+      :body
+      (lambda ()
+        (should
+         (string= "1" "2"))))))))
+
+(ert-deftest sisyphus-test--string= ()
+  "Test that string= works after explanation added."
+  (should
+   (string= "1" "1"))
+  (should-not
+   (string= "1" "2")))



reply via email to

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