From a3a7282226443ba702ec9282358aa104e2bbde64 Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Thu, 17 Sep 2015 16:21:50 -0700 Subject: [PATCH] Minor improvements to runtest.sh --- tests/runtest.sh | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/runtest.sh b/tests/runtest.sh index 13ec787..00847c6 100644 --- a/tests/runtest.sh +++ b/tests/runtest.sh @@ -15,10 +15,10 @@ function print_results { echo "=======================" echo " Test Results" echo "=======================" - echo "# Tests Discovered : "$countTotalTests - echo "# Passed : "$countPassedTests - echo "# Failed : "$countFailedTests - echo "# Skipped : "$countSkippedTests + echo "# Tests Discovered : $countTotalTests" + echo "# Passed : $countPassedTests" + echo "# Failed : $countFailedTests" + echo "# Skipped : $countSkippedTests" echo "=======================" } @@ -39,61 +39,61 @@ trap handle_ctrl_c INT function set_test_directories { listFileName=$1 - if [ ! -f $listFileName ] + if [ ! -f "$listFileName" ] then - echo "Test directories file not found at "$listFileName + echo "Test directories file not found at $listFileName" echo "Exiting..." exit 1 fi - readarray testDirectories < $listFileName + readarray testDirectories < "$listFileName" } function run_tests_in_directory { rootDir=$1 # Recursively search through directories for .sh files to run. - for file in $(find $rootDir -name '*.sh' -printf '%P\n') + for file in $(find "$rootDir" -name '*.sh' -printf '%P\n') do scriptFullPath="$rootDir/$file" # Switch to directory where the script is - cd "$(dirname $scriptFullPath)" + cd "$(dirname "$scriptFullPath")" # Convert DOS line endings to Unix if needed - sed -i 's/\r$//' $scriptFullPath + sed -i 's/\r$//' "$scriptFullPath" - scriptName=$(basename $file) - test $verbose == 1 && echo "Starting "$file + scriptName=$(basename "$file") + test "$verbose" == 1 && echo "Starting $scriptName" # Run the test - ./$scriptName | + ./"$scriptName" | while testOutput= read -r line do # Print the test output if verbose mode is on - test $verbose == 1 && echo " "$line + test "$verbose" == 1 && echo " $line" done; testScriptExitCode=${PIPESTATUS[0]} case $testScriptExitCode in 0) let countPassedTests++ - echo "PASSED - "$scriptFullPath + echo "PASSED - $scriptFullPath" ;; 1) let countFailedTests++ - echo "FAILED - "$scriptFullPath + echo "FAILED - $scriptFullPath" ;; 2) let countSkippedTests++ - echo "SKIPPED - "$scriptFullPath + echo "SKIPPED - $scriptFullPath" ;; esac let countTotalTests++ # Return to root directory - cd $rootDir + cd "$rootDir" done } @@ -118,17 +118,17 @@ do verbose=1 ;; --testDirFile=*) - set_test_directories ${i#*=} + set_test_directories "${i#*=}" ;; *);; esac done -if [ -z $testDirectories ] +if [ -z "$testDirectories" ] then # No test directories were specified, so run everything in the current # directory and its subdirectories. - run_tests_in_directory $currDir + run_tests_in_directory "$currDir" else # Otherwise, run all the tests in each specified test directory. for testDir in "${testDirectories[@]}" -- 2.7.4