Skip to content

Commit

Permalink
refac: bydi-ci for path setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Walheimat committed Jul 22, 2023
1 parent 7ee9851 commit 2943907
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion Cask
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

(package-file "bydi.el")

(files "bydi.el" "bydi-report.el")
(files "bydi.el" "bydi-report.el" "bydi-ci.el")
42 changes: 42 additions & 0 deletions bydi-ci.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;;; bydi-ci.el --- CI helpers -*- lexical-binding: t; -*-

;; Author: Krister Schuchardt <[email protected]>
;; 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
29 changes: 5 additions & 24 deletions bydi.el
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
(require 'cl-lib)
(require 'compat nil t)

(require 'bydi-ci nil t)

;;; -- Variables

(defvar bydi--temp-files nil)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
25 changes: 25 additions & 0 deletions test/bydi-ci-test.el
Original file line number Diff line number Diff line change
@@ -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:
9 changes: 3 additions & 6 deletions test/bydi-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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?")
Expand Down
2 changes: 1 addition & 1 deletion test/test-helper.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2943907

Please sign in to comment.