mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-09-07 14:11:52 +00:00
clang-format changing output between versions is painful so might need to be reconsidered at some point. Signed-off-by: William Douglas <william.douglas@intel.com>
58 lines
1.7 KiB
Bash
Executable File
58 lines
1.7 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 clang-format -i -style=file src/*.[ch] src/lib/*.[ch] src/3rd_party/*.[ch] src/cmds/*.[ch] src/swupd_lib/*.[ch] src/verifytime/*.[ch]
|
|
if [ "$status" -ne 0 ]; then
|
|
echo "clang-format failed with status $status. Check if you have clang-format installed"
|
|
return "$status"
|
|
fi
|
|
|
|
run git diff --quiet --exit-code src
|
|
if [ "$status" -ne 0 ]; then
|
|
echo "Code style issues found. Run 'git diff' to view issues."
|
|
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 ="
|
|
}
|