Skip to content
Anders Ingemann edited this page Dec 4, 2022 · 7 revisions

homeshick comes with testsuites which ensure that the tool runs to spec after a feature was added or a refactor performed.

Dependencies

bats is required to run the tests. You can install it as a package (e.g. bats on Debian distros) or manually:

git clone --depth 1 --branch v1.8.2 https://github.com/bats-core/bats-core.git /tmp/bats \
&& /tmp/bats/install.sh /usr/local \
&& rm -rf /tmp/bats

The support, assert, and file bats libraries are required. Run test/get_bats_libs.sh to download and install a copy of these under test/bats.

Finally, expect can be installed to test the interactive prompts (these tests will be skipped if expect cannot be found). Similarly, tests related to fish and dash are run if the respective shells are installed.

Running tests

Using the local bash shell

To run all tests, run bats test/suites.

Individual test suites can be run by executing the files in the test/suites/ folder.

Testing against a set of bash versions

First, download and install the set of bash versions you wish to test against. For example:

test/get_bash.sh 4.0 5.0 5.1

For each version of bash you specify, this will download the source code and build a bash binary. All versions built are stored under test/bash-versions. (Obviously, you need to have the required build tools and a compiler installed to make this work.)

To run all tests against the installed bash versions, invoke the test/run script.

Fixtures

To run the tests in a stable manner, fixtures are needed. In the context of homeshick, those fixtures are git repositories. Each repository is created by a script of the same name in test/fixtures/.

Interactive testing

When developing for homeshick some form of manual testing is often needed to quickly confirm that a feature behaves in a specific way. The test/interactive script can be run to drop in to a shell where $HOME is set to a temporary folder and the shell is the one the script was invoked from. To launch into a different shell, the script takes a single argument of the shell executable that should be used.

homeshick will automatically be symlinked to point at the version in your git working copy so that any changes can be tested quickly.

To drop into a preconfigured homefolder where the homeshick function is defined and various dotfiles exist, a setup.sh file can be added to the test/ folder. It will automatically be executed everytime an interactive environment is set up.

In case the file does not exist test/setup-default.sh will be used instead. This script creates various rc-files for different shells that define the homeshick function or alias.

GNU coreutils on OSX

The GNU core utilities can be installed via homebrew on OSX and also configured to override the built-in OSX utilities by modifying the $PATH. The run and interactive scripts automatically remove that override from $PATH if it is detected, in order to test homeshick with the built-in OSX utilities.

If you want to preserve the GNU coreutils path in your $PATH while running tests or using the test/interactive script, you must set the environment variable $HOMESHICK_KEEP_PATH to true (export HOMESHICK_KEEP_PATH=true).