Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove duplication in cpp testsuite #482

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .devcontainer/cpp/test/coverage/CMakeLists.txt

This file was deleted.

20 changes: 0 additions & 20 deletions .devcontainer/cpp/test/coverage/test.cpp

This file was deleted.

78 changes: 33 additions & 45 deletions .devcontainer/cpp/test/testsuite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,11 @@ teardown() {
}

@test "using ccache as a compiler launcher should result in cached build using gcc compiler" {
ccache --clear --zero-stats
cmake --preset gcc -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build --preset gcc

run ccache -s
assert_output --partial "Hits: 0"
assert_output --partial "Misses: 1"

rm -rf build
ccache --zero-stats
cmake --preset gcc -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build --preset gcc

run ccache -s
assert_output --partial "Hits: 1"
assert_output --partial "Misses: 0"
configure_and_build_with_ccache gcc
}

@test "using ccache as a compiler launcher should result in cached build using clang-cl compiler" {
ccache --clear --zero-stats
cmake --preset clang-cl -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build --preset clang-cl

run ccache -s
assert_output --partial "Hits: 0"
assert_output --partial "Misses: 1"

rm -rf build
ccache --zero-stats
cmake --preset clang-cl -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build --preset clang-cl

run ccache -s
assert_output --partial "Hits: 1"
assert_output --partial "Misses: 0"
configure_and_build_with_ccache clang-cl
}

@test "running clang-tidy as part of the build should result in warning diagnostics" {
Expand Down Expand Up @@ -193,27 +163,45 @@ teardown() {
}

@test "sanitizers should detect undefined or suspicious behavior in code compiled with gcc" {
cmake --preset gcc
cmake --build --preset gcc-sanitizers
build_and_run_with_sanitizers gcc
}

run build/gcc/sanitizers/test-asan
assert_failure
assert_output --partial "AddressSanitizer: stack-buffer-overflow"
@test "sanitizers should detect undefined or suspicious behavior in code compiled with clang" {
build_and_run_with_sanitizers clang
}

run build/gcc/sanitizers/test-ubsan
assert_failure
assert_output --partial "runtime error: load of null pointer"
function configure_and_build_with_ccache() {
local PRESET=${1:?}

ccache --clear --zero-stats
cmake --preset ${PRESET} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build --preset ${PRESET}

run ccache -s
assert_output --partial "Hits: 0"
assert_output --partial "Misses: 1"

rm -rf build
ccache --zero-stats
cmake --preset ${PRESET} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build --preset ${PRESET}

run ccache -s
assert_output --partial "Hits: 1"
assert_output --partial "Misses: 0"
}

@test "sanitizers should detect undefined or suspicious behavior in code compiled with clang" {
cmake --preset clang
cmake --build --preset clang-sanitizers
function build_and_run_with_sanitizers() {
local PRESET=${1:?}

cmake --preset ${PRESET}
cmake --build --preset ${PRESET}-sanitizers

run build/clang/sanitizers/test-asan
run build/${PRESET}/sanitizers/test-asan
assert_failure
assert_output --partial "AddressSanitizer: stack-buffer-overflow"

run build/clang/sanitizers/test-ubsan
run build/${PRESET}/sanitizers/test-ubsan
assert_failure
assert_output --partial "runtime error: load of null pointer"
}
Loading