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 THIS_DIR="$(dirname "${0}")" |
| 16 |
15 # Prints usage information. | 17 # Prints usage information. |
16 usage() { | 18 usage() { |
17 echo "Usage: $(basename "${0}")" \ | 19 echo "Usage: $(basename "${0}")" \ |
18 "<path to clang>" \ | 20 "<path to clang>" \ |
19 "<path to plugin>" | 21 "<path to plugin>" |
20 echo "" | 22 echo "" |
21 echo " Runs all the libFindBadConstructs unit tests" | 23 echo " Runs all the libFindBadConstructs unit tests" |
22 echo "" | 24 echo "" |
23 } | 25 } |
24 | 26 |
25 # Runs a single test case. | 27 # Runs a single test case. |
26 do_testcase() { | 28 do_testcase() { |
27 local flags="" | 29 local flags="" |
28 if [ -e "${3}" ]; then | 30 if [ -e "${3}" ]; then |
29 flags="$(cat "${3}")" | 31 flags="$(cat "${3}")" |
30 fi | 32 fi |
31 | 33 |
32 if [ "$(uname -s)" = "Darwin" ]; then | 34 if [ "$(uname -s)" = "Darwin" ]; then |
33 flags="${flags} -isysroot $(xcrun --show-sdk-path) -stdlib=libstdc++" | 35 flags="${flags} -isysroot $(xcrun --show-sdk-path) -stdlib=libstdc++" |
34 fi | 36 fi |
35 | 37 |
36 flags="${flags} -Xclang -plugin-arg-find-bad-constructs \ | 38 flags="${flags} -Xclang -plugin-arg-find-bad-constructs \ |
37 -Xclang with-ast-visitor" | 39 -Xclang with-ast-visitor" |
38 | 40 |
39 local output="$("${CLANG_PATH}" -fsyntax-only -Wno-c++11-extensions \ | 41 local output="$("${CLANG_PATH}" -fsyntax-only -Wno-c++11-extensions \ |
40 -Wno-inconsistent-missing-override \ | 42 -Wno-inconsistent-missing-override \ |
| 43 -isystem ${THIS_DIR}/system \ |
41 -Xclang -load -Xclang "${PLUGIN_PATH}" \ | 44 -Xclang -load -Xclang "${PLUGIN_PATH}" \ |
42 -Xclang -add-plugin -Xclang find-bad-constructs ${flags} ${1} 2>&1)" | 45 -Xclang -add-plugin -Xclang find-bad-constructs ${flags} ${1} 2>&1)" |
43 local diffout="$(echo "${output}" | diff - "${2}")" | 46 local diffout="$(echo "${output}" | diff - "${2}")" |
44 if [ "${diffout}" = "" ]; then | 47 if [ "${diffout}" = "" ]; then |
45 echo "PASS: ${1}" | 48 echo "PASS: ${1}" |
46 else | 49 else |
47 failed_any_test=yes | 50 failed_any_test=yes |
48 echo "FAIL: ${1}" | 51 echo "FAIL: ${1}" |
49 echo "Output of compiler:" | 52 echo "Output of compiler:" |
50 echo "${output}" | 53 echo "${output}" |
(...skipping 23 matching lines...) Expand all Loading... |
74 usage | 77 usage |
75 exit ${E_BADARGS} | 78 exit ${E_BADARGS} |
76 else | 79 else |
77 export CLANG_PATH="${1}" | 80 export CLANG_PATH="${1}" |
78 export PLUGIN_PATH="${2}" | 81 export PLUGIN_PATH="${2}" |
79 echo "Using clang ${CLANG_PATH}..." | 82 echo "Using clang ${CLANG_PATH}..." |
80 echo "Using plugin ${PLUGIN_PATH}..." | 83 echo "Using plugin ${PLUGIN_PATH}..." |
81 | 84 |
82 # The golden files assume that the cwd is this directory. To make the script | 85 # The golden files assume that the cwd is this directory. To make the script |
83 # work no matter what the cwd is, explicitly cd to there. | 86 # work no matter what the cwd is, explicitly cd to there. |
84 cd "$(dirname "${0}")" | 87 cd "${THIS_DIR}" |
85 fi | 88 fi |
86 | 89 |
87 for input in *.cpp; do | 90 for input in *.cpp; do |
88 do_testcase "${input}" "${input%cpp}txt" "${input%cpp}flags" | 91 do_testcase "${input}" "${input%cpp}txt" "${input%cpp}flags" |
89 done | 92 done |
90 | 93 |
91 for input in *.c; do | 94 for input in *.c; do |
92 do_testcase "${input}" "${input%c}txt" "${input%c}flags" | 95 do_testcase "${input}" "${input%c}txt" "${input%c}flags" |
93 done | 96 done |
94 | 97 |
95 if [[ "${failed_any_test}" ]]; then | 98 if [[ "${failed_any_test}" ]]; then |
96 exit ${E_FAILEDTEST} | 99 exit ${E_FAILEDTEST} |
97 fi | 100 fi |
OLD | NEW |