glib/tests/lint-common.sh
Simon McVittie d7601f7eed Incorporate some lint checks into meson test
This will make it easier and more obvious for developers to run them
locally: I'm sure I'm not the only developer who had assumed that
`.gitlab-ci/` is private to the CI environment and inappropriate (or
perhaps even destructive) to run on a developer/user system.

The lint checks are automatically skipped (with TAP SKIP syntax) if we
are not in a git checkout, or if git or the lint tool is missing. They
can also be disabled explicitly with `meson test --no-suite=lint`,
which downstream distributions will probably want to do.

By default, most lint checks are reported as an "expected failure"
(with TAP TODO syntax) rather than a hard failure, because they do not
indicate a functional problem with GLib and there is a tendency for
lint tools to introduce additional checks or become more strict over
time. Developers can override this by configuring with `-Dwerror=true`
(which also makes compiler warnings into fatal errors), or by running
the test suite like `LINT_WARNINGS_ARE_ERRORS=1 meson test --suite=lint`.

One exception to this is tests/check-missing-install-tag.py, which is
checking a functionally significant feature of our build system, and
seems like it is unlikely to have false positives: if that one fails,
it is reported as a hard failure.

run-style-check-diff.sh and run-check-todos.sh are not currently given
this treatment, because they require search-common-ancestor.sh, which
uses Gitlab-CI-specific information to find out which commits are in-scope
for checking.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-08 00:18:23 +00:00

47 lines
947 B
Bash

#!/usr/bin/env bash
# Copyright 2016-2018 Simon McVittie
# Copyright 2018-2024 Collabora Ltd.
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eu
skip_all () {
echo "1..0 # SKIP $*"
exit 0
}
main () {
local need_git=
local tool
cd "$G_TEST_SRCDIR/.."
echo "TAP version 13"
# shellcheck disable=SC2046
for tool in ${TEST_REQUIRES_TOOLS-}; do
command -v "$tool" >/dev/null || skip_all "$tool not found"
if [ "$tool" = git ]; then
need_git=1
fi
done
if [ -n "${need_git-}" ] && ! test -e .git; then
skip_all "not a git checkout"
fi
echo "1..1"
if run_lint >&2; then
echo "ok 1"
exit 0
elif [ -n "${LINT_WARNINGS_ARE_ERRORS-}" ]; then
echo "not ok 1 - warnings from ${TEST_NAME-"lint tool"}"
exit 1
else
echo "not ok 1 # TO""DO warnings from ${TEST_NAME-"lint tool"}"
exit 0
fi
}
main