michael@0: #!/bin/bash michael@0: # michael@0: # Copyright (c) 2011 The Chromium Authors. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: # michael@0: # Hacky, primitive testing: This runs the style plugin for a set of input files michael@0: # and compares the output with golden result files. michael@0: michael@0: E_BADARGS=65 michael@0: E_FAILEDTEST=1 michael@0: michael@0: failed_any_test= michael@0: michael@0: # Prints usage information. michael@0: usage() { michael@0: echo "Usage: $(basename "${0}")" \ michael@0: "" michael@0: echo "" michael@0: echo " Runs all the libFindBadConstructs unit tests" michael@0: echo "" michael@0: } michael@0: michael@0: # Runs a single test case. michael@0: do_testcase() { michael@0: local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \ michael@0: -Xclang -load -Xclang "${CLANG_DIR}"/lib/libFindBadConstructs.${LIB} \ michael@0: -Xclang -plugin -Xclang find-bad-constructs ${1} 2>&1)" michael@0: local diffout="$(echo "${output}" | diff - "${2}")" michael@0: if [ "${diffout}" = "" ]; then michael@0: echo "PASS: ${1}" michael@0: else michael@0: failed_any_test=yes michael@0: echo "FAIL: ${1}" michael@0: echo "Output of compiler:" michael@0: echo "${output}" michael@0: echo "Expected output:" michael@0: cat "${2}" michael@0: echo michael@0: fi michael@0: } michael@0: michael@0: # Validate input to the script. michael@0: if [[ -z "${1}" ]]; then michael@0: usage michael@0: exit ${E_BADARGS} michael@0: elif [[ ! -d "${1}" ]]; then michael@0: echo "${1} is not a directory." michael@0: usage michael@0: exit ${E_BADARGS} michael@0: else michael@0: export CLANG_DIR="${PWD}/${1}" michael@0: echo "Using clang directory ${CLANG_DIR}..." michael@0: michael@0: # The golden files assume that the cwd is this directory. To make the script michael@0: # work no matter what the cwd is, explicitly cd to there. michael@0: cd "$(dirname "${0}")" michael@0: michael@0: if [ "$(uname -s)" = "Linux" ]; then michael@0: export LIB=so michael@0: elif [ "$(uname -s)" = "Darwin" ]; then michael@0: export LIB=dylib michael@0: fi michael@0: fi michael@0: michael@0: for input in *.cpp; do michael@0: do_testcase "${input}" "${input%cpp}txt" michael@0: done michael@0: michael@0: if [[ "${failed_any_test}" ]]; then michael@0: exit ${E_FAILEDTEST} michael@0: fi