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 if [ "$(uname -s)" = "Darwin" ]; then
35 flags
="${flags} -isysroot $(xcrun --show-sdk-path) -stdlib=libstdc++"
38 flags
="${flags} -Xclang -plugin-arg-find-bad-constructs \
39 -Xclang with-ast-visitor"
41 local output
="$("${CLANG_PATH}" -fsyntax-only -Wno-c++11-extensions \
42 -Wno-inconsistent-missing-override \
43 -isystem ${THIS_DIR}/system \
44 -Xclang -load -Xclang "${PLUGIN_PATH}" \
45 -Xclang -add-plugin -Xclang find-bad-constructs ${flags} ${1} 2>&1)"
46 local diffout
="$(echo "${output}" | diff - "${2}")"
47 if [ "${diffout}" = "" ]; then
52 echo "Output of compiler:"
54 cat > ${2}-actual << EOF
58 echo "Expected output:"
64 # Validate input to the script.
65 if [[ -z "${1}" ]]; then
68 elif [[ -z "${2}" ]]; then
71 elif [[ ! -x "${1}" ]]; then
72 echo "${1} is not an executable"
75 elif [[ ! -f "${2}" ]]; then
76 echo "${2} could not be found"
80 export CLANG_PATH
="${1}"
81 export PLUGIN_PATH
="${2}"
82 echo "Using clang ${CLANG_PATH}..."
83 echo "Using plugin ${PLUGIN_PATH}..."
85 # The golden files assume that the cwd is this directory. To make the script
86 # work no matter what the cwd is, explicitly cd to there.
90 for input
in *.cpp
; do
91 do_testcase
"${input}" "${input%cpp}txt" "${input%cpp}flags"
95 do_testcase
"${input}" "${input%c}txt" "${input%c}flags"
98 if [[ "${failed_any_test}" ]]; then