bkahlert/bats-wrapper
Self-contained wrapper to run tests based on the Bash testing framework Bats
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.7%) to scientific vocabulary
Keywords
Repository
Self-contained wrapper to run tests based on the Bash testing framework Bats
Basic Info
Statistics
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 8
- Releases: 5
Topics
Metadata Files
README.md
bkahlert/bats-wrapper

About
Bats Wrapper is a self-contained wrapper to run tests based on the Bash testing framework Bats with some differences:
- To facilitate testing of Dockerfiles the Docker command line tools is pre-installed and
docker buildx bake is called if $DOCKER_BAKE is set (with its contents as the arguments).
- The environment variable TESTING is set to 1 while running tests.
- The following arguments are set by default:
- --jobs (with the number of processors or 4 or they cannot be determined)
- --no-parallelize-within-files
- --no-tempdir-cleanup
- --recursive
- --timing
- The following extensions are loaded by default (and patched to support the nounset shell option):
- bats-support
- bats-assert
- bats-file
- Helper script with the name _setup.sh are automatically sourced
(with the _setup.sh located in the same directory as the bats test file sourced last)
text
📁work ⬅︎ you are here
├─📁src
└─📁test
├─🔧_setup.sh … automatically sourced
├─📄foo.bats
└─📁bar
├─🔧_setup.sh … automatically sourced
└─📄baz.bats
- The working directory for each test is $BATS_TEST_TMPDIR.
- To focus on a single or a couple of tests an alternative to the --filter option
is to prefix a test name with x or X:
```bash
@test "foo" {
...
}
@test "Xbar" {
...
}
``
The above example will only executeXbarwithout you having to change the command line.
- Several extensions are provided:
-copy_fixtureto handle fixtures
-expect` for tests that require interaction
- Check wrapper.sh for all extensions.
Docker image
Build locally
```shell git clone https://github.com/bkahlert/bats-wrapper.git cd bats-wrapper
Build image and output to docker (default)
docker buildx bake
Build multi-platform image
docker buildx bake image-all ```
Image
- Docker Hub
bkahlert/bats-wrapper - GitHub Container Registry
ghcr.io/bkahlert/bats-wrapper
Following platforms for this image are available:
- linux/amd64
- linux/arm64/v8
Usage
The Docker container passes all arguments to the wrapped Bash testing framework Bats and therefore inherits all its supported options.
Docker image
shell
docker run -it --rm \
-e TERM="$TERM" \
-v "$PWD":"$PWD" \
-w "$PWD" \
bkahlert/bats-wrapper [OPTIONS] TEST [TEST...]
Wrapper
The Bats Wrapper batsw needs nothing but a working Docker installation and either curl
, wget,
or wget2:
curl
shell
curl -LfsS https://git.io/batsw | "$SHELL" -s -- [OPTIONS] TEST [TEST...]
wget
shell
wget -qO- https://git.io/batsw | "$SHELL" -s -- [OPTIONS] TEST [TEST...]
wget2
shell
wget2 -nv -O- https://git.io/batsw | "$SHELL" -s -- [OPTIONS] TEST [TEST...]
GitHub Action
The Bats Wrapper can also be used to run your Bats based tests right inside your GitHub workflow.
Usage Example
```yml jobs: docs: runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run Bats tests
id: bats
uses: bkahlert/bats-wrapper@v0.1.4
with:
tests: test
```
All described options can be used to customize the test run. Please consult action.yml for detailed information.
Image Configuration
This image can be configured using the following options of which all but APP_USER and APP_GROUP exist as both—build argument and environment variable.
You should go for build arguments if you want to set custom defaults you don't intend to change (often). Environment variables will overrule any existing
configuration on each container start.
APP_USERName of the main user (default:bats)APP_GROUPName of the main user's group (default:bats)DEBUGWhether to log debug information (default:0)TZTimezone the container runs in (default:UTC)LANGLanguage/locale to use (default:C.UTF-8)PUIDUser ID of thelibguestfsuser (default:1000)PGIDGroup ID of thelibguestfsgroup (default:1000)
```shell
Build single image with build argument TZ
docker buildx bake --build-arg TZ="$(date +"%Z")"
Build multi-platform image with build argument TZ
docker buildx bake image-all --build-arg TZ="$(date +"%Z")"
Start container with environment variable TZ
docker run --rm \ -e TZ="$(date +"%Z")" \ -v "$(pwd):$(pwd)" \ -w "$(pwd)" \ bats-wrapper:local ```
Testing
```shell git clone https://github.com/bkahlert/bats-wrapper.git cd bats-wrapper
Use Bats wrapper to build the Docker image and run the tests
chmod +x ./batsw DOCKERBAKE="--set '*.tags=test'" BATSWIMAGE=test:latest \ ./batsw --batsw:-e --batsw:BUILD_TAG=test test ```
Troubleshooting
- To avoid permission problems with generated files, you can use your local user/group ID (see
PUID/PGID). - If you need access to Docker, its command line interface is already installed.
You can control your host instance by mounting/var/run/docker.sock.
shell
docker run -it --rm \
-e PUID="$(id -u)" \
-e PGID="$(id -g)" \
-e TERM="$TERM" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$PWD":"$PWD" \
-w "$PWD" \
bkahlert/bats-wrapper:edge
Contributing
Want to contribute? Awesome! The most basic way to show your support is to star the project, or to raise issues. You can also support this project by making a Paypal donation to ensure this journey continues indefinitely!
Thanks again for your support, it is much appreciated! :pray:
License
MIT. See LICENSE for more details.
Owner
- Name: Björn Kahlert
- Login: bkahlert
- Kind: user
- Location: Berlin, Germany
- Website: bkahlert.com
- Repositories: 23
- Profile: https://github.com/bkahlert
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- given-names: "Björn"
family-names: "Kahlert"
orcid: "https://orcid.org/0000-0003-1705-4067"
title: "Bats Wrapper — self-contained wrapper to run Bats (Bash Automated Testing System) tests"
version: 0.1.4
date-released: 2021-11-29
url: "https://github.com/bkahlert/bats-wrapper"
GitHub Events
Total
- Watch event: 1
Last Year
- Watch event: 1
Committers
Last synced: about 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Björn Kahlert | m****l@b****m | 17 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 5 months ago
All Time
- Total issues: 1
- Total pull requests: 13
- Average time to close issues: N/A
- Average time to close pull requests: about 1 month
- Total issue authors: 1
- Total pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 0.15
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 13
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- johnqa (1)
Pull Request Authors
- dependabot[bot] (8)
- github-actions[bot] (5)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
- Total downloads: unknown
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 5
github actions: bkahlert/bats-wrapper
Run Bats (Bash Automated Testing System) tests
- License: mit
-
Latest release: v0.1.4
published about 4 years ago
Rankings
Dependencies
- actions/checkout v2 composite
- actions/upload-artifact v2 composite
- docker/bake-action v1 composite
- docker/login-action v1 composite
- docker/metadata-action v3 composite
- docker/setup-buildx-action v1 composite
- docker/setup-qemu-action v1 composite
- softprops/action-gh-release v1 composite
- actions/checkout v2 composite
- actions/upload-artifact v2 composite
- bkahlert/recordr v0.2.2 composite
- peter-evans/create-pull-request v3 composite
- dorny/test-reporter v1 composite
- docker 20.10.11-alpine3.14 build