Skip to content

Commit b3f5cee

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

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

+951
-1465
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

+8-26
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,17 @@ jobs:
2727
run: "composer-normalize --dry-run"
2828

2929
test:
30-
name: "Expect tests"
30+
name: "Bats tests"
3131
runs-on: "ubuntu-latest"
32-
strategy:
33-
matrix:
34-
composer-version:
35-
- "v1"
36-
- "v2"
3732
steps:
3833
- name: "Checkout repository"
3934
uses: "actions/checkout@v4"
40-
- name: "Install expect"
41-
run: |
42-
sudo apt-get update
43-
sudo apt-get -y install expect
35+
with:
36+
submodules: "recursive"
4437
- name: "Set up PHP"
4538
uses: "shivammathur/setup-php@v2"
4639
with:
4740
php-version: "latest"
48-
tools: "composer:${{ matrix.composer-version }}"
4941
coverage: "none"
5042
env:
5143
fail-fast: true
@@ -60,10 +52,8 @@ jobs:
6052
steps:
6153
- name: "Checkout repository"
6254
uses: "actions/checkout@v4"
63-
- name: "Install expect"
64-
run: |
65-
sudo apt-get update
66-
sudo apt-get -y install expect
55+
with:
56+
submodules: "recursive"
6757
- name: "Set up Ruby"
6858
uses: "ruby/setup-ruby@v1"
6959
with:
@@ -79,9 +69,9 @@ jobs:
7969
tools: "composer:v2"
8070
coverage: "none"
8171
- name: "Run expect tests"
82-
run: "bashcov --root ./bin -- ./tests/bash-test.sh tests/tests.sh"
72+
run: "bashcov --root ./bin -- ./tests/test_helper/bats/bin/bats tests/"
8373
- name: "Publish coverage report to Codecov"
84-
uses: "codecov/codecov-action@v4"
74+
uses: "codecov/codecov-action@v5"
8575
with:
8676
files: "./bin/coverage/codecov-result.json"
8777

@@ -92,7 +82,7 @@ jobs:
9282
- name: "Checkout repository"
9383
uses: "actions/checkout@v4"
9484
- name: "Run shellcheck"
95-
run: "shellcheck --exclude=SC2230 bin/*.sh tests/*.sh"
85+
run: "shellcheck --exclude=SC2230 bin/*.sh tests/*.bats"
9686

9787
run:
9888
needs: test
@@ -107,9 +97,6 @@ jobs:
10797
- "lowest"
10898
- "highest"
10999
- "locked"
110-
composer-version:
111-
- "v1"
112-
- "v2"
113100
working-directory:
114101
- "tests/fixtures/with-lock-file"
115102
- "tests/fixtures/no-lock-file"
@@ -122,7 +109,6 @@ jobs:
122109
uses: "shivammathur/setup-php@v2"
123110
with:
124111
php-version: "latest"
125-
tools: "composer:${{ matrix.composer-version }}"
126112
coverage: "none"
127113
env:
128114
fail-fast: true
@@ -243,17 +229,13 @@ jobs:
243229
operating-system:
244230
- "ubuntu-latest"
245231
- "windows-latest"
246-
composer-version:
247-
- "v1"
248-
- "v2"
249232
steps:
250233
- name: "Checkout repository"
251234
uses: "actions/checkout@v4"
252235
- name: "Set up PHP"
253236
uses: "shivammathur/setup-php@v2"
254237
with:
255238
php-version: "latest"
256-
tools: "composer:${{ matrix.composer-version }}"
257239
coverage: "none"
258240
env:
259241
fail-fast: true

.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
}

0 commit comments

Comments
 (0)