22
33bats_require_minimum_version 1.5.0
44
5- setup_file () {
6- # Installing the Windows SDK/CRT takes a long time.
7- # When still valid, use the installation from cache.
8-
9- xwin --accept-license --manifest-version 16 --cache-dir ${BATS_TEST_DIRNAME} /.xwin-hash list
10- local HASH_LIST_MANIFEST=$( sha256sum ${BATS_TEST_DIRNAME} /.xwin-hash/dl/manifest* .json | awk ' { print $1 }' )
11- local HASH_CACHED_MANIFEST=
12-
13- if [[ -d ${BATS_TEST_DIRNAME} /.xwin-cache/dl ]]; then
14- HASH_CACHED_MANIFEST=$( sha256sum ${BATS_TEST_DIRNAME} /.xwin-cache/dl/manifest* .json | awk ' { print $1 }' )
15- fi
16-
17- if [[ $HASH_LIST_MANIFEST != $HASH_CACHED_MANIFEST ]]; then
18- xwin --accept-license --manifest-version 16 --cache-dir ${BATS_TEST_DIRNAME} /.xwin-cache splat --preserve-ms-arch-notation
19- fi
20-
21- ln -sf ${BATS_TEST_DIRNAME} /.xwin-cache/splat/ /winsdk
22- }
23-
245teardown_file () {
256 rm -rf ${BATS_TEST_DIRNAME} /.xwin-hash/ /winsdk
267}
@@ -38,6 +19,34 @@ teardown() {
3819 popd
3920}
4021
22+ # # This section contains tests for version correctness and compatibility of the installed tools.
23+ # Comparing the versions of the installed tools with the expected versions and ensuring
24+ # that the tools are compatible with each other. E.g. that the host and embedded toolchains
25+ # are aligned in terms of major and minor versions.
26+
27+ @test " host clang toolchain versions and alternatives should be aligned with expected versions" {
28+ EXPECTED_VERSION=$( get_expected_version_for clang | sed -E ' s/^[0-9]+://' | cut -d ' ~' -f1)
29+
30+ for TOOL in clang clang++; do
31+ INSTALLED_VERSION=$( $TOOL -dumpversion)
32+ assert_equal $INSTALLED_VERSION $EXPECTED_VERSION
33+ done
34+
35+ for TOOL in clang-cl clang-format clang-tidy; do
36+ INSTALLED_VERSION=$( $TOOL --version | grep -o ' [0-9]\+\.[0-9]\+\.[0-9]\+' | head -n1)
37+ assert_equal $INSTALLED_VERSION $EXPECTED_VERSION
38+ done
39+ }
40+
41+ @test " all tool versions should be aligned with the expected version" {
42+ for TOOL in git ninja; do
43+ EXPECTED_VERSION=$( get_expected_version_for ${TOOL} | sed -E ' s/^[0-9]+://' | cut -d ' ~' -f1)
44+ INSTALLED_VERSION=$( ${TOOL} --version | grep -o ' [0-9]\+\.[0-9]\+\.[0-9]\+' | head -n1)
45+
46+ assert_equal $INSTALLED_VERSION $EXPECTED_VERSION
47+ done
48+ }
49+
4150@test " host gcc toolchain versions and alternatives should be aligned with expected versions" {
4251 EXPECTED_VERSION=$( get_expected_version_for g++)
4352
@@ -75,6 +84,8 @@ teardown() {
7584}
7685
7786@test " valid code input should result in Windows executable using clang-cl compiler" {
87+ install_win_sdk
88+
7889 cmake --preset clang-cl
7990 cmake --build --preset clang-cl
8091}
@@ -97,6 +108,8 @@ teardown() {
97108}
98109
99110@test " using ccache as a compiler launcher should result in cached build using clang-cl compiler" {
111+ install_win_sdk
112+
100113 configure_and_build_with_ccache clang-cl
101114}
102115
@@ -255,3 +268,22 @@ function get_expected_version_for() {
255268 ${BATS_TEST_DIRNAME} /../../.devcontainer/cpp/apt-requirements-base.json \
256269 ${BATS_TEST_DIRNAME} /../../.devcontainer/cpp/apt-requirements-clang.json
257270}
271+
272+ function install_win_sdk() {
273+ # Installing the Windows SDK/CRT takes a long time.
274+ # When still valid, use the installation from cache.
275+
276+ xwin --accept-license --manifest-version 16 --cache-dir ${BATS_TEST_DIRNAME} /.xwin-hash list
277+ local HASH_LIST_MANIFEST=$( sha256sum ${BATS_TEST_DIRNAME} /.xwin-hash/dl/manifest* .json | awk ' { print $1 }' )
278+ local HASH_CACHED_MANIFEST=
279+
280+ if [[ -d ${BATS_TEST_DIRNAME} /.xwin-cache/dl ]]; then
281+ HASH_CACHED_MANIFEST=$( sha256sum ${BATS_TEST_DIRNAME} /.xwin-cache/dl/manifest* .json | awk ' { print $1 }' )
282+ fi
283+
284+ if [[ $HASH_LIST_MANIFEST != $HASH_CACHED_MANIFEST ]]; then
285+ xwin --accept-license --manifest-version 16 --cache-dir ${BATS_TEST_DIRNAME} /.xwin-cache splat --preserve-ms-arch-notation
286+ fi
287+
288+ ln -sf ${BATS_TEST_DIRNAME} /.xwin-cache/splat/ /winsdk
289+ }
0 commit comments