#!/bin/bash if [ -z "$1" ]; then echo "Helper script to create empty test and reference files and assign a new number." echo "Usage: $0 " exit 1 fi TESTS_PATH=$(dirname ${BASH_SOURCE[0]}) set -ue # shellcheck disable=SC2010 LAST_TEST_NO=$(ls -1 ${TESTS_PATH} | grep -P -o '^\d+' | sort -nr | head -1) # remove leading zeros, increment and add padding zeros to 5 digits NEW_TEST_NO=$(printf "%05d\n" $((10#$LAST_TEST_NO + 1))) # if extension is not provided, use `.sql` FILENAME="${1}" FILEEXT="sql" if [[ $1 == *.* ]] ; then FILENAME="${1%.*}" FILEEXT="${1##*.}" fi set -x touch ${TESTS_PATH}/${NEW_TEST_NO}_${FILENAME}.${FILEEXT} if [[ $FILEEXT == "sh" ]] ; then chmod +x ${TESTS_PATH}/${NEW_TEST_NO}_${FILENAME}.${FILEEXT} # shellcheck disable=SC2016 echo '#!/usr/bin/env bash CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # shellcheck source=../shell_config.sh . "$CUR_DIR"/../shell_config.sh ' >> ${TESTS_PATH}/${NEW_TEST_NO}_${FILENAME}.${FILEEXT} fi touch ${TESTS_PATH}/${NEW_TEST_NO}_${FILENAME}.reference