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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/webrtc/trunk/tools/clang/plugins/tests/test.sh	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +#!/bin/bash
     1.5 +#
     1.6 +# Copyright (c) 2011 The Chromium Authors. All rights reserved.
     1.7 +# Use of this source code is governed by a BSD-style license that can be
     1.8 +# found in the LICENSE file.
     1.9 +#
    1.10 +# Hacky, primitive testing: This runs the style plugin for a set of input files
    1.11 +# and compares the output with golden result files.
    1.12 +
    1.13 +E_BADARGS=65
    1.14 +E_FAILEDTEST=1
    1.15 +
    1.16 +failed_any_test=
    1.17 +
    1.18 +# Prints usage information.
    1.19 +usage() {
    1.20 +  echo "Usage: $(basename "${0}")" \
    1.21 +    "<Path to the llvm build dir, usually Release+Asserts>"
    1.22 +  echo ""
    1.23 +  echo "  Runs all the libFindBadConstructs unit tests"
    1.24 +  echo ""
    1.25 +}
    1.26 +
    1.27 +# Runs a single test case.
    1.28 +do_testcase() {
    1.29 +  local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \
    1.30 +      -Xclang -load -Xclang "${CLANG_DIR}"/lib/libFindBadConstructs.${LIB} \
    1.31 +      -Xclang -plugin -Xclang find-bad-constructs ${1} 2>&1)"
    1.32 +  local diffout="$(echo "${output}" | diff - "${2}")"
    1.33 +  if [ "${diffout}" = "" ]; then
    1.34 +    echo "PASS: ${1}"
    1.35 +  else
    1.36 +    failed_any_test=yes
    1.37 +    echo "FAIL: ${1}"
    1.38 +    echo "Output of compiler:"
    1.39 +    echo "${output}"
    1.40 +    echo "Expected output:"
    1.41 +    cat "${2}"
    1.42 +    echo
    1.43 +  fi
    1.44 +}
    1.45 +
    1.46 +# Validate input to the script.
    1.47 +if [[ -z "${1}" ]]; then
    1.48 +  usage
    1.49 +  exit ${E_BADARGS}
    1.50 +elif [[ ! -d "${1}" ]]; then
    1.51 +  echo "${1} is not a directory."
    1.52 +  usage
    1.53 +  exit ${E_BADARGS}
    1.54 +else
    1.55 +  export CLANG_DIR="${PWD}/${1}"
    1.56 +  echo "Using clang directory ${CLANG_DIR}..."
    1.57 +
    1.58 +  # The golden files assume that the cwd is this directory. To make the script
    1.59 +  # work no matter what the cwd is, explicitly cd to there.
    1.60 +  cd "$(dirname "${0}")"
    1.61 +
    1.62 +  if [ "$(uname -s)" = "Linux" ]; then
    1.63 +    export LIB=so
    1.64 +  elif [ "$(uname -s)" = "Darwin" ]; then
    1.65 +    export LIB=dylib
    1.66 +  fi
    1.67 +fi
    1.68 +
    1.69 +for input in *.cpp; do
    1.70 +  do_testcase "${input}" "${input%cpp}txt"
    1.71 +done
    1.72 +
    1.73 +if [[ "${failed_any_test}" ]]; then
    1.74 +  exit ${E_FAILEDTEST}
    1.75 +fi

mercurial