Skip to content

Commit 1da0201

Browse files
authored
Fix: eask options should not be passed to buttercup (#281)
* 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
1 parent 46d38d6 commit 1da0201

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

cmds/test/buttercup.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717

1818
"use strict";
1919

20-
exports.command = ['buttercup [files..]'];
20+
exports.command = ['buttercup [directories..]'];
2121
exports.desc = 'Run buttercup tests';
2222
exports.builder = yargs => yargs
2323
.positional(
24-
'[files..]', {
25-
description: 'files you want buttercup to run on',
24+
'[directories..]', {
25+
description: 'directories containing buttercup tests, must be children of the current directory',
2626
type: 'array',
2727
});
2828

2929
exports.handler = async (argv) => {
30-
await UTIL.e_call(argv, 'test/buttercup', argv.files);
30+
await UTIL.e_call(argv, 'test/buttercup', argv.directories);
3131
};

lisp/test/buttercup.el

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,18 @@
2222
;; Start Testing
2323
(require 'buttercup)
2424
;; Propose fix from https://github.com/jorgenschaefer/emacs-buttercup/pull/217
25-
(let ((load-path (cons "." load-path)))
25+
(let* ((load-path (cons "." load-path))
26+
;; this does not include options
27+
(args (eask-args)))
28+
;; buttercup-run-discover uses command-line-args-left not command-line-args
29+
(setq command-line-args-left args)
30+
;; Seems like buttercup-run-discover only works on directories that are children of
31+
;; the current directory.
32+
;; When given a parent directory it always fails with "No suites found", even if there are tests.
33+
;; Since this is a bit confusing, we warn the user specifically.
34+
;; See discussion https://github.com/emacs-eask/cli/pull/281
35+
(when-let ((bad-arg (seq-find (lambda (x) (not (file-in-directory-p x default-directory))) args)))
36+
(error "Buttercup cannot run in parent directory: %s" bad-arg))
2637
(buttercup-run-discover)))
2738

2839
;;; test/buttercup.el ends here

test/commands/test/buttercup/run.sh

100644100755
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,25 @@ echo "Test command 'buttercup'..."
2626
cd $(dirname "$0")
2727

2828
eask install-deps --dev
29-
eask test buttercup
29+
if eask test buttercup; then
30+
# this runs all tests, so should error
31+
echo "expected error"
32+
exit 1
33+
fi
34+
35+
# buttercup takes directories as arguments
36+
eask test buttercup ./test-ok
37+
if eask test buttercup ./test-ok ./test-fail; then
38+
echo "expected error"
39+
exit 1
40+
fi
41+
42+
# buttercup does not take options
43+
eask test buttercup --no-color ./test-ok
44+
45+
# Because load-path is manually set, cannot refer to parent directories.
46+
# Note this does work if you do ../buttercup/test-ok/, but not for any other directory.
47+
if eask test buttercup ../ert/ 2>&1 | grep 'No suites defined'; then
48+
echo "expected error"
49+
exit 1
50+
fi
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
;;; buttercup-test.el --- Test the command buttercup -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2022-2024 the Eask authors.
4+
5+
;; This program is free software; you can redistribute it and/or modify
6+
;; it under the terms of the GNU General Public License as published by
7+
;; the Free Software Foundation, either version 3 of the License, or
8+
;; (at your option) any later version.
9+
10+
;; This program is distributed in the hope that it will be useful,
11+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
;; GNU General Public License for more details.
14+
15+
;; You should have received a copy of the GNU General Public License
16+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
18+
;;; Commentary:
19+
20+
;; Tests for the command buttercup
21+
22+
;;; Code:
23+
24+
(require 'buttercup)
25+
(require 'debug)
26+
27+
(describe "A failing suite"
28+
(it "contains a spec with a false expectation"
29+
(expect t :to-be nil)))
30+
31+
;;; buttercup-test.el ends here

0 commit comments

Comments
 (0)