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 # Prints usage information.
17 echo "Usage: $(basename "${0}")" \
21 echo " Runs all the libFindBadConstructs unit tests"
25 # Runs a single test case.
28 if [ -e "${3}" ]; then
32 if [ "$(uname -s)" = "Darwin" ]; then
33 flags
="${flags} -isysroot $(xcrun --show-sdk-path) -stdlib=libstdc++"
36 flags
="${flags} -Xclang -plugin-arg-find-bad-constructs \
37 -Xclang with-ast-visitor"
39 local output
="$("${CLANG_PATH}" -fsyntax-only -Wno-c++11-extensions \
40 -Wno-inconsistent-missing-override \
41 -Xclang -load -Xclang "${PLUGIN_PATH}" \
42 -Xclang -add-plugin -Xclang find-bad-constructs ${flags} ${1} 2>&1)"
43 local diffout
="$(echo "${output}" | diff - "${2}")"
44 if [ "${diffout}" = "" ]; then
49 echo "Output of compiler:"
51 cat > ${2}-actual << EOF
55 echo "Expected output:"
61 # Validate input to the script.
62 if [[ -z "${1}" ]]; then
65 elif [[ -z "${2}" ]]; then
68 elif [[ ! -x "${1}" ]]; then
69 echo "${1} is not an executable"
72 elif [[ ! -f "${2}" ]]; then
73 echo "${2} could not be found"
77 export CLANG_PATH
="${1}"
78 export PLUGIN_PATH
="${2}"
79 echo "Using clang ${CLANG_PATH}..."
80 echo "Using plugin ${PLUGIN_PATH}..."
82 # 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.
84 cd "$(dirname "${0}")"
87 for input
in *.cpp
; do
88 do_testcase
"${input}" "${input%cpp}txt" "${input%cpp}flags"
92 do_testcase
"${input}" "${input%c}txt" "${input%c}flags"
95 if [[ "${failed_any_test}" ]]; then