From 9b9f1bc799d9b644c595aa0493664c0f383c85ba Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sun, 14 Apr 2024 03:47:44 -0700 Subject: [PATCH] Add command ensure files --- cmds/generate/test/buttercup.js | 2 +- cmds/generate/test/ecukes.js | 2 +- cmds/generate/test/ert-runner.js | 10 +++- cmds/generate/test/ert.js | 10 +++- .../Commands-and-options/_index.en.md | 12 ++--- .../Commands-and-options/_index.zh-tw.md | 12 ++--- lisp/generate/test/buttercup.el | 4 +- lisp/generate/test/ert-runner.el | 24 +++++++++- lisp/generate/test/ert.el | 47 ++++++++++++------- 9 files changed, 85 insertions(+), 38 deletions(-) diff --git a/cmds/generate/test/buttercup.js b/cmds/generate/test/buttercup.js index 73b0ac5e..b9c29919 100644 --- a/cmds/generate/test/buttercup.js +++ b/cmds/generate/test/buttercup.js @@ -17,7 +17,7 @@ "use strict"; -exports.command = ['buttercup [file]']; +exports.command = ['buttercup']; exports.desc = 'Create a new Buttercup setup for the project'; exports.handler = async (argv) => { diff --git a/cmds/generate/test/ecukes.js b/cmds/generate/test/ecukes.js index 21645fda..2ef53bcd 100644 --- a/cmds/generate/test/ecukes.js +++ b/cmds/generate/test/ecukes.js @@ -17,7 +17,7 @@ "use strict"; -exports.command = ['ecukes [file]']; +exports.command = ['ecukes']; exports.desc = 'Create a new Ecukes setup for the project'; exports.handler = async (argv) => { diff --git a/cmds/generate/test/ert-runner.js b/cmds/generate/test/ert-runner.js index 239a3809..601abc74 100644 --- a/cmds/generate/test/ert-runner.js +++ b/cmds/generate/test/ert-runner.js @@ -17,9 +17,15 @@ "use strict"; -exports.command = ['ert-runner [file]']; +exports.command = ['ert-runner [names..]']; exports.desc = 'Create a new test project for the ert-runner'; +exports.builder = yargs => yargs + .positional( + '[names..]', { + description: 'specify test names', + type: 'array', + }); exports.handler = async (argv) => { - await UTIL.e_call(argv, 'generate/test/ert-runner', argv.file); + await UTIL.e_call(argv, 'generate/test/ert-runner', argv.names); }; diff --git a/cmds/generate/test/ert.js b/cmds/generate/test/ert.js index 253a39d3..7afb21d1 100644 --- a/cmds/generate/test/ert.js +++ b/cmds/generate/test/ert.js @@ -17,9 +17,15 @@ "use strict"; -exports.command = ['ert [file]']; +exports.command = ['ert [names..]']; exports.desc = 'Create a new test project for the ert tests'; +exports.builder = yargs => yargs + .positional( + '[names..]', { + description: 'specify test names', + type: 'array', + }); exports.handler = async (argv) => { - await UTIL.e_call(argv, 'generate/test/ert', argv.file); + await UTIL.e_call(argv, 'generate/test/ert', argv.names); }; diff --git a/docs/content/Getting-Started/Commands-and-options/_index.en.md b/docs/content/Getting-Started/Commands-and-options/_index.en.md index 1c246244..b922aab2 100644 --- a/docs/content/Getting-Started/Commands-and-options/_index.en.md +++ b/docs/content/Getting-Started/Commands-and-options/_index.en.md @@ -514,7 +514,7 @@ to generate ignore file. Create a new test project for the [ert][] tests. ```sh -$ eask [GLOBAL-OPTIONS] generate test ert +$ eask [GLOBAL-OPTIONS] generate test ert [NAMES..] ``` ## ๐Ÿ” eask generate test ert-runner @@ -522,7 +522,7 @@ $ eask [GLOBAL-OPTIONS] generate test ert Create a new test project for the [ert-runner][]. ```sh -$ eask [GLOBAL-OPTIONS] generate test ert-runner +$ eask [GLOBAL-OPTIONS] generate test ert-runner [NAMES..] ``` ## ๐Ÿ” eask generate test buttercup @@ -591,23 +591,23 @@ Link between this package and a dependency on the local filesystem. A linked dependency avoids the need to download a dependency from a remote archive. The package linked to must either have a `Eask`-file or a `-pkg.el`-file. -## ๐Ÿ” eask link add +## ๐Ÿ” eask link add Links the given *source* directory into the package directory of this project, under the given *package* name. ```sh -$ eask [GLOBAL-OPTIONS] link add +$ eask [GLOBAL-OPTIONS] link add ``` -## ๐Ÿ” eask link delete [name..] +## ๐Ÿ” eask link delete Deletes the link for the given packages. Alias: `remove` ```sh -$ eask [GLOBAL-OPTIONS] link delete [names..] +$ eask [GLOBAL-OPTIONS] link delete [NAMES..] ``` ## ๐Ÿ” eask link list diff --git a/docs/content/Getting-Started/Commands-and-options/_index.zh-tw.md b/docs/content/Getting-Started/Commands-and-options/_index.zh-tw.md index e81fa9b5..25ec3d56 100644 --- a/docs/content/Getting-Started/Commands-and-options/_index.zh-tw.md +++ b/docs/content/Getting-Started/Commands-and-options/_index.zh-tw.md @@ -503,7 +503,7 @@ $ eask [GLOBAL-OPTIONS] generate ignore ็‚บ [ert][]ๆธฌ่ฉฆๅปบ็ซ‹ไธ€ๅ€‹ๆ–ฐ็š„ๆธฌ่ฉฆ้ …็›ฎใ€‚ ```sh -$ eask [GLOBAL-OPTIONS] generate test ert +$ eask [GLOBAL-OPTIONS] generate test ert [NAMES..] ``` ## ๐Ÿ” eask generate test ert-runner @@ -511,7 +511,7 @@ $ eask [GLOBAL-OPTIONS] generate test ert ็‚บ [ert-runner][] ๅปบ็ซ‹ไธ€ๅ€‹ๆ–ฐ็š„ๆธฌ่ฉฆ้ …็›ฎใ€‚ ```sh -$ eask [GLOBAL-OPTIONS] generate test ert-runner +$ eask [GLOBAL-OPTIONS] generate test ert-runner [NAMES..] ``` ## ๐Ÿ” eask generate test buttercup @@ -579,22 +579,22 @@ $ eask [GLOBAL-OPTIONS] generate workflow travis-ci [--file] ๆญคๅŒ…่ˆ‡ๆœฌๅœฐๆ–‡ไปถ็ณป็ตฑ็š„ไพ่ณด้—œไฟ‚ไน‹้–“็š„้ˆๆŽฅใ€‚ ้ˆๆŽฅ็š„ไพ่ณด้ …้ฟๅ…ไบ†ๅพž้ ็จ‹ๅญ˜ๆช”ไธ‹่ผ‰ไพ่ณด้ …็š„้œ€่ฆใ€‚ ้ˆๆŽฅๅˆฐ็š„ๅŒ…ๅฟ…้ ˆๆœ‰ไธ€ๅ€‹ `Eask` ๆ–‡ไปถๆˆ–ไธ€ๅ€‹ `-pkg.el` ๆ–‡ไปถใ€‚ -## ๐Ÿ” eask link add +## ๐Ÿ” eask link add ๅฐ‡็ตฆๅฎš็š„ *source* ็›ฎ้Œ„้ˆๆŽฅๅˆฐๆญค้ …็›ฎ็š„ๅŒ…็›ฎ้Œ„๏ผŒๅœจ็ตฆๅฎš็š„ *package* ๅ็จฑไธ‹ใ€‚ ```sh -$ eask [GLOBAL-OPTIONS] link add +$ eask [GLOBAL-OPTIONS] link add ``` -## ๐Ÿ” eask link delete [name..] +## ๐Ÿ” eask link delete ๅˆช้™ค็ตฆๅฎšๅŒ…็š„้ˆๆŽฅใ€‚ ๅˆฅๅ: `remove` ```sh -$ eask [GLOBAL-OPTIONS] link delete [names..] +$ eask [GLOBAL-OPTIONS] link delete [NAMES..] ``` ## ๐Ÿ” eask link list diff --git a/lisp/generate/test/buttercup.el b/lisp/generate/test/buttercup.el index f9722903..6ef83ca1 100644 --- a/lisp/generate/test/buttercup.el +++ b/lisp/generate/test/buttercup.el @@ -15,11 +15,11 @@ nil t)) (defun eask-generate-test-buttercup--init (&optional name) - "Create new test project (optional project name)." + "Create new test buffercup project (optional project NAME)." (let ((name (or name (f-filename default-directory))) (test-path (expand-file-name "tests" default-directory))) (when (f-dir? test-path) - (error "%s" (ansi-red "Directory `tests` already exists."))) + (eask-error "Directory `tests` already exists.")) (message "create %s" (ansi-green (f-filename test-path))) (f-mkdir "tests") (let ((test-file (s-concat "test-" name ".el"))) diff --git a/lisp/generate/test/ert-runner.el b/lisp/generate/test/ert-runner.el index 77d860ba..645447da 100644 --- a/lisp/generate/test/ert-runner.el +++ b/lisp/generate/test/ert-runner.el @@ -4,7 +4,12 @@ ;; ;; Command use to create a new test project for the ert-runner, ;; -;; $ eask generate test ert-runner +;; $ eask generate test ert-runner [names..] +;; +;; +;; Positionals: +;; +;; [names..] specify test names ;; ;;; Code: @@ -14,11 +19,26 @@ (locate-dominating-file dir "_prepare.el")) nil t)) +(eask-load "generate/test/ert") + +(defun eask-generate-test-ert-runner--test-helper (&optional name) + "Generate test helper for NAME." + (with-temp-file (f-join ert-runner-test-path "test-helper.el") + (insert (format "\ +;;; test-helper.el --- Helpers for %s + +;;; test-helper.el ends here +" name)))) + (eask-start (eask-with-archives '("gnu" "melpa") (eask-package-install 'ert-runner)) (advice-add 'ert-runner/run :override #'ignore) (load-library "ert-runner") - (ert-runner/init (eask-guess-package-name))) + (load-library "f") + (let ((name (eask-guess-package-name))) + (eask-generate-test-ert--init name) + (eask-generate-test-ert-runner--test-helper name)) + (mapc #'eask-generate-test-ert--create-test-file (eask-args))) ;;; generate/test/ert-runner.el ends here diff --git a/lisp/generate/test/ert.el b/lisp/generate/test/ert.el index 3611d3a7..c1cab37b 100644 --- a/lisp/generate/test/ert.el +++ b/lisp/generate/test/ert.el @@ -4,7 +4,12 @@ ;; ;; Command use to create a new test project for the ert tests, ;; -;; $ eask generate test ert +;; $ eask generate test ert [names..] +;; +;; +;; Positionals: +;; +;; [names..] specify test names ;; ;;; Code: @@ -14,27 +19,37 @@ (locate-dominating-file dir "_prepare.el")) nil t)) +(defvar eask-generate-test-ert-test-path + (expand-file-name "test" default-directory) + "The default test path.") + (defun eask-generate-test-ert--init (&optional name) - "Create new test project (optional project name)." - (let ((name (or name (f-filename default-directory))) - (test-path (expand-file-name "test" default-directory))) - (when (f-dir? "test") - (error "%s" (ansi-red "Directory `test` already exists."))) - (message "create %s" (ansi-green (f-filename test-path))) - (f-mkdir test-path) - (let ((test-file (s-concat name "-test.el"))) - (message "create %s" (ansi-green (s-concat name "-test.el"))) - (with-temp-file (f-join test-path test-file) + "Create new test project (optional project NAME)." + (let* ((name (or name (file-name-nondirectory default-directory))) + (dir (file-directory-p eask-generate-test-ert-test-path))) + (eask-with-progress + (format "create %s folder... " (ansi-green "test")) + (ignore-errors (make-directory eask-generate-test-ert-test-path t)) + (if dir "skipped โœ—" "done โœ“")) + (eask-generate-test-ert--create-test-file name))) + +(defun eask-generate-test-ert--create-test-file (name) + "Generate test file by NAME." + (let* ((test-file (concat name "-test.el")) + (full-test-file (expand-file-name test-file eask-generate-test-ert-test-path)) + (ext (file-exists-p full-test-file))) + (eask-with-progress + (format " create %s... " (ansi-green test-file)) + (with-temp-file full-test-file (insert (format "\ ;;; %s --- Tests for %s ;;; %s ends here -" test-file name test-file)))))) +" test-file name test-file))) + (if ext "skipped โœ—" "done โœ“")))) (eask-start - (eask-with-archives '("gnu" "melpa") - (eask-package-install 'f)) - (require 'f) - (eask-generate-test-ert--init (eask-guess-package-name))) + (eask-generate-test-ert--init (eask-guess-package-name)) + (mapc #'eask-generate-test-ert--create-test-file (eask-args))) ;;; generate/test/ert.el ends here