media/webrtc/trunk/tools/clang/plugins/tests/test.sh

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rwxr-xr-x

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 #!/bin/bash
michael@0 2 #
michael@0 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
michael@0 4 # Use of this source code is governed by a BSD-style license that can be
michael@0 5 # found in the LICENSE file.
michael@0 6 #
michael@0 7 # Hacky, primitive testing: This runs the style plugin for a set of input files
michael@0 8 # and compares the output with golden result files.
michael@0 9
michael@0 10 E_BADARGS=65
michael@0 11 E_FAILEDTEST=1
michael@0 12
michael@0 13 failed_any_test=
michael@0 14
michael@0 15 # Prints usage information.
michael@0 16 usage() {
michael@0 17 echo "Usage: $(basename "${0}")" \
michael@0 18 "<Path to the llvm build dir, usually Release+Asserts>"
michael@0 19 echo ""
michael@0 20 echo " Runs all the libFindBadConstructs unit tests"
michael@0 21 echo ""
michael@0 22 }
michael@0 23
michael@0 24 # Runs a single test case.
michael@0 25 do_testcase() {
michael@0 26 local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \
michael@0 27 -Xclang -load -Xclang "${CLANG_DIR}"/lib/libFindBadConstructs.${LIB} \
michael@0 28 -Xclang -plugin -Xclang find-bad-constructs ${1} 2>&1)"
michael@0 29 local diffout="$(echo "${output}" | diff - "${2}")"
michael@0 30 if [ "${diffout}" = "" ]; then
michael@0 31 echo "PASS: ${1}"
michael@0 32 else
michael@0 33 failed_any_test=yes
michael@0 34 echo "FAIL: ${1}"
michael@0 35 echo "Output of compiler:"
michael@0 36 echo "${output}"
michael@0 37 echo "Expected output:"
michael@0 38 cat "${2}"
michael@0 39 echo
michael@0 40 fi
michael@0 41 }
michael@0 42
michael@0 43 # Validate input to the script.
michael@0 44 if [[ -z "${1}" ]]; then
michael@0 45 usage
michael@0 46 exit ${E_BADARGS}
michael@0 47 elif [[ ! -d "${1}" ]]; then
michael@0 48 echo "${1} is not a directory."
michael@0 49 usage
michael@0 50 exit ${E_BADARGS}
michael@0 51 else
michael@0 52 export CLANG_DIR="${PWD}/${1}"
michael@0 53 echo "Using clang directory ${CLANG_DIR}..."
michael@0 54
michael@0 55 # The golden files assume that the cwd is this directory. To make the script
michael@0 56 # work no matter what the cwd is, explicitly cd to there.
michael@0 57 cd "$(dirname "${0}")"
michael@0 58
michael@0 59 if [ "$(uname -s)" = "Linux" ]; then
michael@0 60 export LIB=so
michael@0 61 elif [ "$(uname -s)" = "Darwin" ]; then
michael@0 62 export LIB=dylib
michael@0 63 fi
michael@0 64 fi
michael@0 65
michael@0 66 for input in *.cpp; do
michael@0 67 do_testcase "${input}" "${input%cpp}txt"
michael@0 68 done
michael@0 69
michael@0 70 if [[ "${failed_any_test}" ]]; then
michael@0 71 exit ${E_FAILEDTEST}
michael@0 72 fi

mercurial