This repository demonstrates via its commit history the process of improving the code quality of a Bash script. The commit messages explain the introduced changes and their motivation while this document lists the used tools and references.
The ShellSpec framework is used for testing as it employs a behaviour-driven development approach with a domain-specific language that helps create easily readable tests. In addition, it provides many options for mocking and other useful testing features.
The other essential tool to detect error-prone code or even bugs is the static code analyser ShellCheck. It can be run in the command line or integrated into editors.
For example, for the presentation of the process, the ALE plugin and Airline status line for Vim have been used to show the annotations in the editor.
The Flog plugin for Vim has been used to check out the commits one after another, so tests could be run at the various stages.
- ShellSpec – Project directory
- ShellSpec – runs specfile using
/bin/sh
by default - ShellSpec – How to use ShellSpec with Docker, Run simple with helper script and extra hooks
- Bash reference manual – Here strings
- Bash reference manual – Shell parameter expansion,
${parameter:?word}
- Bash reference manual – Conditional constructs,
((…))
-
Stack Overflow – How to assign a heredoc value to a variable in Bash?
-
Bash reference manual – Shell parameter expansion,
${parameter/pattern/string}
- Bash FAQ – What is the difference between
test
,[
and[[
? - Bash Guide – Practices, Choose your shell