This is the shellmock
project, a mocking framework for shell scripts.
It works well with the bats-core testing framework.
You can find our documentation below.
Inspiration for shellmock
was taken from testing frameworks such as pytest
and golang/mock
.
To get started, just head over to the releases and download the
latest release.
Then, you can write your bats-core-based tests.
Just make sure to use load shellmock
in your setup
function.
See below for shellmock
's documentation.
The following tools are needed to use shellmock
:
base32
bash
(at least version 4.4)cat
chmod
mkdir
mktemp
rm
On Debian-based systems, they can be installed via:
sudo apt install -yqq bash coreutils
You also need the bats-core testing framework that
can be installed via npm following its docs.
We recommend an installation via npm
instead of an installation via apt
.
The reason is that many system packages provide comparatively old versions while
the version installable via npm
is up to date.
To run the commands
command, you also need a
Golang toolchain.
For optimal performance, install flock
, which is contained within the
util-linux
package on Debian-based systems.
- Usage documentation:
- Quickstart guide:
Read this page if this is your first time using
shellmock
and you want to get started. - How to:
Read this page if you want to know how to go about creating your tests with
shellmock
in general. - Detailed example:
Read this page if you want to see how
shellmock
can be used to create extensive tests of a script of medium complexity. - Command reference:
Read this page if you want to know about all of
shellmock
's features or have questions about a specific command. - shellmock's own tests:
Read this code if you want see how
shellmock
itself is being tested using bats-core. Those tests also showcaseshellmock
's features. This is a non-exhaustive list of examples you can find in the tests:- Mock an executable
- Mock a function
- Mock with non-zero exit code
- Match positional arguments, both with fixed and flexible positions
- Create a mock that is writing a fixed string to stdout
- Fail a test by killing the parent process when there is an unexpected call
- Quickstart guide:
Read this page if this is your first time using
- Technical documentation:
- Building shellmock: Read this page if you want to know how to generate the release artefacts.
Like what we did? Great, we’d love to hear that. Don’t like it? Not so great! But we are eager to hear your feedback on how we could improve!
Shellmock is open-sourced under the Apache-2.0 license. See the LICENSE file for details.
Copyright (c) 2022 - for information on the respective copyright owner see the NOTICE file or the repository https://github.com/boschresearch/shellmock
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.