From 2943907396731d98213e6d8ef59da5eac85b6c64 Mon Sep 17 00:00:00 2001 From: Walheimat Date: Sat, 22 Jul 2023 17:11:32 +0200 Subject: [PATCH] refac: bydi-ci for path setup --- CHANGELOG.md | 1 + Cask | 2 +- bydi-ci.el | 42 ++++++++++++++++++++++++++++++++++++++++++ bydi.el | 29 +++++------------------------ test/bydi-ci-test.el | 25 +++++++++++++++++++++++++ test/bydi-test.el | 9 +++------ test/test-helper.el | 2 +- 7 files changed, 78 insertions(+), 32 deletions(-) create mode 100644 bydi-ci.el create mode 100644 test/bydi-ci-test.el diff --git a/CHANGELOG.md b/CHANGELOG.md index b31c8de..1105cea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 package `bydi-report`. - `bydi-calculate-coverage` has been deprecated. Printing the report and the average is now done automatically for text coverage. +- `bydi-path-setup` was made obsolete by `bydi-ci-setup-paths`. ## [v0.2.0] diff --git a/Cask b/Cask index f3687ce..a6779ab 100644 --- a/Cask +++ b/Cask @@ -11,4 +11,4 @@ (package-file "bydi.el") -(files "bydi.el" "bydi-report.el") \ No newline at end of file +(files "bydi.el" "bydi-report.el" "bydi-ci.el") \ No newline at end of file diff --git a/bydi-ci.el b/bydi-ci.el new file mode 100644 index 0000000..7fd8432 --- /dev/null +++ b/bydi-ci.el @@ -0,0 +1,42 @@ +;;; bydi-ci.el --- CI helpers -*- lexical-binding: t; -*- + +;; Author: Krister Schuchardt +;; Homepage: https://github.com/Walheimat/bydi +;; Version: 0.2.0 +;; Package-Requires: ((emacs "28.1")) +;; Keywords: extensions + +;;; Commentary: +;; +;; Utility to integrate with CI. + +;;; Code: + +(defvar bydi-setup--env-github-workspace "GITHUB_WORKSPACE" + "Location of the project in GitHub action.") + +(defun bydi-ci--setup-paths (paths) + "Set up `load-path'. + +Optionally, set up additional relative PATHS. + +This function returns a list of the directories added to the +`load-path'." + (let* ((source-dir (expand-file-name (or (getenv bydi-setup--env-github-workspace) + default-directory))) + (paths (append (list source-dir) (mapcar (lambda (it) (expand-file-name it source-dir)) paths)))) + + (message "Adding %s to `load-path'" paths) + + (dolist (it paths) + (add-to-list 'load-path it)) + + paths)) + +(defun bydi-ci-setup-paths (paths) + "Add PATHS to load path in a CI-aware way." + (bydi-ci--setup-paths paths)) + +(provide 'bydi-ci) + +;;; bydi-ci.el ends here diff --git a/bydi.el b/bydi.el index cd73333..ce3e05c 100644 --- a/bydi.el +++ b/bydi.el @@ -18,6 +18,8 @@ (require 'cl-lib) (require 'compat nil t) +(require 'bydi-ci nil t) + ;;; -- Variables (defvar bydi--temp-files nil) @@ -29,9 +31,6 @@ (defvar bydi-spy--advice-name 'bydi-spi) (defvar bydi-mock-sometimes nil) -(defvar bydi-setup--env-github-workspace "GITHUB_WORKSPACE" - "Location of the project in GitHub action.") - ;;; -- Macros (defmacro bydi-with-mock (to-mock &rest body) @@ -314,26 +313,6 @@ Optionally, return RETURN." (push (match-string 1) matches))) matches)) -;;; -- Setup helpers - -(defun bydi-setup--paths (paths) - "Set up `load-path'. - -Optionally, set up additional relative PATHS. - -This function returns a list of the directories added to the -`load-path'." - (let* ((source-dir (expand-file-name (or (getenv bydi-setup--env-github-workspace) - default-directory))) - (paths (append (list source-dir) (mapcar (lambda (it) (expand-file-name it source-dir)) paths)))) - - (message "Adding %s to `load-path'" paths) - - (dolist (it paths) - (add-to-list 'load-path it)) - - paths)) - ;;; -- API ;;;###autoload @@ -362,7 +341,9 @@ Optionally, set up additional relative PATHS. This function returns a list of the directories added to the `load-path'." - (bydi-setup--paths paths)) + (declare-function bydi-ci-setup-paths "bydi.el") + (bydi-ci-setup-paths paths)) +(make-obsolete 'bydi-path-setup 'bydi-ci-setup-paths "0.3.0") (provide 'bydi) diff --git a/test/bydi-ci-test.el b/test/bydi-ci-test.el new file mode 100644 index 0000000..0d08176 --- /dev/null +++ b/test/bydi-ci-test.el @@ -0,0 +1,25 @@ +;;; bydi-ci-test.el --- Tests for custom functionality. -*- lexical-binding: t; -*- + +;;; Commentary: +;; +;; Tests for the custom functionality. + +;;; Code: + +(require 'bydi-ci nil t) + +(ert-deftest bydi-ci-setup-paths () + (let ((load-path nil) + (default-directory "/tmp")) + + (bydi ((:ignore getenv)) + + (bydi-ci-setup-paths (list "test" "mock")) + + (should (equal load-path '("/tmp/mock" "/tmp/test" "/tmp")))))) + +;;; bydi-ci-test.el ends here + +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/test/bydi-test.el b/test/bydi-test.el index 2e70e46..87545f5 100644 --- a/test/bydi-test.el +++ b/test/bydi-test.el @@ -287,14 +287,11 @@ (delete-file "/tmp/test")))))) (ert-deftest bydi-path-setup () - (let ((load-path nil) - (default-directory "/tmp")) + (bydi (bydi-ci--setup-paths) - (bydi ((:ignore getenv)) + (bydi-path-setup (list "test" "mock")) - (bydi-path-setup (list "test" "mock")) - - (should (equal load-path '("/tmp/mock" "/tmp/test" "/tmp")))))) + (bydi-was-called bydi-ci--setup-paths))) (ert-deftest bydi--matches-in-string () (let ((str "This 1 string has 3 matches, or is it 2?") diff --git a/test/test-helper.el b/test/test-helper.el index d5435bc..f399ce5 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -28,7 +28,7 @@ report-file "./coverage/.resultset.json"))) (undercover--setup - (append (list "bydi.el" "bydi-report.el") + (append (list "bydi.el" "bydi-report.el" "bydi-ci.el") (list (list :report-format report-format) (list :report-file report-file)