Skip to content

Commit

Permalink
try to get compile-failure tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
ericniebler committed Nov 25, 2023
1 parent 7dafc0f commit 15fb92a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions cmake/cpm/patches/icm/regex-build-error.diff
Original file line number Diff line number Diff line change
@@ -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}")
22 changes: 22 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
# )
25 changes: 25 additions & 0 deletions test/stdexec/algos/adaptors/test_then_fail1.cpp
Original file line number Diff line number Diff line change
@@ -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 <stdexec/execution.hpp>

namespace ex = stdexec;

int main() {
ex::sender auto snd = ex::just(42) | ex::then([](int*){});
// build error: _NOT_CALLABLE_.*_WITH_FUNCTION_.*_WITH_ARGUMENTS_<int>
stdexec::sync_wait(std::move(snd));
}

0 comments on commit 15fb92a

Please sign in to comment.