2014-04-09 22:17:23 +08:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Run clang-tidy in fix mode and verify the result.
|
2014-08-06 18:17:55 +08:00
|
|
|
# Usage:
|
|
|
|
# check_clang_tidy_fix.sh <source-file> <check-name> <temp-file> \
|
|
|
|
# [optional compiler arguments]
|
|
|
|
#
|
|
|
|
# Example:
|
2014-09-26 20:44:30 +08:00
|
|
|
# // RUN: $(dirname %s)/check_clang_tidy_fix.sh %s llvm-include-order %t -- -isystem $(dirname %s)/Inputs/Headers
|
2014-08-06 18:17:55 +08:00
|
|
|
# // REQUIRES: shell
|
2014-04-09 22:17:23 +08:00
|
|
|
|
|
|
|
INPUT_FILE=$1
|
|
|
|
CHECK_TO_RUN=$2
|
|
|
|
TEMPORARY_FILE=$3.cpp
|
2014-09-26 20:44:30 +08:00
|
|
|
# Feed the rest arguments to clang-tidy.
|
2014-08-06 16:19:30 +08:00
|
|
|
shift 3
|
2014-09-26 20:44:30 +08:00
|
|
|
if [ "$#" -eq 0 ] ; then
|
|
|
|
# Default to -- --std=c++11
|
|
|
|
set - -- --std=c++11
|
2014-09-22 07:39:28 +08:00
|
|
|
fi
|
2014-04-09 22:17:23 +08:00
|
|
|
|
2014-08-06 18:17:55 +08:00
|
|
|
set -o errexit
|
|
|
|
|
2014-07-10 05:09:26 +08:00
|
|
|
# Remove the contents of the CHECK lines to avoid CHECKs matching on themselves.
|
|
|
|
# We need to keep the comments to preserve line numbers while avoiding empty
|
|
|
|
# lines which could potentially trigger formatting-related checks.
|
2014-09-18 20:53:13 +08:00
|
|
|
sed 's#// *CHECK-[A-Z-]*:.*#//#' ${INPUT_FILE} > ${TEMPORARY_FILE}
|
2014-07-11 21:44:51 +08:00
|
|
|
|
2014-09-26 20:44:30 +08:00
|
|
|
clang-tidy ${TEMPORARY_FILE} -fix --checks="-*,${CHECK_TO_RUN}" "$@" \
|
|
|
|
> ${TEMPORARY_FILE}.msg 2>&1
|
2014-07-11 21:44:51 +08:00
|
|
|
|
|
|
|
FileCheck -input-file=${TEMPORARY_FILE} ${INPUT_FILE} \
|
2014-08-06 18:17:55 +08:00
|
|
|
-check-prefix=CHECK-FIXES -strict-whitespace
|
2014-07-11 21:44:51 +08:00
|
|
|
|
2014-07-10 05:09:26 +08:00
|
|
|
if grep -q CHECK-MESSAGES ${INPUT_FILE}; then
|
2014-07-11 21:44:51 +08:00
|
|
|
FileCheck -input-file=${TEMPORARY_FILE}.msg ${INPUT_FILE} \
|
2014-08-06 18:17:55 +08:00
|
|
|
-check-prefix=CHECK-MESSAGES -implicit-check-not="{{warning|error}}:"
|
2014-07-09 00:15:48 +08:00
|
|
|
fi
|