Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
raxod502 committed Mar 10, 2024
1 parent 8c970d9 commit 60cd641
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
env:
VERSION: ${{ matrix.emacs_version }}
run: >-
make docker CMD="make lint lint-changelog"
make docker CMD="make unit-test lint lint-changelog"
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,26 @@ fmt-build-common: ## Build a Docker image with just the common base
fmt-docker: ## Start a Docker shell for testing formatters
@scripts/docker-run.bash -e FORMATTERS "apheleia-formatters:$(TAG)" "$(CMD)"

APHELEIA_FT := -L test/formatters -l apheleia-ft

.PHONY: fmt-lint
fmt-lint: ## Do basic linting for formatter configuration
@test/formatters/run-func.bash apheleia-ft-lint
@test/shared/run-func.bash apheleia-ft-lint $(APHELEIA_FT)

.PHONY: fmt-check
fmt-changed: ## Get list of changed formatters on this PR
@test/formatters/run-func.bash apheleia-ft-changed
@test/shared/run-func.bash apheleia-ft-changed $(APHELEIA_FT)

.PHONY: fmt-test # env var: FORMATTERS
fmt-test: ## Actually run formatter tests
@test/formatters/run-func.bash apheleia-ft-test
@test/shared/run-func.bash apheleia-ft-test $(APHELEIA_FT)

.PHONY: lint-changelog
lint-changelog: ## Report an error if the changelog wasn't updated
@scripts/lint-changelog.bash

APHELEIA_UNIT := -L test/unit -l apheleia-unit

.PHONY: unit-test
unit-test: ## Run unit tests
@test/shared/run-func.bash ert-run-tests-batch-and-exit $(APHELEIA_UNIT)
10 changes: 6 additions & 4 deletions test/formatters/run-func.bash → test/shared/run-func.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

set -euo pipefail

func="$1"
shift

# Avoid using git to get project directory, due to
# https://github.com/radian-software/apheleia/pull/89#issuecomment-1107319617

cd "$(dirname "$0")"
repo="$(cd ../.. && pwd)"
cd "$(dirname "$0")/../.."

exec emacs --batch -L "${repo}" -L . -l apheleia-ft \
--eval "(setq debug-on-error t)" -f "$1"
exec emacs --batch -L . "$@" \
--eval "(setq debug-on-error t)" -f "${func}"
17 changes: 17 additions & 0 deletions test/unit/apheleia-unit.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
;; -*- lexical-binding: t -*-

;; `apheleia-unit' - unit tests using ERT.

(require 'apheleia)

(require 'ert)

(ert-deftest apheleia-align-point ()
;; https://github.com/radian-software/apheleia/pull/290
(should
(equal
(apheleia--align-point
" <div class=\"left-[40rem] fixed inset-y-0 right-0 z-0 hidden lg:block xl:left-[50rem]\">\n <svg\n"
"<div class=\"left-[40rem] fixed inset-y-0 right-0 z-0 hidden lg:block xl:left-[50rem]\">\n <svg"
6)
1)))

0 comments on commit 60cd641

Please sign in to comment.