#!/bin/sh #do_unittests.sh # # run this script _before_ you do a commit and fix errors before uploading # # preparations: # - add the following lines to /etc/super.tab: # :global_options relative_path=y # CryptoBoxRootActionsLocal ./CryptoBoxRootActions cryptobox # GETOPT="getopt" BASE_DIR=$(cd "$(dirname $0)/.."; pwd) export PYTHONPATH=$BASE_DIR/src disable_filecheck() { sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = True/" "$BASE_DIR/bin/CryptoBoxRootActions" } enable_filecheck() { sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = False/" "$BASE_DIR/bin/CryptoBoxRootActions" } run_tests() { # chdir to 'bin' - all config settings depend on this cd "${BASE_DIR}/bin" disable_filecheck if test -n "$files" then # do the specified tests ##The use of "eval", plus not using double quotes for ##$a below are ##required because getopt already puts argument names in ##single-quotes, and the script will not work with both sets ##of quotes. for a in $files do eval testoob -v $a done else # do all tests for a in ${BASE_DIR}/src/cryptobox/tests/test.*.py do testoob -v "$a" done fi enable_filecheck return 0 } usage() { echo -e "Usage:" echo -e "\tbin/do_unittests.sh --clobber=foo [ files... ]" echo -e "\t" echo -e "\t(Where \"files\", if given, are absolute pathnames)" echo -e "\t(Example: bin/do_unittests.sh --clobber=sdX)" echo -e "***Warning: All data on /dev/foo will be DESTROYED!" echo -e "\t" exit 1 } ##### main() section ##### ##Declare global variables with empty contents CNAS_UTEST_CLOBBER="" files="" clobber_dev_arg="" ##Use the getopt command line utility to simplify parsing getopt_str=`${GETOPT} -o c: --long clobber: \ -n do_unittests.sh -- "$@"` #echo $getopt_str ##Assign the tokens to an array getopt_arr=($getopt_str) ##Note: Output of getopt in this script should look like: ## --clobber 'sdX' -- file1 file2 file3 ... ##Read the following code with that in mind. ##If there is exactly one option, and it has an argument if [ "${getopt_arr[0]}" == "--clobber" ] \ && [ "${getopt_arr[2]}" == "--" ]; then clobber_dev_arg="${getopt_arr[1]}" ##Strip any single quotes from the device name clobber_dev_arg="${clobber_dev_arg//\'/}" #echo ${clobber_dev_arg} ##Grab the part of $getopt_str that follows "--" files="`expr match \"${getopt_str}\" '.*--\(.*\)'`" #echo $files if [ -b "/dev/${clobber_dev_arg}" ]; then export CNAS_UTEST_CLOBBER="${clobber_dev_arg}" ##Run the tests using testoob... run_tests else echo "Error: /dev/${clobber_dev_arg} is not a valid block device" exit 2 fi else usage fi