Skip to content

Commit

Permalink
Closes #12: Create unit tests for Easysession using GitHub Actions an…
Browse files Browse the repository at this point in the history
…d Cask

This commit also renames easysession-set-current-session to
easysession--set-current-session.
  • Loading branch information
jamescherti committed Aug 14, 2024
1 parent 436f860 commit 7bf893a
Show file tree
Hide file tree
Showing 6 changed files with 394 additions and 33 deletions.
97 changes: 69 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,77 @@
# This is a basic workflow to help you get started with Actions
---
#
# Copyright (C) 2024 James Cherti
# URL: https://github.com/jamescherti/easysession.el
#
# This file 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 2, or (at your option)
# any later version.
#
# This file 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
#

name: CI
on: [push, pull_request]

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
test:
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
strategy:
matrix:
emacs-version:
- 26.3
- 27.1
- 28.2
- 29.1
- 29.4
python-version:
- 3.11
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs-version }}
- uses: actions/cache@v2
id: cache-cask-packages
with:
path: .cask
key: cache-cask-packages-000
- uses: actions/cache@v2
id: cache-cask-executable
with:
path: ~/.cask
key: cache-cask-executable-000
- uses: cask/setup-cask@master
if: steps.cache-cask-executable.outputs.cache-hit != 'true'
with:
version: snapshot
- run: echo "$HOME/.cask/bin" >> $GITHUB_PATH

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run a multi-line script
- name: Install
run: |
echo Add other actions to build,
echo test, and deploy your project.
python -m pip install --upgrade pip
sudo apt-get install emacs && emacs --version
git clone https://github.com/riscy/melpazoid.git ~/melpazoid
pip install ~/melpazoid
- name: Run melpazoid
env:
RECIPE: (easysession :repo "jamescherti/easysession.el" :branch "${{ github.ref_name }}" :fetcher github :files ("*.el"))
EXIST_OK: false
run: echo $GITHUB_REF && make -C ~/melpazoid

- name: Run tests
run: make test
env:
CASK_PATH: $HOME/.cask/bin
4 changes: 4 additions & 0 deletions Cask
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(source gnu)
(source melpa)

(package-file "easysession.el")
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Copyright (C) 2024 James Cherti
# URL: https://github.com/jamescherti/easysession.el
#
# This file 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 2, or (at your option)
# any later version.
#
# This file 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
#

export EMACS ?= $(shell command -v emacs 2>/dev/null)
CASK_DIR := $(shell cask package-directory)

$(CASK_DIR): Cask
cask install
@touch $(CASK_DIR)

.PHONY: cask
cask: $(CASK_DIR)

.PHONY: compile
compile: cask
cask emacs -batch -L . -L test \
--eval "(setq byte-compile-error-on-warn t)" \
-f batch-byte-compile $$(cask files); \
(ret=$$? ; cask clean-elc && exit $$ret)

.PHONY: test
test: compile
cask emacs --batch -L . -L tests -l tests/test-easysession.el -f test-easysession
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# easysession.el - Easily persist and restore your Emacs editing sessions
[![MELPA](https://melpa.org/packages/easysession-badge.svg)](https://melpa.org/#/easysession)
![](https://raw.githubusercontent.com/jamescherti/easysession.el/main/.images/made-for-gnu-emacs.svg)
![Build Status](https://github.com/jamescherti/easysession.el/actions/workflows/ci.yml/badge.svg)
![License](https://img.shields.io/github/license/jamescherti/easysession.el)

The `easysession.el` Emacs package is a lightweight session manager for Emacs that can persist and restore file editing buffers, indirect buffers/clones, Dired buffers, windows/splits, the built-in tab-bar (including tabs, their buffers, and windows), and Emacs frames. It offers a convenient and effortless way to manage Emacs editing sessions and utilizes built-in Emacs functions to persist and restore frames.
Expand Down
11 changes: 6 additions & 5 deletions easysession.el
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ Raise an error if the session name is invalid."
(error "[easysession] Invalid session name: %s" session-name))
session-name)

(defun easysession-set-current-session (&optional session-name)
(defun easysession--set-current-session (&optional session-name)
"Set the current session to SESSION-NAME.
Return t if the session name is successfully set."
(easysession--ensure-session-name-valid session-name)
Expand Down Expand Up @@ -716,8 +716,9 @@ SESSION-NAME is the name of the session."
'utf-8 session-file)
t)))
(if fwrite-success
(when (called-interactively-p 'any)
(easysession--message "Session saved: %s" session-name)
(progn
(when (called-interactively-p 'any)
(easysession--message "Session saved: %s" session-name))
(run-hooks 'easysession-after-save-hook))
(error "[easysession] %s: failed to save the session to %s"
session-name session-file)))
Expand Down Expand Up @@ -798,7 +799,7 @@ If the function is called interactively, ask the user."
(previous-session-name easysession--current-session-name))
(easysession--ensure-session-name-valid new-session-name)
(easysession-save new-session-name)
(easysession-set-current-session new-session-name)
(easysession--set-current-session new-session-name)
(if (string= previous-session-name easysession--current-session-name)
(easysession--message "Saved the session: %s" new-session-name)
(easysession--message "Saved and switched to session: %s"
Expand Down Expand Up @@ -841,7 +842,7 @@ initialized."
(easysession-load session-name)

(unless session-reloaded
(easysession-set-current-session session-name)
(easysession--set-current-session session-name)
(unless (file-exists-p session-file)
(run-hooks 'easysession-new-session-hook)
(easysession-save)
Expand Down
Loading

0 comments on commit 7bf893a

Please sign in to comment.