| OLD | NEW | 
|---|
| 1 #!/bin/bash | 1 #!/bin/bash | 
| 2 # | 2 # | 
| 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be | 
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. | 
| 6 # | 6 # | 
| 7 # Hacky, primitive testing: This runs the style plugin for a set of input files | 7 # Hacky, primitive testing: This runs the style plugin for a set of input files | 
| 8 # and compares the output with golden result files. | 8 # and compares the output with golden result files. | 
| 9 | 9 | 
| 10 E_BADARGS=65 | 10 E_BADARGS=65 | 
| 11 E_FAILEDTEST=1 | 11 E_FAILEDTEST=1 | 
| 12 | 12 | 
| 13 failed_any_test= | 13 failed_any_test= | 
| 14 | 14 | 
| 15 # Prints usage information. | 15 # Prints usage information. | 
| 16 usage() { | 16 usage() { | 
| 17   echo "Usage: $(basename "${0}")" \ | 17   echo "Usage: $(basename "${0}")" \ | 
| 18     "<path to clang>" \ | 18     "<Path to the llvm build dir, usually Release+Asserts>" | 
| 19     "<path to plugin>" |  | 
| 20   echo "" | 19   echo "" | 
| 21   echo "  Runs all the libFindBadConstructs unit tests" | 20   echo "  Runs all the libFindBadConstructs unit tests" | 
| 22   echo "" | 21   echo "" | 
| 23 } | 22 } | 
| 24 | 23 | 
| 25 # Runs a single test case. | 24 # Runs a single test case. | 
| 26 do_testcase() { | 25 do_testcase() { | 
| 27   local flags="" | 26   local flags="" | 
| 28   if [ -e "${3}" ]; then | 27   if [ -e "${3}" ]; then | 
| 29     flags="$(cat "${3}")" | 28     flags="$(cat "${3}")" | 
| 30   fi | 29   fi | 
| 31 | 30 | 
| 32   if [ "$(uname -s)" = "Darwin" ]; then | 31   if [ "$(uname -s)" = "Darwin" ]; then | 
| 33     flags="${flags} -isysroot $(xcrun --show-sdk-path) -stdlib=libstdc++" | 32     flags="${flags} -isysroot $(xcrun --show-sdk-path) -stdlib=libstdc++" | 
| 34   fi | 33   fi | 
| 35 | 34 | 
| 36   local output="$("${CLANG_PATH}" -c -Wno-c++11-extensions \ | 35   local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \ | 
| 37       -Xclang -load -Xclang "${PLUGIN_PATH}" \ | 36       -Xclang -load -Xclang "${CLANG_DIR}"/lib/libFindBadConstructs.${LIB} \ | 
| 38       -Xclang -add-plugin -Xclang find-bad-constructs ${flags} ${1} 2>&1)" | 37       -Xclang -add-plugin -Xclang find-bad-constructs ${flags} ${1} 2>&1)" | 
| 39   local diffout="$(echo "${output}" | diff - "${2}")" | 38   local diffout="$(echo "${output}" | diff - "${2}")" | 
| 40   if [ "${diffout}" = "" ]; then | 39   if [ "${diffout}" = "" ]; then | 
| 41     echo "PASS: ${1}" | 40     echo "PASS: ${1}" | 
| 42   else | 41   else | 
| 43     failed_any_test=yes | 42     failed_any_test=yes | 
| 44     echo "FAIL: ${1}" | 43     echo "FAIL: ${1}" | 
| 45     echo "Output of compiler:" | 44     echo "Output of compiler:" | 
| 46     echo "${output}" | 45     echo "${output}" | 
| 47     echo "Expected output:" | 46     echo "Expected output:" | 
| 48     cat "${2}" | 47     cat "${2}" | 
| 49     echo | 48     echo | 
| 50   fi | 49   fi | 
| 51 } | 50 } | 
| 52 | 51 | 
| 53 # Validate input to the script. | 52 # Validate input to the script. | 
| 54 if [[ -z "${1}" ]]; then | 53 if [[ -z "${1}" ]]; then | 
| 55   usage | 54   usage | 
| 56   exit ${E_BADARGS} | 55   exit ${E_BADARGS} | 
| 57 elif [[ -z "${2}" ]]; then | 56 elif [[ ! -d "${1}" ]]; then | 
| 58   usage | 57   echo "${1} is not a directory." | 
| 59   exit ${E_BADARGS} |  | 
| 60 elif [[ ! -x "${1}" ]]; then |  | 
| 61   echo "${1} is not an executable" |  | 
| 62   usage |  | 
| 63   exit ${E_BADARGS} |  | 
| 64 elif [[ ! -f "${2}" ]]; then |  | 
| 65   echo "${2} could not be found" |  | 
| 66   usage | 58   usage | 
| 67   exit ${E_BADARGS} | 59   exit ${E_BADARGS} | 
| 68 else | 60 else | 
| 69   export CLANG_PATH="${1}" | 61   export CLANG_DIR="${PWD}/${1}" | 
| 70   export PLUGIN_PATH="${2}" | 62   echo "Using clang directory ${CLANG_DIR}..." | 
| 71   echo "Using clang ${CLANG_PATH}..." |  | 
| 72   echo "Using plugin ${PLUGIN_PATH}..." |  | 
| 73 | 63 | 
| 74   # The golden files assume that the cwd is this directory. To make the script | 64   # The golden files assume that the cwd is this directory. To make the script | 
| 75   # work no matter what the cwd is, explicitly cd to there. | 65   # work no matter what the cwd is, explicitly cd to there. | 
| 76   cd "$(dirname "${0}")" | 66   cd "$(dirname "${0}")" | 
|  | 67 | 
|  | 68   if [ "$(uname -s)" = "Linux" ]; then | 
|  | 69     export LIB=so | 
|  | 70   elif [ "$(uname -s)" = "Darwin" ]; then | 
|  | 71     export LIB=dylib | 
|  | 72   fi | 
| 77 fi | 73 fi | 
| 78 | 74 | 
| 79 for input in *.cpp; do | 75 for input in *.cpp; do | 
| 80   do_testcase "${input}" "${input%cpp}txt" "${input%cpp}flags" | 76   do_testcase "${input}" "${input%cpp}txt" "${input%cpp}flags" | 
| 81 done | 77 done | 
| 82 | 78 | 
| 83 for input in *.c; do | 79 for input in *.c; do | 
| 84   do_testcase "${input}" "${input%c}txt" "${input%c}flags" | 80   do_testcase "${input}" "${input%c}txt" "${input%c}flags" | 
| 85 done | 81 done | 
| 86 | 82 | 
| 87 if [[ "${failed_any_test}" ]]; then | 83 if [[ "${failed_any_test}" ]]; then | 
| 88   exit ${E_FAILEDTEST} | 84   exit ${E_FAILEDTEST} | 
| 89 fi | 85 fi | 
| OLD | NEW | 
|---|