Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / tools / clang / plugins / tests / test.sh
blobcf262522eb855e291b8f769638bcddce0e9f7114
1 #!/bin/bash
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.
10 E_BADARGS=65
11 E_FAILEDTEST=1
13 failed_any_test=
15 THIS_DIR="$(dirname "${0}")"
17 # Prints usage information.
18 usage() {
19 echo "Usage: $(basename "${0}")" \
20 "<path to clang>" \
21 "<path to plugin>"
22 echo ""
23 echo " Runs all the libFindBadConstructs unit tests"
24 echo ""
27 # Runs a single test case.
28 do_testcase() {
29 local flags=""
30 if [ -e "${3}" ]; then
31 flags="$(cat "${3}")"
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
48 echo "PASS: ${1}"
49 else
50 failed_any_test=yes
51 echo "FAIL: ${1}"
52 echo "Output of compiler:"
53 echo "${output}"
54 cat > ${2}-actual << EOF
55 ${output}
56 EOF
58 echo "Expected output:"
59 cat "${2}"
60 echo
64 # Validate input to the script.
65 if [[ -z "${1}" ]]; then
66 usage
67 exit ${E_BADARGS}
68 elif [[ -z "${2}" ]]; then
69 usage
70 exit ${E_BADARGS}
71 elif [[ ! -x "${1}" ]]; then
72 echo "${1} is not an executable"
73 usage
74 exit ${E_BADARGS}
75 elif [[ ! -f "${2}" ]]; then
76 echo "${2} could not be found"
77 usage
78 exit ${E_BADARGS}
79 else
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.
87 cd "${THIS_DIR}"
90 for input in *.cpp; do
91 do_testcase "${input}" "${input%cpp}txt" "${input%cpp}flags"
92 done
94 for input in *.c; do
95 do_testcase "${input}" "${input%c}txt" "${input%c}flags"
96 done
98 if [[ "${failed_any_test}" ]]; then
99 exit ${E_FAILEDTEST}