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
5 # found in the LICENSE file.
7 # Hacky, primitive testing: This runs the style plugin for a set of input files
8 # and compares the output with golden result files.
15 THIS_DIR
="$(dirname "${0}")"
17 # Prints usage information.
19 echo "Usage: $(basename "${0}")" \
23 echo " Runs all the libFindBadConstructs unit tests"
27 # Runs a single test case.
30 if [ -e "${3}" ]; then
34 # TODO(thakis): Remove once the tests are standalone, http://crbug.com/486559
35 if [[ "$(uname -s)" == "Darwin" ]]; then
36 flags
="${flags} -isysroot $(xcrun --show-sdk-path)"
38 if [[ "$(uname -s)" == "Darwin" && "${flags}" != *-target* ]]; then
39 flags
="${flags} -stdlib=libstdc++"
42 flags
="${flags} -Xclang -plugin-arg-find-bad-constructs \
43 -Xclang with-ast-visitor"
45 local output
="$("${CLANG_PATH}" -fsyntax-only -Wno-c++11-extensions \
46 -Wno-inconsistent-missing-override \
47 -isystem ${THIS_DIR}/system \
48 -Xclang -load -Xclang "${PLUGIN_PATH}" \
49 -Xclang -add-plugin -Xclang find-bad-constructs ${flags} ${1} 2>&1)"
50 local diffout
="$(echo "${output}" | diff - "${2}")"
51 if [ "${diffout}" = "" ]; then
56 echo "Output of compiler:"
58 cat > ${2}-actual << EOF
62 echo "Expected output:"
68 # Validate input to the script.
69 if [[ -z "${1}" ]]; then
72 elif [[ -z "${2}" ]]; then
75 elif [[ ! -x "${1}" ]]; then
76 echo "${1} is not an executable"
79 elif [[ ! -f "${2}" ]]; then
80 echo "${2} could not be found"
84 export CLANG_PATH
="${1}"
85 export PLUGIN_PATH
="${2}"
86 echo "Using clang ${CLANG_PATH}..."
87 echo "Using plugin ${PLUGIN_PATH}..."
89 # The golden files assume that the cwd is this directory. To make the script
90 # work no matter what the cwd is, explicitly cd to there.
94 for input
in *.cpp
; do
95 do_testcase
"${input}" "${input%cpp}txt" "${input%cpp}flags"
99 do_testcase
"${input}" "${input%c}txt" "${input%c}flags"
102 if [[ "${failed_any_test}" ]]; then