[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / tools / clang / plugins / tests / test.sh
blobea2105446f07ace607cbed8c587b2c476ac934ca
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 # Prints usage information.
16 usage() {
17 echo "Usage: $(basename "${0}")" \
18 "<path to clang>" \
19 "<path to plugin>"
20 echo ""
21 echo " Runs all the libFindBadConstructs unit tests"
22 echo ""
25 # Runs a single test case.
26 do_testcase() {
27 local flags=""
28 if [ -e "${3}" ]; then
29 flags="$(cat "${3}")"
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
45 echo "PASS: ${1}"
46 else
47 failed_any_test=yes
48 echo "FAIL: ${1}"
49 echo "Output of compiler:"
50 echo "${output}"
51 cat > ${2}-actual << EOF
52 ${output}
53 EOF
55 echo "Expected output:"
56 cat "${2}"
57 echo
61 # Validate input to the script.
62 if [[ -z "${1}" ]]; then
63 usage
64 exit ${E_BADARGS}
65 elif [[ -z "${2}" ]]; then
66 usage
67 exit ${E_BADARGS}
68 elif [[ ! -x "${1}" ]]; then
69 echo "${1} is not an executable"
70 usage
71 exit ${E_BADARGS}
72 elif [[ ! -f "${2}" ]]; then
73 echo "${2} could not be found"
74 usage
75 exit ${E_BADARGS}
76 else
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"
89 done
91 for input in *.c; do
92 do_testcase "${input}" "${input%c}txt" "${input%c}flags"
93 done
95 if [[ "${failed_any_test}" ]]; then
96 exit ${E_FAILEDTEST}