diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 69bbfd9..ffc79e2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,8 +31,8 @@ jobs: - name: Run tests if: matrix.allow_failure != true - run: './run-tests.sh' + run: 'make check' - name: Run tests (allow failure) if: matrix.allow_failure == true - run: './run-tests.sh || true' + run: 'make check || true' diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4829be3 --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +# Makefile for Dash. + +# Copyright (C) 2021 Free Software Foundation, Inc. +# +# 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 . + +# Variables. + +EMACS ?= emacs +BATCH := $(EMACS) -Q -batch -L . +ELS := dash.el dash-functional.el +ELCS := $(addsuffix c,$(ELS)) + +# Targets. + +lisp: $(ELCS) +.PHONY: lisp + +docs: README.md dash.texi +.PHONY: docs + +# ERT_SELECTOR is a Lisp expression determining which tests to run. +# Its format is described in (info "(ert) Test Selectors"). It +# defaults to selecting all tests. Note that in batch mode, a nil +# selector is the same as t. +check: ERT_SELECTOR ?= t +check: lisp + $(BATCH) -l dev/examples-to-tests.el -l dev/examples.el \ + -eval '(ert-run-tests-batch-and-exit (quote $(ERT_SELECTOR)))' +.PHONY: check + +all: lisp docs check +.PHONY: all + +clean: + $(RM) $(ELCS) +.PHONY: clean + +# Files. + +%.elc: %.el + $(BATCH) -eval '(setq byte-compile-error-on-warn t)' \ + -f batch-byte-compile $< + +dash-functional.elc: dash.elc + +README.md: $(ELS) dev/examples-to-docs.el dev/examples.el readme-template.md + $(BATCH) $(addprefix -l ,$(filter %.el,$^)) -f create-docs-file + +dash.texi: $(ELS) dev/examples-to-info.el dev/examples.el dash-template.texi + $(BATCH) $(addprefix -l ,$(filter %.el,$^)) -f create-info-file diff --git a/README.md b/README.md index 5b3ee0e..2c8411b 100644 --- a/README.md +++ b/README.md @@ -2932,11 +2932,11 @@ You'll find the repo at: Run the tests with: - ./run-tests.sh + make check Regenerate the docs with: - ./create-docs.sh + make docs I highly recommend that you install these as a pre-commit hook, so that the tests are always running and the docs are always in sync: diff --git a/create-docs.sh b/create-docs.sh deleted file mode 100755 index 0d1cedd..0000000 --- a/create-docs.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env sh - -if [ -z "${EMACS}" ]; then - EMACS=emacs -fi - -"${EMACS}" -Q -batch -l dash.el -l dash-functional.el \ - -l dev/examples-to-docs.el -l dev/examples.el -f create-docs-file -"${EMACS}" -Q -batch -l dash.el -l dash-functional.el \ - -l dev/examples-to-info.el -l dev/examples.el -f create-info-file diff --git a/dash-template.texi b/dash-template.texi index f77d20f..72cc77c 100644 --- a/dash-template.texi +++ b/dash-template.texi @@ -212,8 +212,8 @@ please. There's a suite of examples/tests in @file{dev/examples.el}, so remember to add tests for your additions, or they may get broken later. -Run the tests with @samp{./run-tests.sh}. Regenerate the docs with -@samp{./create-docs.sh}. Contributors are encouraged to install these +Run the tests with @samp{make check}. Regenerate the docs with +@samp{make docs}. Contributors are encouraged to install these commands as a Git pre-commit hook, so that the tests are always running and the docs are always in sync: diff --git a/dash.texi b/dash.texi index 65e8061..6da2309 100644 --- a/dash.texi +++ b/dash.texi @@ -4474,8 +4474,8 @@ please. There's a suite of examples/tests in @file{dev/examples.el}, so remember to add tests for your additions, or they may get broken later. -Run the tests with @samp{./run-tests.sh}. Regenerate the docs with -@samp{./create-docs.sh}. Contributors are encouraged to install these +Run the tests with @samp{make check}. Regenerate the docs with +@samp{make docs}. Contributors are encouraged to install these commands as a Git pre-commit hook, so that the tests are always running and the docs are always in sync: diff --git a/dev/examples.el b/dev/examples.el index c60601c..a508b32 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -28,6 +28,12 @@ (unless (fboundp 'def-example-group) (require 'examples-to-tests "dev/examples-to-tests"))) +;; TODO: `setf' was introduced in Emacs 24.3, so remove this when +;; support for earlier versions is dropped. +(eval-when-compile + (unless (fboundp 'setf) + (require 'cl))) + ;; FIXME: These definitions ought to be exported along with the ;; examples, if they are going to be used there. (defun odd? (num) (= 1 (% num 2))) diff --git a/pre-commit.sh b/pre-commit.sh index af91826..713472b 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -1,9 +1,9 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh git stash -q --keep-index -./run-tests.sh +make check RESULT=$? -[ $RESULT == 0 ] && ./create-docs.sh && git add ./README.md +[ $RESULT -eq 0 ] && make docs && git add ./README.md git stash pop -q [ $RESULT -ne 0 ] && exit 1 exit 0 diff --git a/readme-template.md b/readme-template.md index dc61218..875f5f0 100644 --- a/readme-template.md +++ b/readme-template.md @@ -104,11 +104,11 @@ You'll find the repo at: Run the tests with: - ./run-tests.sh + make check Regenerate the docs with: - ./create-docs.sh + make docs I highly recommend that you install these as a pre-commit hook, so that the tests are always running and the docs are always in sync: diff --git a/run-tests.sh b/run-tests.sh deleted file mode 100755 index 41a187f..0000000 --- a/run-tests.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -set -e - -if [ -z "$EMACS" ] ; then - EMACS="emacs" -fi - -# Run all tests by default. -# To only run certain tests, set $ERT_SELECTOR as required. -# For example, to skip the test "-fixfn", run the following command: -# -# ERT_SELECTOR='(not "-fixfn")' ./run-tests.sh -# -if [ -z "$ERT_SELECTOR" ] ; then - ERT_SELECTOR="nil" -fi - -$EMACS -Q -batch \ - -l dash.el \ - -l dash-functional.el \ - -l dev/examples-to-tests.el \ - -l dev/examples.el \ - -eval "(ert-run-tests-batch-and-exit (quote ${ERT_SELECTOR}))" - -$EMACS -Q -batch \ - -eval '(setq byte-compile-error-on-warn t)' \ - -f batch-byte-compile dash.el