From 15fb92aeb34f1115e964af8eac46772f54babef5 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Sat, 25 Nov 2023 14:28:51 -0800 Subject: [PATCH] try to get compile-failure tests working --- CMakeLists.txt | 10 +++++++ cmake/cpm/patches/icm/regex-build-error.diff | 28 +++++++++++++++++++ test/CMakeLists.txt | 22 +++++++++++++++ .../algos/adaptors/test_then_fail1.cpp | 25 +++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 cmake/cpm/patches/icm/regex-build-error.diff create mode 100644 test/stdexec/algos/adaptors/test_then_fail1.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e0a5aa2d..9e62a8619 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,16 @@ rapids_cpm_find(Catch2 ${Catch2_VERSION} URL https://github.com/catchorg/Catch2/archive/refs/tags/v${Catch2_VERSION}.zip ) +# Add ICM +set(icm_VERSION 1.5.0) +# Always download it, don't attempt to do `find_package(ICM)` first +set(CPM_DOWNLOAD_icm TRUE) +rapids_cpm_find(icm ${icm_VERSION} + CPM_ARGS + URL https://github.com/iboB/icm/archive/refs/tags/v${icm_VERSION}.zip + PATCH_COMMAND patch -p 1 -i ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cpm/patches/icm/regex-build-error.diff +) + # Ensure that we link with the threading library set(CMAKE_THREAD_PREFER_PTHREAD TRUE) rapids_find_package(Threads REQUIRED diff --git a/cmake/cpm/patches/icm/regex-build-error.diff b/cmake/cpm/patches/icm/regex-build-error.diff new file mode 100644 index 000000000..8dd2bfdd9 --- /dev/null +++ b/cmake/cpm/patches/icm/regex-build-error.diff @@ -0,0 +1,28 @@ +diff --git a/icm_build_failure_parse_and_run.cmake b/icm_build_failure_parse_and_run.cmake +index 0e62f6c..2ea5f0a 100644 +--- a/icm_build_failure_parse_and_run.cmake ++++ b/icm_build_failure_parse_and_run.cmake +@@ -29,14 +29,15 @@ endif() + + # collect possible errors from source + file(READ "@parsedSourcePath@" sourceText) ++ + string(REGEX MATCHALL "//[ ]*build error:[^\n]+" matchErrors ${sourceText}) + + # look for collected errors in output + foreach(possibleError ${matchErrors}) + string(REGEX MATCH "//[ ]*build error:[ \t]*(.+)$" _ "${possibleError}") + set(possibleError "${CMAKE_MATCH_1}") +- string(FIND "${out}" "${possibleError}" pos) +- if(NOT pos EQUAL -1) ++ string(REGEX MATCH "${possibleError}" actualError "${out}") ++ if(NOT "${actualError}" STREQUAL "") + message("Success: output when building '@ARG_TARGET@' contains '${possibleError}'") + return() + endif() +@@ -48,4 +49,4 @@ endforeach() + # print execute_process output for debugging purposes + message("${out}") + # print error +-message(FATAL_ERROR "Error: Building '@ARG_TARGET@' failed, but output doesn't contain any of the expected errors:${outErrors}") ++message(FATAL_ERROR "Error: Building '@ARG_TARGET@' failed, but output doesn't match the expected errors:${outErrors}") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4954b9f41..ab8810131 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -117,3 +117,25 @@ catch_discover_tests(test.scratch) if(STDEXEC_ENABLE_CUDA) add_subdirectory(nvexec) endif() + +# build failure tests: + +include(${icm_SOURCE_DIR}/icm_build_failure_testing.cmake) + +# Test which parses a source file for an expected error message +icm_add_build_failure_test( + NAME test_then_fail1 + TARGET test_then_fail1 + SOURCES PARSE stdexec/algos/adaptors/test_then_fail1.cpp + LIBRARIES stdexec + FOLDER test +) + + +# # Adding multiple tests with a glob +# icm_glob_build_failure_tests( +# PATTERN *_fail*.cpp +# LIBRARIES stdexec +# PREFIX stdexec +# FOLDER test/stdexec/algos/adaptors +# ) diff --git a/test/stdexec/algos/adaptors/test_then_fail1.cpp b/test/stdexec/algos/adaptors/test_then_fail1.cpp new file mode 100644 index 000000000..a05215bea --- /dev/null +++ b/test/stdexec/algos/adaptors/test_then_fail1.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 NVIDIA Corporation + * + * Licensed under the Apache License Version 2.0 with LLVM Exceptions + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace ex = stdexec; + +int main() { + ex::sender auto snd = ex::just(42) | ex::then([](int*){}); + // build error: _NOT_CALLABLE_.*_WITH_FUNCTION_.*_WITH_ARGUMENTS_ + stdexec::sync_wait(std::move(snd)); +}