Files
William Douglas e01b473251 Switch to clang-format as a github action
Instead of having this be a local test, have a format target for the
Makefile and use a github action for clang-format to avoid differences
between developer systems clang-format and runner clang-format
versions.

Signed-off-by: William Douglas <william.douglas@intel.com>
2023-04-25 14:44:10 -07:00

46 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bats
# Author: Otavio Pontes
# Email: otavio.pontes@intel.com
check_sort_makefile()
{
start_str="$1"
export LC_COLLATE=en_US.UTF-8
START=$(grep "$start_str" Makefile.am --line-number -m 1| cut -f1 -d:)
START=$((START + 1))
END=$(tail +"$START" Makefile.am | grep -e '^$' --line-number -m 1 | cut -f1 -d:)
END=$((END - 1))
tail -n +$START Makefile.am | head -n $END | sort -c
}
@test "ANL003: Compliant code style check" {
run git diff --quiet --exit-code src
# shellcheck disable=SC2154
# output and status variable is being assigned and exported by bats
if [ "$status" -ne 0 ]; then
echo "Error: can only check code style when src/ is clean."
echo "Stash or commit your changes and try again."
return "$status"
fi
run git grep if\ \(.*\)$ -- '*.c'
if [ "$status" -eq 0 ]; then
echo "Missing brackets in single line if:"
# shellcheck disable=SC2154
# output and status variable is being assigned and exported by bats
echo "$output"
return 1
fi
run grep -r '[[:blank:]]$' test/ src/ -l --include \*.bats --include \*.c --include \*.h
if [ "$status" -eq 0 ]; then
echo "Trailing whitespaces in files:"
echo "$output"
return 1
fi
check_sort_makefile swupd_SOURCES
check_sort_makefile "TESTS ="
}