| 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 the llvm build dir, usually Release+Asserts>" | 18 "<Path to the llvm build dir, usually Release+Asserts>" |
| 19 echo "" | 19 echo "" |
| 20 echo " Runs all the libFindBadConstructs unit tests" | 20 echo " Runs all the libFindBadConstructs unit tests" |
| 21 echo "" | 21 echo "" |
| 22 } | 22 } |
| 23 | 23 |
| 24 # Runs a single test case. | 24 # Runs a single test case. |
| 25 do_testcase() { | 25 do_testcase() { |
| 26 local flags="" |
| 27 if [ -e "${3}" ]; then |
| 28 flags="$(cat "${3}")" |
| 29 fi |
| 26 local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \ | 30 local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \ |
| 27 -Xclang -load -Xclang "${CLANG_DIR}"/lib/libFindBadConstructs.${LIB} \ | 31 -Xclang -load -Xclang "${CLANG_DIR}"/lib/libFindBadConstructs.${LIB} \ |
| 28 -Xclang -plugin -Xclang find-bad-constructs ${1} 2>&1)" | 32 -Xclang -add-plugin -Xclang find-bad-constructs ${flags} ${1} 2>&1)" |
| 29 local diffout="$(echo "${output}" | diff - "${2}")" | 33 local diffout="$(echo "${output}" | diff - "${2}")" |
| 30 if [ "${diffout}" = "" ]; then | 34 if [ "${diffout}" = "" ]; then |
| 31 echo "PASS: ${1}" | 35 echo "PASS: ${1}" |
| 32 else | 36 else |
| 33 failed_any_test=yes | 37 failed_any_test=yes |
| 34 echo "FAIL: ${1}" | 38 echo "FAIL: ${1}" |
| 35 echo "Output of compiler:" | 39 echo "Output of compiler:" |
| 36 echo "${output}" | 40 echo "${output}" |
| 37 echo "Expected output:" | 41 echo "Expected output:" |
| 38 cat "${2}" | 42 cat "${2}" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 57 cd "$(dirname "${0}")" | 61 cd "$(dirname "${0}")" |
| 58 | 62 |
| 59 if [ "$(uname -s)" = "Linux" ]; then | 63 if [ "$(uname -s)" = "Linux" ]; then |
| 60 export LIB=so | 64 export LIB=so |
| 61 elif [ "$(uname -s)" = "Darwin" ]; then | 65 elif [ "$(uname -s)" = "Darwin" ]; then |
| 62 export LIB=dylib | 66 export LIB=dylib |
| 63 fi | 67 fi |
| 64 fi | 68 fi |
| 65 | 69 |
| 66 for input in *.cpp; do | 70 for input in *.cpp; do |
| 67 do_testcase "${input}" "${input%cpp}txt" | 71 do_testcase "${input}" "${input%cpp}txt" "${input%cpp}flags" |
| 68 done | 72 done |
| 69 | 73 |
| 70 if [[ "${failed_any_test}" ]]; then | 74 if [[ "${failed_any_test}" ]]; then |
| 71 exit ${E_FAILEDTEST} | 75 exit ${E_FAILEDTEST} |
| 72 fi | 76 fi |
| OLD | NEW |