Skip to content

Commit b39d741

Browse files
committed
Convert tests to Bats
1 parent 0f18aec commit b39d741

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+949
-1449
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/.gitattributes export-ignore
33
/.github/ export-ignore
44
/.gitignore export-ignore
5+
/.gitmodules export-ignore
56
/.simplecov export-ignore
67
/CHANGELOG.md export-ignore
78
/CODE_OF_CONDUCT.md export-ignore

.github/workflows/continuous-integration.yml

+6-10
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ jobs:
3737
steps:
3838
- name: "Checkout repository"
3939
uses: "actions/checkout@v4"
40-
- name: "Install expect"
41-
run: |
42-
sudo apt-get update
43-
sudo apt-get -y install expect
40+
with:
41+
submodules: "recursive"
4442
- name: "Set up PHP"
4543
uses: "shivammathur/setup-php@v2"
4644
with:
@@ -60,10 +58,8 @@ jobs:
6058
steps:
6159
- name: "Checkout repository"
6260
uses: "actions/checkout@v4"
63-
- name: "Install expect"
64-
run: |
65-
sudo apt-get update
66-
sudo apt-get -y install expect
61+
with:
62+
submodules: "recursive"
6763
- name: "Set up Ruby"
6864
uses: "ruby/setup-ruby@v1"
6965
with:
@@ -79,9 +75,9 @@ jobs:
7975
tools: "composer:v2"
8076
coverage: "none"
8177
- name: "Run expect tests"
82-
run: "bashcov --root ./bin -- ./tests/bash-test.sh tests/tests.sh"
78+
run: "bashcov --root ./bin -- ./tests/test_helper/bats/bin/bats tests/"
8379
- name: "Publish coverage report to Codecov"
84-
uses: "codecov/codecov-action@v4"
80+
uses: "codecov/codecov-action@v5"
8581
with:
8682
files: "./bin/coverage/codecov-result.json"
8783

.gitmodules

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[submodule "tests/test_helper/bats-assert"]
2+
path = tests/test_helper/bats-assert
3+
url = https://github.com/bats-core/bats-assert.git
4+
[submodule "tests/test_helper/bats-support"]
5+
path = tests/test_helper/bats-support
6+
url = https://github.com/bats-core/bats-support.git
7+
[submodule "tests/test_helper/bats-file"]
8+
path = tests/test_helper/bats-file
9+
url = https://github.com/bats-core/bats-file.git
10+
[submodule "tests/test_helper/bats"]
11+
path = tests/test_helper/bats
12+
url = https://github.com/bats-core/bats-core.git

CONTRIBUTING.md

+15-24
Original file line numberDiff line numberDiff line change
@@ -89,38 +89,29 @@ When you do begin working on your feature, here are some guidelines to consider:
8989
## Developing
9090

9191
To develop this project, you will need [PHP](https://www.php.net),
92-
[Composer](https://getcomposer.org), [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)),
93-
and [Expect](https://en.wikipedia.org/wiki/Expect).
92+
[Composer](https://getcomposer.org), and [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)).
9493

9594
### Running Tests
9695

97-
This project includes a suite of tests located in `tests/expect/`. These tests
98-
use the `expect` command to automate CLI interactions. The tests will run
99-
automatically as part of continuous integration, or you may run them locally with:
96+
This project includes a suite of tests located in `tests/`. These tests
97+
use [Bats](https://bats-core.readthedocs.io/en/stable/) to test command line
98+
interaction. The tests will run automatically as part of continuous integration,
99+
and you may also run them locally.
100100

101-
```
102-
composer test
103-
```
104-
105-
To run the tests, you must have an up-to-date version of coreutils (8.30 or
106-
later).
107-
108-
To generate a new test:
101+
To ensure Bats is set up properly in your local environment, after cloning the
102+
project, download the Git submodules:
109103

104+
```bash
105+
cd composer-install/
106+
git submodule init
107+
git submodule update
110108
```
111-
cd tests/expect/
112-
autoexpect ../../bin/path-to-script-to-test.sh
113-
```
114-
115-
`autoexpect` will save the test to `script.exp`. Rename it with a more
116-
descriptive name, and run it to ensure it does what you expect: `./script.exp`.
117-
You may need to edit the test file or add to it, according to your needs.
118109

119-
Expect is an extension to the [Tcl](https://en.wikipedia.org/wiki/Tcl) scripting
120-
language, so it may be helpful to learn a little about Tcl as you write tests.
110+
Then run:
121111

122-
When done, `cd ../..` and run `composer test`.
123-
Your new test should run along with the other tests.
112+
```bash
113+
composer test
114+
```
124115

125116
[github]: https://github.com/ramsey/composer-install
126117
[issues]: https://github.com/ramsey/composer-install/issues

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ the [Setup PHP](https://github.com/shivammathur/setup-php) action as a step.
4242
- uses: "ramsey/composer-install@v3"
4343
```
4444
45-
:bulb: There is no need to set up a separate caching step since ramsey/composer-install
46-
handles this for you.
45+
> [!TIP]
46+
> There is no need to set up a separate caching step since ramsey/composer-install handles this for you.
4747
4848
### Input Parameters
4949

bin/cache_key.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ function make_key {
1919
tr "[:blank:]" "-" <<<"${non_empties[*]}"
2020
}
2121

22-
runner_os="${1}"
23-
php_version="${2}"
24-
dependency_versions="${3:-locked}"
25-
composer_options="${4}"
26-
files_hash="${5}"
27-
custom_cache_key="${6}"
28-
custom_cache_suffix="${7}"
29-
working_directory="${8}"
22+
runner_os="${1:-}"
23+
php_version="${2:-}"
24+
dependency_versions="${3:-}"
25+
composer_options="${4:-}"
26+
files_hash="${5:-}"
27+
custom_cache_key="${6:-}"
28+
custom_cache_suffix="${7:-}"
29+
working_directory="${8:-}"
3030

3131
key=()
3232
restore_key=()

bin/composer_install.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env bash
22

3-
dependency_versions="${1:-locked}"
4-
additional_composer_options="${2}"
5-
working_directory="${3}"
3+
dependency_versions="${1:-}"
4+
additional_composer_options="${2:-}"
5+
working_directory="${3:-}"
66
php_path="${4:-$(which php)}"
77
composer_path="${5:-$(which composer)}"
8-
composer_lock="${6}"
9-
require_lock_file="${7}"
8+
composer_lock="${6:-}"
9+
require_lock_file="${7:-}"
1010

1111
composer_command="update"
1212
composer_options=("--no-interaction" "--no-progress" "--ansi")

bin/should_cache.sh

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#!/usr/bin/env bash
22

3-
ignore_cache="${1}"
4-
should_cache=1
3+
ignore_cache="${1:-}"
54
will_cache="will cache"
65

76
case "${ignore_cache}" in
8-
1) should_cache=0 ;;
9-
yes) should_cache=0 ;;
10-
true) should_cache=0 ;;
7+
1 | yes | Yes | y | Y | true | True) should_cache=0 ;;
8+
*) should_cache=1 ;;
119
esac
1210

1311
if [ $should_cache -eq 0 ]; then

composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"allow-plugins": false
1717
},
1818
"scripts": {
19-
"clean-tests": "git clean -fX tests/",
20-
"test": "./tests/bash-test.sh tests/tests.sh"
19+
"test": "./tests/test_helper/bats/bin/bats tests/"
2120
}
2221
}

tests/bash-test.sh

-154
This file was deleted.

0 commit comments

Comments
 (0)