From 15bcbdbf55aac7e417adb282c70d51bf9c4815ae Mon Sep 17 00:00:00 2001 From: Psionik K <73710933+psionic-k@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:19:17 +0900 Subject: [PATCH 1/9] move erk--last-defname Signed-off-by: Psionik K <73710933+psionic-k@users.noreply.github.com> --- lisp/erk.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lisp/erk.el b/lisp/erk.el index 8956c7b..939a598 100644 --- a/lisp/erk.el +++ b/lisp/erk.el @@ -357,6 +357,16 @@ for development, and being lenient for degenerate cases is fine." ;; back into elisp files (find-file (erk--project-root-feature-file))))) +(defun erk--last-defname () + "Return previous definition and name. +Returns nil if we don't know what kind of definition it is or +what to do with it (yet). Returns `(def . name)' form." + (save-excursion + (beginning-of-defun) + (pcase-let* ((`(,def ,name) + (funcall load-read-function (current-buffer)))) + (cons def name)))) + (defun erk--insert-test (fun buffer) "Insert test named TEST-SYMBOL for FUN into BUFFER." (pop-to-buffer buffer) @@ -377,16 +387,6 @@ for development, and being lenient for degenerate cases is fine." (save-excursion (insert after)))) -(defun erk--last-defname () - "Return previous definition and name. -Returns nil if we don't know what kind of definition it is or -what to do with it (yet). Returns `(def . name)' form." - (save-excursion - (beginning-of-defun) - (pcase-let* ((`(,def ,name) - (funcall load-read-function (current-buffer)))) - (cons def name)))) - (defun erk--make-test-symbol (symbol) "Convert defun SYMBOL into test symbol." (intern (concat (symbol-name symbol) "-test" ))) From 47dff831583202be4892f6d9e8aa3cdb95d722e0 Mon Sep 17 00:00:00 2001 From: Psionik K <73710933+psionic-k@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:19:33 +0900 Subject: [PATCH 2/9] insert functions near point only if the point is near deftest otherwise puts the test end at at the end of the tests Signed-off-by: Psionik K <73710933+psionic-k@users.noreply.github.com> --- lisp/erk.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/erk.el b/lisp/erk.el index 939a598..eef53fa 100644 --- a/lisp/erk.el +++ b/lisp/erk.el @@ -372,7 +372,7 @@ what to do with it (yet). Returns `(def . name)' form." (pop-to-buffer buffer) ;; If the buffer is open and the point is near a defun already, just slam in a ;; test. If not, put the test in at the end. - (if (erk--last-defname) + (if (eq (car (erk--last-defname)) 'ert-deftest) (progn (beginning-of-defun) (forward-sexp)) From 493037efb91db823cdb8e3569885a341276e3aa9 Mon Sep 17 00:00:00 2001 From: Psionik K <73710933+psionic-k@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:20:41 +0900 Subject: [PATCH 3/9] normalize to display using swtich-to-buffer and recenter Signed-off-by: Psionik K <73710933+psionic-k@users.noreply.github.com> --- lisp/erk.el | 11 +++++++---- test/erk-test.el | 11 +++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lisp/erk.el b/lisp/erk.el index eef53fa..23cdcaa 100644 --- a/lisp/erk.el +++ b/lisp/erk.el @@ -385,7 +385,8 @@ what to do with it (yet). Returns `(def . name)' form." (after ")))")) (insert before) (save-excursion - (insert after)))) + (insert after)) + (recenter))) (defun erk--make-test-symbol (symbol) "Convert defun SYMBOL into test symbol." @@ -417,8 +418,9 @@ corresponding `defun' are supported." (progn (erk-reload-project-tests) (when (ert-test-boundp test-name) test-name))))) (if test - (progn (ert-find-test-other-window test) - (forward-sexp)) + (progn (find-function-do-it test 'ert--test 'switch-to-buffer) + (forward-sexp) + (recenter)) (let ((test-buffer (erk-jump-features))) (when (y-or-n-p (format "%s not found. Create? " test-name)) @@ -431,7 +433,8 @@ corresponding `defun' are supported." (if def (progn (find-function-do-it def nil 'switch-to-buffer) - (forward-sexp)) + (forward-sexp) + (recenter)) (progn (erk-jump-features) (user-error "Definition not found: %s" def-name))))) (_ diff --git a/test/erk-test.el b/test/erk-test.el index 933d971..0a35ca0 100644 --- a/test/erk-test.el +++ b/test/erk-test.el @@ -112,6 +112,17 @@ (erk-jump-features) (string-match-p "lisp" default-directory)))) +(ert-deftest erk-jump-defs-test () + (should + (save-window-excursion + (find-file (concat (erk--project-elisp-dir) + "/erk.el")) + (save-excursion + (goto-char (point-min)) + (search-forward "(defun erk-jump-defs") + (erk-jump-defs) + (string-match-p "erk-test.el" (buffer-file-name (current-buffer))))))) + (ert-deftest erk--project-elisp-dir-test () (should (erk--project-elisp-dir))) From 3ada1add2ada474ed298152c42e4ea4e38508e16 Mon Sep 17 00:00:00 2001 From: Psionik K <73710933+psionic-k@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:35:05 +0900 Subject: [PATCH 4/9] ! start cleaning up test state / behavior Signed-off-by: Psionik K <73710933+psionic-k@users.noreply.github.com> --- test/erk-test.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/erk-test.el b/test/erk-test.el index 0a35ca0..e816aa6 100644 --- a/test/erk-test.el +++ b/test/erk-test.el @@ -93,7 +93,7 @@ (ert-deftest erk-jump-features-test () ;; jump to feature when in tests (should - (save-excursion + (save-window-excursion ;; test normally executes in a temporary buffer but `erk-jump-features' ;; relies on `current-buffer'. (find-file (erk--project-root-feature-file)) @@ -101,13 +101,13 @@ (string-match-p "test" default-directory))) ;; jump to tests when in feature (should - (save-excursion + (save-window-excursion (find-file (concat (erk--test-directory) "erk-test.el")) (erk-jump-features) (string-match-p "lisp" default-directory))) ;; jump to feature when in root (should - (save-excursion + (save-window-excursion (find-file (concat (erk--project-root) "README.md")) (erk-jump-features) (string-match-p "lisp" default-directory)))) @@ -148,6 +148,7 @@ (should (erk--project-contains-p (erk--project-root-feature-file)))) (ert-deftest erk-clone-test () + :tags '("slow") (let ((enable-local-variables nil) (clone-root (make-temp-file "erk-clone-test-" t))) (erk-clone (cdr (assoc 'erk-basic erk-templates)) @@ -161,6 +162,7 @@ (delete-directory clone-root t))) (ert-deftest erk-new-test () + :tags '("slow") (let ((enable-local-variables nil) (erk-after-new-hook (when (require 'magit nil t) '(magit-status))) From 86974e5b5aa9f61e8d2a098e686c5b23c10c05ba Mon Sep 17 00:00:00 2001 From: Psionik K <73710933+psionic-k@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:35:28 +0900 Subject: [PATCH 5/9] - minor documentation Signed-off-by: Psionik K <73710933+psionic-k@users.noreply.github.com> --- doc/README.org | 5 +---- lisp/erk.el | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/README.org b/doc/README.org index 22fbeb8..52ee2a6 100644 --- a/doc/README.org +++ b/doc/README.org @@ -180,16 +180,13 @@ answer all the questions. - Expose trivial options where a structural choice has limited them unnecessarily - Behave the same, but with a less complicated code - - Guix or other pure dependency management support + - More templates, such as those for dynamic modules or using different CI Changes will likely be rejected if it is aimed at: - Non-elisp interfaces meant for invocation outside of Emacs or with scripting implemented in a language besides elisp. - Managing dependencies outside of Nix (or other pure dependency management) - expressions - - CI infrastructure support for non-Actions infrastructure (which cannot be - tested in this repo) - Backwards compatibility for Emacs two versions behind next release. Master, current stable release, and release - 1 are the only versions being supported - pre-flake Nix support diff --git a/lisp/erk.el b/lisp/erk.el index 23cdcaa..9018652 100644 --- a/lisp/erk.el +++ b/lisp/erk.el @@ -381,6 +381,7 @@ what to do with it (yet). Returns `(def . name)' form." (backward-sexp) (backward-sexp) (forward-sexp))) + ;; TODO test templates configuration (let ((before (format "\n\n(ert-deftest %s-test ()\n (should (%s" fun fun)) (after ")))")) (insert before) From a9b94c20f50c73bba2bcb0c71a4aa75b14291c3c Mon Sep 17 00:00:00 2001 From: Psionik K <73710933+psionic-k@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:35:36 +0900 Subject: [PATCH 6/9] generated Signed-off-by: Psionik K <73710933+psionic-k@users.noreply.github.com> --- README.md | 61 ++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index f0b4108..3b296d9 100644 --- a/README.md +++ b/README.md @@ -50,30 +50,30 @@ your secrets for Cachix. Read the CI customization section. # Table of Contents -- [Creating Packages](#orgdbe452f) -- [Using ERK for development](#orgac601cf) - - [Loading and re-loading your package](#orga0cf377) - - [Jumping to files](#org396eda3) - - [Run tests](#orgcda3976) - - [Duplicating CI Locally](#org3dacc44) - - [Find Files](#org4970f85) -- [File contents and structure](#org8ce5e2c) - - [Setting Up Your Github Repository](#orge370d02) -- [Customizing CI](#orgad90c4f) -- [Licensing, Developer Certificate of Origin](#orgbccb740) -- [Publishing to MELPA](#org89cc5b7) - - [Creating the recipe](#orgc42570c) - - [Testing package build](#org8509443) - - [Testing stable package build](#orgf82d903) - - [MELPA Lints](#org0496004) -- [Maintaining versions](#org2c1191b) -- [Package scope and relation to other work](#orge7e095a) - - [Dependency Management](#org5df7fa9) - - [Discovering and Running Tests & Lints](#orgdcccbf5) - - [Comparisons](#orgbfd286f) -- [Contributing](#orgbaa1077) -- [Footnote on FSF and Emacs Core Licensing](#orgd1e7ded) -- [Shout-outs](#org0f2ed06) +- [Creating Packages](#org55d6c6f) +- [Using ERK for development](#org8df953f) + - [Loading and re-loading your package](#org832dbac) + - [Jumping to files](#org6cd8dde) + - [Run tests](#org59f2f7b) + - [Duplicating CI Locally](#org512e00a) + - [Find Files](#orgd13d7b8) +- [File contents and structure](#orgd91f6b8) + - [Setting Up Your Github Repository](#org2b43980) +- [Customizing CI](#org6f4bf92) +- [Licensing, Developer Certificate of Origin](#org5d1d80d) +- [Publishing to MELPA](#orgf9492cc) + - [Creating the recipe](#org1bcced8) + - [Testing package build](#orgea41cb1) + - [Testing stable package build](#org6975475) + - [MELPA Lints](#orgef6e69d) +- [Maintaining versions](#org90c8308) +- [Package scope and relation to other work](#org74f808b) + - [Dependency Management](#org7e7eab5) + - [Discovering and Running Tests & Lints](#orgdc8001e) + - [Comparisons](#orgccbe76b) +- [Contributing](#org729e175) +- [Footnote on FSF and Emacs Core Licensing](#orga0697b8) +- [Shout-outs](#orgd54722e) # Creating Packages @@ -92,7 +92,7 @@ ask you for: `erk-new` also calls `erk-rename-relicense` to rename all of the files, string replace names, and re-license to GPL3. It also changes the author and resets -the git history. Now just follow the steps in [finish setting up](#orge370d02). Have fun! +the git history. Now just follow the steps in [finish setting up](#org2b43980). Have fun! # Using ERK for development @@ -220,10 +220,10 @@ directories. You can copy this checklist to your org agenda files: -- [X] Create a repository (from [install](#orgb10843e) instructions) +- [X] Create a repository (from [install](#org97f4634) instructions) - [ ] Create an empty GitHub repository configure it as your git remote - [ ] Set up your git commit signing (and verification so that it's obvious) - **and** [sign-off](#orgbccb740) so that it will be hypothetically [straightforward](README.md) for for FSF + **and** [sign-off](#org5d1d80d) so that it will be hypothetically [straightforward](README.md) for for FSF to pull in your changes if they later change to DCO instead of copyright assignment. - [ ] Sign up for [cachix](https://app.cachix.org/) and, create a binary cache with API tokens and public @@ -243,7 +243,7 @@ You can copy this checklist to your org agenda files: **Note**, Python is used to run a DCO check script, nothing more. - [ ] Get your package working, pushed, actions run, and CI badges all green -- [ ] [Publish](#org89cc5b7) to MELPA +- [ ] [Publish](#orgf9492cc) to MELPA - [ ] Make a post on [reddit](https://reddit.com/r/emacs/) and [mastodon](https://emacs.ch/) about your new package @@ -538,16 +538,13 @@ Non-exhaustive list of changes that are very welcome: - Expose trivial options where a structural choice has limited them unnecessarily - Behave the same, but with a less complicated code -- Guix or other pure dependency management support +- More templates, such as those for dynamic modules or using different CI Changes will likely be rejected if it is aimed at: - Non-elisp interfaces meant for invocation outside of Emacs or with scripting implemented in a language besides elisp. - Managing dependencies outside of Nix (or other pure dependency management) - expressions -- CI infrastructure support for non-Actions infrastructure (which cannot be - tested in this repo) - Backwards compatibility for Emacs two versions behind next release. Master, current stable release, and release - 1 are the only versions being supported - pre-flake Nix support From 22fed5591568066082b33c2cb7473cd3799de8de Mon Sep 17 00:00:00 2001 From: Psionik K <73710933+psionic-k@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:12:21 +0900 Subject: [PATCH 7/9] Preparing to make better test shortcuts Signed-off-by: Psionik K <73710933+psionic-k@users.noreply.github.com> --- lisp/erk.el | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lisp/erk.el b/lisp/erk.el index 9018652..f104cf6 100644 --- a/lisp/erk.el +++ b/lisp/erk.el @@ -482,26 +482,31 @@ Will reload all features and test features." (defun erk-ert-project-results-buffer () "Return an ERT buffer name based on project name.") +(defun erk--get-ert-test-symbols () + "Return all defined ERT test symbols. +Does not reload." + (let ((test-features (erk--test-features))) + (->> test-features + (-map #'symbol-file) + (--map (cdr (assoc it load-history))) + (-flatten-n 1) + (--filter (eq 'define-symbol-props (car it))) + (-map #'cdr) + (-flatten-n 2) + (--filter (plist-get (symbol-plist it) 'ert--test))))) + (defun erk-ert-project-selector () "Return a selector for just this project's ERT test. This selector generates the symbols list before that selector will run, so new features or new symbols only available after reload will not be picked up. Run this after any necessary feature reloading." - (let* ((test-features (erk--test-features)) - (test-symbols (->> test-features - (-map #'symbol-file) - (--map (cdr (assoc it load-history))) - (-flatten-n 1) - (--filter (eq 'define-symbol-props (car it))) - (-map #'cdr) - (-flatten-n 2)))) - (message "test-symbols: %s" test-symbols) - `(satisfies ,(lambda (test) - (member (ert-test-name test) test-symbols))))) + `(member ,@(erk--get-ert-test-symbols))) ;;;###autoload (defun erk-ert-project () + ;; TODO select failed, automatically when there are failed figure out how to + ;; offer up tags as options. See `ert-select-tests', but it's just okay "Run Ert interactively, with selector for this project." (interactive) (erk-reload-project-package) From 5bce74ce210a17805d4cfc82926f1edabbc19fa0 Mon Sep 17 00:00:00 2001 From: Psionik K <73710933+psionic-k@users.noreply.github.com> Date: Mon, 6 Nov 2023 12:59:58 +0900 Subject: [PATCH 8/9] filter flycheck temp files from erk--dir-elisp-files Signed-off-by: Psionik K <73710933+psionic-k@users.noreply.github.com> --- lisp/erk.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lisp/erk.el b/lisp/erk.el index f104cf6..b9ed3b3 100644 --- a/lisp/erk.el +++ b/lisp/erk.el @@ -233,8 +233,11 @@ Returns FUN if it's bound and within the project." "Return a list of the elisp files in DIR. Ignore autoloads." (->> - (directory-files dir nil (rx ".el" string-end)) - (--reject (string-match-p (rx "autoloads.el" string-end) it)))) + (directory-files dir nil (rx (literal ".el") string-end)) + (--reject (string-match-p (rx (literal "autoloads.el") line-end) it)) + ;; flycheck creates a short-lived file starting with flycheck_ + ;; Will heisenbug you. + (--reject (string-match-p (rx line-start (literal "flycheck_")) it)))) (defun erk--dir-features (dir) "Return list of features provided by elisp files in DIR. From 49611de3ed000b5872c63270dd66efa0e6bf76c9 Mon Sep 17 00:00:00 2001 From: Psionik K <73710933+psionic-k@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:00:51 +0900 Subject: [PATCH 9/9] execute the fallback jump, stay quiet about it We can add some debugging messages with a debug flag, but the messages were just noise. Not the only offenders Signed-off-by: Psionik K <73710933+psionic-k@users.noreply.github.com> --- lisp/erk.el | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lisp/erk.el b/lisp/erk.el index b9ed3b3..6dd073d 100644 --- a/lisp/erk.el +++ b/lisp/erk.el @@ -439,12 +439,8 @@ corresponding `defun' are supported." (find-function-do-it def nil 'switch-to-buffer) (forward-sexp) (recenter)) - (progn (erk-jump-features) - (user-error "Definition not found: %s" def-name))))) + (progn (erk-jump-features))))) (_ - (user-error - "No compatible def before point. def: %s name: %s" - def name) (erk-jump-features))))) (defun erk--last-test ()