Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 #!/bin/bash
2 #
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.
6 #
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 the llvm build dir, usually Release+Asserts>"
19 echo ""
20 echo " Runs all the libFindBadConstructs unit tests"
21 echo ""
22 }
24 # Runs a single test case.
25 do_testcase() {
26 local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \
27 -Xclang -load -Xclang "${CLANG_DIR}"/lib/libFindBadConstructs.${LIB} \
28 -Xclang -plugin -Xclang find-bad-constructs ${1} 2>&1)"
29 local diffout="$(echo "${output}" | diff - "${2}")"
30 if [ "${diffout}" = "" ]; then
31 echo "PASS: ${1}"
32 else
33 failed_any_test=yes
34 echo "FAIL: ${1}"
35 echo "Output of compiler:"
36 echo "${output}"
37 echo "Expected output:"
38 cat "${2}"
39 echo
40 fi
41 }
43 # Validate input to the script.
44 if [[ -z "${1}" ]]; then
45 usage
46 exit ${E_BADARGS}
47 elif [[ ! -d "${1}" ]]; then
48 echo "${1} is not a directory."
49 usage
50 exit ${E_BADARGS}
51 else
52 export CLANG_DIR="${PWD}/${1}"
53 echo "Using clang directory ${CLANG_DIR}..."
55 # The golden files assume that the cwd is this directory. To make the script
56 # work no matter what the cwd is, explicitly cd to there.
57 cd "$(dirname "${0}")"
59 if [ "$(uname -s)" = "Linux" ]; then
60 export LIB=so
61 elif [ "$(uname -s)" = "Darwin" ]; then
62 export LIB=dylib
63 fi
64 fi
66 for input in *.cpp; do
67 do_testcase "${input}" "${input%cpp}txt"
68 done
70 if [[ "${failed_any_test}" ]]; then
71 exit ${E_FAILEDTEST}
72 fi