Skip to content

Commit 2e75419

Browse files
committed
Tweaks in test-all.sh
1 parent a5b4980 commit 2e75419

File tree

2 files changed

+232
-44
lines changed

2 files changed

+232
-44
lines changed

scripts/lint-all.sh

Lines changed: 153 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,174 @@
44

55
# Lint all files in the project.
66
# Expected to be run from the root of the project.
7-
# Expected tools to be installed on the system.
8-
# Usage: ./scripts/lint-all.sh
7+
# Expected tools to be installed on the system. A pre-check is done to ensure all tools are installed.
98

109
set -e
11-
set -x
1210

11+
# Base directories to lint.
1312
BASE_DIRS=(
1413
include
1514
examples
1615
scripts
1716
src
1817
)
18+
19+
# Print usage information.
20+
function usage() {
21+
echo "Usage: $0"
22+
echo " -h, --help: Display help."
23+
echo " -a, --all: Lint all files."
24+
echo " -c, --cpp: Lint C++ files."
25+
echo " -s, --shell: Lint shell scripts."
26+
echo " -m, --markdown: Lint Markdown files."
27+
echo " -y, --yaml: Lint YAML files."
28+
echo " -C, --cmake: Lint CMake files."
29+
}
30+
31+
# Parse command line arguments.
32+
function parse_args() {
33+
while [[ $# -gt 0 ]]; do
34+
case $1 in
35+
-h|--help)
36+
usage
37+
exit 0
38+
;;
39+
-a|--all)
40+
lint_all_files
41+
exit 0
42+
;;
43+
-c|--cpp)
44+
lint_cpp_files
45+
exit 0
46+
;;
47+
-s|--shell)
48+
lint_shell_files
49+
exit 0
50+
;;
51+
-m|--markdown)
52+
lint_markdown_files
53+
exit 0
54+
;;
55+
-y|--yaml)
56+
lint_yaml_files
57+
exit 0
58+
;;
59+
-C|--cmake)
60+
lint_cmake_files
61+
exit 0
62+
;;
63+
*)
64+
echo "Unknown option: $1"
65+
usage
66+
exit 1
67+
;;
68+
esac
69+
done
70+
}
71+
72+
# Check if all linters are installed.
73+
function check_linters_installed() {
74+
echo "Checking linters..."
75+
linters=(
76+
clang-format
77+
shellcheck
78+
cmake-format
79+
markdownlint
80+
yamlfmt
81+
)
82+
83+
for linter in "${linters[@]}"; do
84+
echo " -> ${linter}..."
85+
if ! command -v "${linter}" &> /dev/null; then
86+
echo "${linter} could not be found."
87+
exit 1
88+
fi
89+
done
90+
echo "Checking linters finished: all linters installed."
91+
echo ""
92+
}
93+
1994
# Lint all C++ files in the project.
20-
CPP_DIRS=(
21-
"${BASE_DIRS[@]}"
22-
)
23-
find -E "${CPP_DIRS[@]}" -regex '.*\.(h|hpp|hxx|cpp|c|cxx)' | xargs clang-format -i -style=file || echo "clang-format failed."
24-
echo "All C++ files were linted."
95+
function lint_cpp_files() {
96+
echo "Linting C++ files..."
2597

26-
# Lint all scripts in the project.
27-
SHELL_DIRS=(
28-
"${BASE_DIRS[@]}"
29-
)
30-
find -E "${SHELL_DIRS[@]}" -regex '.*\.(sh)' | xargs shellcheck || echo "shellcheck failed."
31-
echo "All scripts files were linted."
98+
CPP_DIRS=(
99+
"${BASE_DIRS[@]}"
100+
)
101+
find -E "${CPP_DIRS[@]}" -regex '.*\.(h|hpp|hxx|cpp|c|cxx)' | xargs clang-format -i -style=file || echo "clang-format failed."
102+
103+
echo "Done."
104+
echo ""
105+
}
106+
107+
# Lint all shell files in the project.
108+
function lint_shell_files() {
109+
echo "Linting shell files..."
110+
111+
SHELL_DIRS=(
112+
"${BASE_DIRS[@]}"
113+
)
114+
find -E "${SHELL_DIRS[@]}" -regex '.*\.(sh)' | xargs shellcheck || echo "shellcheck failed."
115+
116+
echo "Done."
117+
echo ""
118+
}
32119

33120
# Lint all CMake files in the project.
34-
CMAKE_DIRS=(
35-
CMakeLists.txt
36-
"${BASE_DIRS[@]}"
37-
cmake
38-
)
39-
find -E "${CMAKE_DIRS[@]}" -regex '.*CMakeLists\.txt' | xargs cmake-format -i || echo "cmake-format failed."
40-
echo "All CMake files were linted."
121+
function lint_cmake_files() {
122+
echo "Linting CMake files..."
123+
124+
CMAKE_DIRS=(
125+
CMakeLists.txt
126+
"${BASE_DIRS[@]}"
127+
cmake
128+
)
129+
find -E "${CMAKE_DIRS[@]}" -regex '.*CMakeLists\.txt' | xargs cmake-format -i || echo "cmake-format failed."
130+
131+
echo "Done."
132+
echo ""
133+
}
41134

42135
# Lint all Markdown files in the project.
43-
MD_DIRS=(
44-
README.md
45-
"${BASE_DIRS[@]}"
46-
papers/P2988/README.md
47-
)
48-
find -E "${MD_DIRS[@]}" -regex '.*\.(md)' | xargs markdownlint -f || echo "markdownlint failed."
49-
echo "All Markdown files were linted."
136+
function lint_markdown_files() {
137+
echo "Linting Markdown files..."
138+
139+
MD_DIRS=(
140+
README.md
141+
"${BASE_DIRS[@]}"
142+
papers/P2988/README.md
143+
)
144+
find -E "${MD_DIRS[@]}" -regex '.*\.(md)' | xargs markdownlint -f || echo "markdownlint failed."
145+
146+
echo "Done."
147+
echo ""
148+
}
50149

51150
# Lint all YAML files in the project.
52-
YAML_DIRS=(
53-
.github/
54-
"${BASE_DIRS[@]}"
55-
)
56-
find -E "${YAML_DIRS[@]}" -regex '.*\.(yml)' | xargs yamlfmt || echo "yamlfmt failed."
57-
echo "All YAML files were linted."
151+
function lint_yaml_files() {
152+
echo "Linting YAML files..."
153+
154+
YAML_DIRS=(
155+
.github/
156+
"${BASE_DIRS[@]}"
157+
)
158+
find -E "${YAML_DIRS[@]}" -regex '.*\.(yml)' | xargs yamlfmt || echo "yamlfmt failed."
159+
160+
echo "Done."
161+
echo ""
162+
}
163+
164+
# Lint all files in the project.
165+
function lint_all_files() {
166+
check_linters_installed || exit 1
167+
168+
lint_cpp_files || exit 1
169+
lint_shell_files || exit 1
170+
lint_cmake_files || exit 1
171+
lint_markdown_files || exit 1
172+
lint_yaml_files || exit 1
173+
174+
echo "All linters finished."
175+
}
58176

59-
echo "All linters finished."
177+
parse_args "$@"

scripts/test-all.sh

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,89 @@
22

33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
# Test all configurations: gcc-14, gcc-13, clang-18, clang-17.
5+
# Run tests on all known toolchains.
66
# Expected to be run from the root of the project.
77
# Expected all configurations to be present in the CMakeLists.txt file and installed on the system.
8-
# Usage: ./scripts/test-all.sh
98

109
set -e
11-
set -x
1210

13-
rm -rf .build
11+
# Toolchains to test.
12+
TOOLCHAINS=(
13+
gcc-14
14+
gcc-13
15+
clang-19
16+
clang-18
17+
clang-17
18+
)
1419

15-
cmake --workflow --preset gcc-14 &> /dev/null && echo "passed" || echo "gcc-14 test failed."
16-
cmake --workflow --preset gcc-13 &> /dev/null && echo "passed" || echo "gcc-13 test failed."
17-
cmake --workflow --preset clang-18 &> /dev/null && echo "passed" || echo "clang-18 test failed."
18-
cmake --workflow --preset clang-17 &> /dev/null && echo "passed" || echo "clang-17 test failed."
20+
# Build directory.
21+
BUILD_DIR=".build"
1922

20-
echo "All tests passed."
23+
# Print usage information.
24+
function usage() {
25+
echo "Usage: $0"
26+
echo " -h, --help: Display help."
27+
echo " -v, --verbose: Display verbose output."
28+
echo " -f, --fresh: Run tests on a fresh build directory."
29+
}
30+
31+
# Parse command line arguments.
32+
function parse_args() {
33+
while [[ $# -gt 0 ]]; do
34+
case $1 in
35+
-h|--help)
36+
usage
37+
exit 0
38+
;;
39+
-v|--verbose)
40+
VERBOSE=true
41+
shift
42+
;;
43+
-f|--fresh)
44+
FRESH=true
45+
shift
46+
;;
47+
*)
48+
echo "Unknown option: $1"
49+
usage
50+
exit 1
51+
;;
52+
esac
53+
done
54+
55+
}
56+
57+
# Run tests with a specific toolchain.
58+
function test_with_toolchain() {
59+
toolchain=$1
60+
echo "Testing with ${toolchain}..."
61+
62+
cmd="cmake --workflow --preset ${toolchain}"
63+
if [ ! "$VERBOSE" ]; then
64+
cmd+="&> /dev/null"
65+
fi
66+
67+
if ! eval "${cmd}"; then
68+
echo " -> failed"
69+
exit 1
70+
else
71+
echo " -> passed"
72+
fi
73+
}
74+
75+
# Run tests with all toolchains.
76+
function test_all_toolchains() {
77+
if [ "$FRESH" ]; then
78+
echo " -> cleaning build directory"
79+
rm -rf "${BUILD_DIR}"
80+
fi
81+
82+
for toolchain in "${TOOLCHAINS[@]}"; do
83+
test_with_toolchain "${toolchain}"
84+
done
85+
86+
echo "All tests passed on all toolchains."
87+
}
88+
89+
parse_args "$@"
90+
test_all_toolchains

0 commit comments

Comments
 (0)