Skip to content

Commit

Permalink
Fix: eask options should not be passed to buttercup (#281)
Browse files Browse the repository at this point in the history
* Add more tests for buttercup command

* Update 'test buttercup' to filter options

* Update 'test buttercup' command doco

* Add a comment about buttercup warning and check full paths too
  • Loading branch information
joshbax189 authored Nov 18, 2024
1 parent 46d38d6 commit 1da0201
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cmds/test/buttercup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

"use strict";

exports.command = ['buttercup [files..]'];
exports.command = ['buttercup [directories..]'];
exports.desc = 'Run buttercup tests';
exports.builder = yargs => yargs
.positional(
'[files..]', {
description: 'files you want buttercup to run on',
'[directories..]', {
description: 'directories containing buttercup tests, must be children of the current directory',
type: 'array',
});

exports.handler = async (argv) => {
await UTIL.e_call(argv, 'test/buttercup', argv.files);
await UTIL.e_call(argv, 'test/buttercup', argv.directories);
};
13 changes: 12 additions & 1 deletion lisp/test/buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@
;; Start Testing
(require 'buttercup)
;; Propose fix from https://github.com/jorgenschaefer/emacs-buttercup/pull/217
(let ((load-path (cons "." load-path)))
(let* ((load-path (cons "." load-path))
;; this does not include options
(args (eask-args)))
;; buttercup-run-discover uses command-line-args-left not command-line-args
(setq command-line-args-left args)
;; Seems like buttercup-run-discover only works on directories that are children of
;; the current directory.
;; When given a parent directory it always fails with "No suites found", even if there are tests.
;; Since this is a bit confusing, we warn the user specifically.
;; See discussion https://github.com/emacs-eask/cli/pull/281
(when-let ((bad-arg (seq-find (lambda (x) (not (file-in-directory-p x default-directory))) args)))
(error "Buttercup cannot run in parent directory: %s" bad-arg))
(buttercup-run-discover)))

;;; test/buttercup.el ends here
23 changes: 22 additions & 1 deletion test/commands/test/buttercup/run.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,25 @@ echo "Test command 'buttercup'..."
cd $(dirname "$0")

eask install-deps --dev
eask test buttercup
if eask test buttercup; then
# this runs all tests, so should error
echo "expected error"
exit 1
fi

# buttercup takes directories as arguments
eask test buttercup ./test-ok
if eask test buttercup ./test-ok ./test-fail; then
echo "expected error"
exit 1
fi

# buttercup does not take options
eask test buttercup --no-color ./test-ok

# Because load-path is manually set, cannot refer to parent directories.
# Note this does work if you do ../buttercup/test-ok/, but not for any other directory.
if eask test buttercup ../ert/ 2>&1 | grep 'No suites defined'; then
echo "expected error"
exit 1
fi
31 changes: 31 additions & 0 deletions test/commands/test/buttercup/test-fail/buttercup-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
;;; buttercup-test.el --- Test the command buttercup -*- lexical-binding: t; -*-

;; Copyright (C) 2022-2024 the Eask authors.

;; 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 <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Tests for the command buttercup

;;; Code:

(require 'buttercup)
(require 'debug)

(describe "A failing suite"
(it "contains a spec with a false expectation"
(expect t :to-be nil)))

;;; buttercup-test.el ends here

0 comments on commit 1da0201

Please sign in to comment.