Skip to content

Commit bcce216

Browse files
authored
refactor: Report exit status globally (#368)
* feat: Report exit status globally * chore: Fix test files summary * test: Attempt to fix options * test: Avoid reporting error on incompat versions * test: split elisp lint * test: Take care of more exit status * fix: export * test: don't sync emacs version * test: Try semver-compare * test: fix syntax * test: fix param args * test: Remove old avoid11 var * test: Use cmd version comparison instead
1 parent b23841d commit bcce216

22 files changed

+164
-79
lines changed

lisp/_prepare.el

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,29 @@ This uses function `locate-dominating-file' to look up directory tree."
14321432
(ignore-errors (make-directory package-user-dir t))
14331433
(eask--silent (eask-setup-paths))
14341434
(eask-with-verbosity 'debug (eask--load-config))
1435-
(eask--with-hooks ,@body))))))))))
1435+
(eask--with-hooks ,@body))))))
1436+
;; Report exit stats if any.
1437+
(eask--handle-exit-status)))))
1438+
1439+
(defun eask--error-status ()
1440+
"Return error status."
1441+
(let ((result))
1442+
;; Error.
1443+
(when eask--has-error-p
1444+
(push 'error result))
1445+
;; Warning.
1446+
(when eask--has-warn-p
1447+
(push (if (eask-strict-p)
1448+
'error
1449+
'warn)
1450+
result))
1451+
;; No repeat.
1452+
(delete-dups result)))
1453+
1454+
(defun eask--handle-exit-status ()
1455+
"Return non-nil if we should report error for exit status."
1456+
(when (memq 'error (eask--error-status))
1457+
(eask--exit 'failure)))
14361458

14371459
;;
14381460
;;; Eask file
@@ -2000,7 +2022,7 @@ Argument ARGS are direct arguments for functions `eask-error' or `eask-warn'."
20002022
"On error.
20012023
20022024
Arguments FNC and ARGS are used for advice `:around'."
2003-
(setq eask--has-error-p t)
2025+
(setq eask--has-error-p t) ; Just a record.
20042026
(let ((msg (eask--ansi 'error (apply #'format-message args))))
20052027
(unless eask-inhibit-error-message
20062028
(eask--unsilent (eask-msg "%s" msg)))
@@ -2012,7 +2034,7 @@ Arguments FNC and ARGS are used for advice `:around'."
20122034
"On warn.
20132035
20142036
Arguments FNC and ARGS are used for advice `:around'."
2015-
(setq eask--has-warn-p t)
2037+
(setq eask--has-warn-p t) ; Just a record.
20162038
(let ((msg (eask--ansi 'warn (apply #'format-message args))))
20172039
(unless eask-inhibit-error-message
20182040
(eask--unsilent (eask-msg "%s" msg)))

lisp/lint/elint.el

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@
4444
(eask-print-log-buffer log-buffer)
4545
(kill-buffer log-buffer))))
4646

47-
(defun eask-lint-elint--has-error-p ()
48-
"Return non-nil if we should report error for exit status."
49-
(and eask--has-warn-p
50-
(eask-strict-p)))
51-
5247
(eask-start
5348
(require 'elint)
5449
(let* ((patterns (eask-args))
@@ -62,10 +57,7 @@
6257
(eask-msg "")
6358
(eask-info "(Total of %s file%s %s checked)" (length files)
6459
(eask--sinr files "" "s")
65-
(eask--sinr files "has" "have"))
66-
;; Report error.
67-
(when (eask-lint-elint--has-error-p)
68-
(eask--exit 'failure)))
60+
(eask--sinr files "has" "have")))
6961
;; Pattern defined, but no file found!
7062
(patterns
7163
(eask-info "(No files match wildcard: %s)"

lisp/lint/elsa.el

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@
6060
(t (eask-log line)))))
6161
(eask-msg "No issues found"))))
6262

63-
(defun eask-lint-elsa--has-error-p ()
64-
"Return non-nil if we should report error for exit status."
65-
(or eask--has-error-p
66-
(and eask--has-warn-p
67-
(eask-strict-p))))
68-
6963
(eask-start
7064
;; Preparation
7165
(eask-archive-install-packages '("gnu" "melpa")
@@ -85,10 +79,7 @@
8579
(mapcar #'eask-lint-elsa--analyse-file files)
8680
(eask-msg "")
8781
(eask-info "(Total of %s file%s linted)" (length files)
88-
(eask--sinr files "" "s"))
89-
;; Report error.
90-
(when (eask-lint-elsa--has-error-p)
91-
(eask--exit 'failure)))
82+
(eask--sinr files "" "s")))
9283
;; Pattern defined, but no file found!
9384
(patterns
9485
(eask-msg "")

lisp/lint/package.el

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@
5757
(kill-current-buffer)))
5858
(eask-print-log-buffer "*Package-Lint*"))
5959

60-
(defun eask-lint-package--has-error-p ()
61-
"Return non-nil if we should report error for exit status."
62-
(and eask--has-warn-p
63-
(eask-strict-p)))
64-
6560
(eask-start
6661
;; Preparation
6762
(eask-archive-install-packages '("gnu" "melpa")
@@ -82,10 +77,7 @@
8277
(mapcar #'eask-lint-package--file files)
8378
(eask-msg "")
8479
(eask-info "(Total of %s file%s linted)" (length files)
85-
(eask--sinr files "" "s"))
86-
;; Report error.
87-
(when (eask-lint-package--has-error-p)
88-
(eask--exit 'failure)))
80+
(eask--sinr files "" "s")))
8981
;; Pattern defined, but no file found!
9082
(patterns
9183
(eask-msg "")

lisp/lint/regexps.el

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@
6161
(eask-msg "No issues found"))
6262
(kill-current-buffer))))
6363

64-
(defun eask-lint-regexps--has-error-p ()
65-
"Return non-nil if we should report error for exit status."
66-
(and eask--has-warn-p
67-
(eask-strict-p)))
68-
6964
(eask-start
7065
;; Preparation
7166
(eask-archive-install-packages '("gnu")
@@ -85,10 +80,7 @@
8580
(mapcar #'eask-lint-regexps--relint-file files)
8681
(eask-msg "")
8782
(eask-info "(Total of %s file%s linted)" (length files)
88-
(eask--sinr files "" "s"))
89-
;; Report error.
90-
(when (eask-lint-regexps--has-error-p)
91-
(eask--exit 'failure)))
83+
(eask--sinr files "" "s")))
9284
;; Pattern defined, but no file found!
9385
(patterns
9486
(eask-msg "")

package-lock.json

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
},
3838
"devDependencies": {
3939
"@yao-pkg/pkg": "^6.0.0",
40-
"jest": "^29.7.0"
40+
"jest": "^29.7.0",
41+
"semver-compare": "^1.0.0"
4142
},
4243
"jest": {
4344
"rootDir": "./test/jest",

test/jest/exec.test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
const { TestContext } = require("./helpers");
1+
const cmp = require('semver-compare');
2+
const { emacsVersion, TestContext } = require("./helpers");
23

34
describe("exec", () => {
45
const ctx = new TestContext("./test/jest/exec");
56

6-
beforeAll(async () => await ctx.runEask("install-deps"));
7+
beforeAll(async () => {
8+
await ctx.runEask(
9+
"install-deps", { timeout: 40000 },
10+
// See https://github.com/emacs-eask/cli/issues/11.
11+
cmp(await emacsVersion(), "28.1") == -1);
12+
});
713

814
afterAll(() => ctx.cleanUp());
915

test/jest/helpers.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class TestContext {
157157
* @param {any} config
158158
* @returns {Promise.<CommandOutput>}
159159
*/
160-
runEask(command, config) {
161-
return this.run(this.easkCommand + " " + command, config);
160+
runEask(command, config, safe = false) {
161+
return this.run(this.easkCommand + " " + command, config, safe);
162162
}
163163

164164
/**
@@ -170,7 +170,7 @@ class TestContext {
170170
* @param {any} config
171171
* @returns {Promise.<CommandOutput>}
172172
*/
173-
run(command, config) {
173+
run(command, config, safe = false) {
174174
return exec(command, {
175175
cwd: this.cwd,
176176
signal: this.controller.signal,
@@ -188,7 +188,12 @@ class TestContext {
188188
return new CommandOutput(obj, this.cwd);
189189
})
190190
.catch((err) => {
191-
if (!err.code) err.message += "\nexec: TIMEOUT";
191+
if (safe)
192+
return this.errorToCommandOutput(err);
193+
194+
if (!err.code)
195+
err.message += "\nexec: TIMEOUT";
196+
192197
throw err;
193198
});
194199
}

test/jest/install.test.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const cmp = require('semver-compare');
12
const { emacsVersion, TestContext } = require("./helpers");
23

34
describe("install and uninstall", () => {
@@ -12,8 +13,12 @@ describe("install and uninstall", () => {
1213
afterAll(() => ctx.cleanUp());
1314

1415
it("installs project package", async () => {
15-
await ctx.runEask("package"); // creates dist/<pkg>.tar
16-
await ctx.runEask("install"); // installs dependencies and generated package
16+
// creates dist/<pkg>.tar
17+
await ctx.runEask("package", { timeout: 40000 },
18+
// See https://github.com/emacs-eask/cli/issues/11.
19+
cmp(await emacsVersion(), "28.1") == -1);
20+
// installs dependencies and generated package
21+
await ctx.runEask("install");
1722
const { stderr } = await ctx.runEask("list");
1823
expect(stderr).toMatch(packageName);
1924
});
@@ -36,13 +41,18 @@ describe("install and uninstall", () => {
3641
});
3742

3843
it("uninstalls project package", async () => {
39-
await ctx.runEask("uninstall");
44+
await ctx.runEask("uninstall", { timeout: 40000 },
45+
// See https://github.com/emacs-eask/cli/issues/11.
46+
cmp(await emacsVersion(), "28.1") == -1);
4047
const { stderr } = await ctx.runEask("list");
4148
expect(stderr).not.toMatch(packageName);
4249
});
4350

4451
it("installs dependencies", async () => {
45-
const { stderr } = await ctx.runEask("install-deps");
52+
const { stderr } = await ctx.runEask(
53+
"install-deps", { timeout: 40000 },
54+
// See https://github.com/emacs-eask/cli/issues/11.
55+
cmp(await emacsVersion(), "28.1") == -1);
4656
expect(stderr).not.toMatch(packageName);
4757
});
4858

@@ -97,7 +107,7 @@ describe("install and uninstall", () => {
97107
/* VC install */
98108

99109
test.skip("installs vc directly", async () => {
100-
if ((await emacsVersion()) >= "29.1") {
110+
if (cmp(await emacsVersion(), "29.1") == 1) {
101111
const { stderr } = await ctx.runEask(
102112
"install-vc https://github.com/jcs-elpa/msgu"
103113
);

0 commit comments

Comments
 (0)