Skip to content

Instantly share code, notes, and snippets.

@jeremy-donson
Last active October 26, 2020 14:13
Show Gist options
  • Save jeremy-donson/aa2da2b5a69ee1d35729fa145d825cee to your computer and use it in GitHub Desktop.
Save jeremy-donson/aa2da2b5a69ee1d35729fa145d825cee to your computer and use it in GitHub Desktop.
Hello Bash Testing
#!/bin/bash
# We could do this for each language: [ python, ruby, node, java, go, kotlin ]
# FUNCTION: testBashVer = Test for min required bash version.
# FUNCTION: testBashHello = Test for expected bash output.
# FUNCTION: bashHello = Print the following to the terminal ["Hello, Bash!" ]
# FUNCTION: printManPage = Print out a linux man page for offline reference.
# SNIPPETS BELOW
# bash --version
BASH_VERSION_MIN='4.1.x'
BASH_VERSION=$( bash --version | grep GNU | cut -d' ' -f4 | cut -d'(' -f1 )
# Remove '.x' from end of version min string.
BASH_VERSION_MIN_STUB=${BASH_VERSION_MIN::-2}
# charcount of BASH_VERSION_MIN_STUB = n
CHARCOUNT=${#BASH_VERSION_MIN_STUB}
# Take n chars from BSH VERSION
BASH_VERSION_STUB=${BASH_VERSION::-2} # ??
# Compare first n chars of version string against first n chars of version min.
if
# echo -en 'Hello, Bash!'
EXPECTED="Hello, Bash!"
OUTPUT=$( echo -en 'Hello, Bash!' )
# This might be better handled with shell result codes?
if [ "$OUTPUT" -eq "$EXPECTED" ]; then
echo "SUCCESS"
else
echo 'FAIL'
fi
# Later we can move from test-driven development (tdd) to behavior-driven developmet (bdd)
# [Shell Spec TDD](https://shellspec.info/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment