Skip to content

Commit

Permalink
Add command ensure files
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Apr 14, 2024
1 parent 851c735 commit 9b9f1bc
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cmds/generate/test/buttercup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion cmds/generate/test/ecukes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
10 changes: 8 additions & 2 deletions cmds/generate/test/ert-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
10 changes: 8 additions & 2 deletions cmds/generate/test/ert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
12 changes: 6 additions & 6 deletions docs/content/Getting-Started/Commands-and-options/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,15 @@ 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

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
Expand Down Expand Up @@ -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 <name> <path>
## 🔍 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 <name> <path>
$ eask [GLOBAL-OPTIONS] link add <NAME> <PATH>
```

## 🔍 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,15 +503,15 @@ $ eask [GLOBAL-OPTIONS] generate ignore <name>
[ert][]測試建立一個新的測試項目。

```sh
$ eask [GLOBAL-OPTIONS] generate test ert
$ eask [GLOBAL-OPTIONS] generate test ert [NAMES..]
```

## 🔍 eask generate test ert-runner

[ert-runner][] 建立一個新的測試項目。

```sh
$ eask [GLOBAL-OPTIONS] generate test ert-runner
$ eask [GLOBAL-OPTIONS] generate test ert-runner [NAMES..]
```

## 🔍 eask generate test buttercup
Expand Down Expand Up @@ -579,22 +579,22 @@ $ eask [GLOBAL-OPTIONS] generate workflow travis-ci [--file]
此包與本地文件系統的依賴關係之間的鏈接。 鏈接的依賴項避免了從遠程存檔下載依賴項的需要。
鏈接到的包必須有一個 `Eask` 文件或一個 `-pkg.el` 文件。

## 🔍 eask link add <name> <path>
## 🔍 eask link add

將給定的 *source* 目錄鏈接到此項目的包目錄,在給定的 *package* 名稱下。

```sh
$ eask [GLOBAL-OPTIONS] link add <name> <path>
$ eask [GLOBAL-OPTIONS] link add <NAME> <PATH>
```

## 🔍 eask link delete [name..]
## 🔍 eask link delete

刪除給定包的鏈接。

別名: `remove`

```sh
$ eask [GLOBAL-OPTIONS] link delete [names..]
$ eask [GLOBAL-OPTIONS] link delete [NAMES..]
```

## 🔍 eask link list
Expand Down
4 changes: 2 additions & 2 deletions lisp/generate/test/buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down
24 changes: 22 additions & 2 deletions lisp/generate/test/ert-runner.el
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
47 changes: 31 additions & 16 deletions lisp/generate/test/ert.el
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

0 comments on commit 9b9f1bc

Please sign in to comment.