Skip to content

Commit

Permalink
feat(generate/test): Add command to setup test files
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Apr 14, 2024
1 parent 6682817 commit 429f005
Show file tree
Hide file tree
Showing 13 changed files with 369 additions and 19 deletions.
38 changes: 38 additions & 0 deletions cmds/generate/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (C) 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, 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/>.
*/

"use strict";

exports.command = ['test <type>'];
exports.desc = 'Generate test files based on the testing framework';
exports.builder = function (yargs) {
yargs.usage(`${exports.desc}
Usage: eask generate test <type> [options..]`)
.commandDir('./test/')
.demandCommand();

/* XXX: Configure only in the menu. */
if (UTIL.cmd_count() == 2) {
yargs.positional(
'<type>', {
description: 'type of the testing framework',
});
}
}

exports.handler = async (argv) => { };
25 changes: 25 additions & 0 deletions cmds/generate/test/buttercup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (C) 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, 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/>.
*/

"use strict";

exports.command = ['buttercup [file]'];
exports.desc = 'Create a new Buttercup setup for the project';

exports.handler = async (argv) => {
await UTIL.e_call(argv, 'generate/test/buttercup', argv.file);
};
25 changes: 25 additions & 0 deletions cmds/generate/test/ecukes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (C) 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, 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/>.
*/

"use strict";

exports.command = ['ecukes [file]'];
exports.desc = 'Create a new Ecukes setup for the project';

exports.handler = async (argv) => {
await UTIL.e_call(argv, 'generate/test/ecukes', argv.file);
};
25 changes: 25 additions & 0 deletions cmds/generate/test/ert-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (C) 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, 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/>.
*/

"use strict";

exports.command = ['ert-runner [file]'];
exports.desc = 'Create a new test project for the ert-runner';

exports.handler = async (argv) => {
await UTIL.e_call(argv, 'generate/test/ert-runner', argv.file);
};
25 changes: 25 additions & 0 deletions cmds/generate/test/ert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (C) 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, 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/>.
*/

"use strict";

exports.command = ['ert [file]'];
exports.desc = 'Create a new test project for the ert tests';

exports.handler = async (argv) => {
await UTIL.e_call(argv, 'generate/test/ert', argv.file);
};
45 changes: 41 additions & 4 deletions docs/content/Getting-Started/Commands-and-options/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,41 @@ $ eask [GLOBAL-OPTIONS] generate ignore <name>
to generate ignore file.
{{< /hint >}}

## 🔍 eask generate test ert

Create a new test project for the [ert][] tests.

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

## 🔍 eask generate test ert-runner

Create a new test project for the [ert-runner][].

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

## 🔍 eask generate test buttercup

Create a new [Buttercup][] setup for the project.

```sh
$ eask [GLOBAL-OPTIONS] generate test buttercup
```

## 🔍 eask generate test ecukes

Create a new [Ecukes][] setup for the project.

```sh
$ eask [GLOBAL-OPTIONS] generate test ecukes
```

## 🔍 eask generate workflow circle-ci

Generate CircleCI workflow yaml file.
Generate [CircleCI][] workflow yaml file.

The default filename is `config.yml`.

Expand All @@ -523,7 +555,7 @@ This will generate the yaml file under `.circleci/`!

## 🔍 eask generate workflow github

Generate GitHub Actions workflow yaml file.
Generate [GitHub Actions][] workflow yaml file.

The default filename is `test.yml`.

Expand All @@ -535,7 +567,7 @@ This will generate the yaml file under `.github/workflow/`!

## 🔍 eask generate workflow gitlab

Generate GitLab Runner workflow yaml file.
Generate [GitLab Runner][] workflow yaml file.

The default filename is `.gitlab-ci.yml`.

Expand All @@ -545,7 +577,7 @@ $ eask [GLOBAL-OPTIONS] generate workflow gitlab [--file]

## 🔍 eask generate workflow travis-ci

Generate Travis CI workflow yaml file.
Generate [Travis CI][] workflow yaml file.

The default filename is `.travis.yml`.

Expand Down Expand Up @@ -1068,6 +1100,11 @@ Do not use a proxy for any URL matching pattern.
[Eldev]: https://emacs-eldev.github.io/eldev/
[Keg]: https://github.com/conao3/keg.el

[CircleCI]: https://circleci.com/
[GitHub Actions]: https://github.com/features/actions
[GitLab Runner]: https://docs.gitlab.com/runner/
[Travis CI]: https://www.travis-ci.com/

[ert]: https://www.gnu.org/software/emacs/manual/html_node/ert/
[ert-runner]: https://github.com/rejeep/ert-runner.el
[buttercup]: https://github.com/jorgenschaefer/emacs-buttercup
Expand Down
45 changes: 41 additions & 4 deletions docs/content/Getting-Started/Commands-and-options/_index.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,41 @@ $ eask [GLOBAL-OPTIONS] generate ignore <name>
💡 此命令使用包 [gitignore-templates](https://github.com/xuchunyang/gitignore-templates.el) 生成忽略文件。
{{< /hint >}}

## 🔍 eask generate test ert

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

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

## 🔍 eask generate test ert-runner

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

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

## 🔍 eask generate test buttercup

為專案建立一個新的 [Buttercup][] 設定。

```sh
$ eask [GLOBAL-OPTIONS] generate test buttercup
```

## 🔍 eask generate test ecukes

為專案創建一個新的 [Ecukes][] 設定。

```sh
$ eask [GLOBAL-OPTIONS] generate test ecukes
```

## 🔍 eask generate workflow circle-ci

生成 CircleCI 工作流 yaml 文件。
生成 [CircleCI][] 工作流 yaml 文件。

默認文件名為 `config.yml`

Expand All @@ -512,7 +544,7 @@ $ eask [GLOBAL-OPTIONS] generate workflow circle-ci [--file]

## 🔍 eask generate workflow github

生成 GitHub Actions 工作流 yaml 文件。
生成 [GitHub Actions][] 工作流 yaml 文件。

默認文件名為 `test.yml`

Expand All @@ -524,7 +556,7 @@ $ eask [GLOBAL-OPTIONS] generate workflow github [--file]

## 🔍 eask generate workflow gitlab

生成 GitLab Runner 工作流程 yaml 文件。
生成 [GitLab Runner][] 工作流程 yaml 文件。

默認文件名為 `.gitlab-ci.yml`

Expand All @@ -534,7 +566,7 @@ $ eask [GLOBAL-OPTIONS] generate workflow gitlab [--file]

## 🔍 eask generate workflow travis-ci

生成 Travis CI 工作流 yaml 文件。
生成 [Travis CI][] 工作流 yaml 文件。

默認文件名為 `.travis.yml`

Expand Down Expand Up @@ -1054,6 +1086,11 @@ $ eask --proxy "localhost:8888" [COMMAND]
[Eldev]: https://emacs-eldev.github.io/eldev/
[Keg]: https://github.com/conao3/keg.el

[CircleCI]: https://circleci.com/
[GitHub Actions]: https://github.com/features/actions
[GitLab Runner]: https://docs.gitlab.com/runner/
[Travis CI]: https://www.travis-ci.com/

[ert]: https://www.gnu.org/software/emacs/manual/html_node/ert/
[ert-runner]: https://github.com/rejeep/ert-runner.el
[buttercup]: https://github.com/jorgenschaefer/emacs-buttercup
Expand Down
20 changes: 10 additions & 10 deletions docs/content/Getting-Started/Introduction/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ The table shows what technology has been chosen by their author and how the
project is being constructed. Furthermore, what technical decisions have they
made? Drop support? Project's layout? Etc.

| | Eask | Cask | Eldev | makem.sh |
|----------------|-------------------|-----------------------------|----------------|-----------------------------|
| bin folder | binary, bash, bat | bash, bat | bash, bat, ps1 | bash |
| Cross-Platform || ❌, doesn't support Windows || ❌, doesn't support Windows |
| Emacs version | 26.1+ | 24.5+ | 24.4+ | 26.1+ |
| Size | 7,000+ lines | 3,000+ lines | 8,000+ lines | 1,200+ lines |
| Executable || || |
| Pure Elisp | ❌, JavaScript | || |
| CLI Parser | [yargs][] | [commander][] | built-in | built-in |
| | Eask | Cask | Eldev | makem.sh |
|----------------|-------------------|-------------------------|----------------|---------------------------|
| bin folder | binary, bash, bat | bash, bat | bash, bat, ps1 | bash |
| Cross-Platform || ❌, Windows not support || ❌, Windows not supported |
| Emacs version | 26.1+ | 24.5+ | 24.4+ | 26.1+ |
| Size | 9,000+ lines | 3,000+ lines | 8,000+ lines | 1,200+ lines |
| Executable |||||
| Pure Elisp | ❌, JavaScript ||||
| CLI Parser | [yargs][] | [commander][] | built-in | built-in |

{{< hint info >}}
💡 **makem.sh** has a good comparisons document as well, visit their [site](https://github.com/alphapapa/makem.sh#comparisons)
Expand Down Expand Up @@ -141,4 +141,4 @@ The design of Eask was greatly influenced by the following projects:
[commander]: https://github.com/rejeep/commander.el

[DSL-Eask]: https://emacs-eask.github.io/DSL/
[DSL-Cask]: https://cask.readthedocs.io/en/latest/guide/dsl.html
[DSL-Cask]: https://cask.readthedocs.io/en/latest/guide/dsl.html
2 changes: 1 addition & 1 deletion docs/content/Getting-Started/Introduction/_index.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Eask 是最好的選擇之一。
| bin folder | binary, bash, bat | bash, bat | bash, bat, ps1 | bash |
| Cross-Platform || ❌, 不支援 Windows || ❌, 不支援 Windows |
| Emacs version | 26.1+ | 24.5+ | 24.4+ | 26.1+ |
| Size | 7,000+ 行 | 3,000+ 行 | 8,000+ 行 | 1,200+ 行 |
| Size | 9,000+ 行 | 3,000+ 行 | 8,000+ 行 | 1,200+ 行 |
| Executable |||||
| Pure Elisp | ❌, JavaScript ||||
| CLI Parser | [yargs][] | [commander][] | 內建 | 內建 |
Expand Down
51 changes: 51 additions & 0 deletions lisp/generate/test/buttercup.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
;;; generate/test/buttercup.el --- Create a new Buttercup setup for the project -*- lexical-binding: t; -*-

;;; Commentary:
;;
;; Command use to create a new Buttercup setup for the project,
;;
;; $ eask generate test buttercup
;;

;;; Code:

(let ((dir (file-name-directory (nth 1 (member "-scriptload" command-line-args)))))
(load (expand-file-name "_prepare.el"
(locate-dominating-file dir "_prepare.el"))
nil t))

(defun eask-generate-test-buttercup--init (&optional name)
"Create new test 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.")))
(message "create %s" (ansi-green (f-filename test-path)))
(f-mkdir "tests")
(let ((test-file (s-concat "test-" name ".el")))
(message "create %s" (ansi-green test-file))
(with-temp-file (f-join test-path test-file)
(insert (format "\
;;; %s --- Buttercup tests for %s -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'buttercup)
;; Example test!
(describe \"A suite\"
(it \"contains a spec with an expectation\"
(expect t :to-be t)))
;;; %s ends here
" test-file name test-file))))))

(eask-start
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'buttercup)
(eask-package-install 'f))
(require 'buttercup)
(require 'f)
(eask-generate-test-buttercup--init (eask-guess-package-name)))

;;; generate/test/buttercup.el ends here
Loading

0 comments on commit 429f005

Please sign in to comment.