Repository: microsoft/GSL (language: cpp)

Issue:
Investigate iOS failing test
The GitHub Action for iOS is disabled due to failures in `no_exception_ensure_test`. 

The test should have exit code = `0` if the test correctly executes the termination handler. Currently, the test exits with `-1`. 


Discussion / hints:
Hi,
I want to help in resolving this issue, but I'm confused on how to setup my local development environment to test my fixes.
To test my fixes locally should I try building the library on Xcode with the build target set to iPhone? 
Any guidance on how I can setup my local environment (system running MacOS) to test my fixes, would be helpful in working on the issue.

Waiting for your feedback,

Thanks.
Hi @rishitc, I'm not familiar with how the iOS tests were created and validated. They were contributed by @dipidoo and disabled when the tests started failing. 

@dipidoo, would you mind sharing with @rishitc how to locally set up the environment to validate GSL for iOS? Thanks.

Fix patch:
diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml
index 9d29bbcc..0ef9fa3b 100644
--- a/.github/workflows/ios.yml
+++ b/.github/workflows/ios.yml
@@ -25,11 +25,11 @@ jobs:
             -GXcode \
             -DCMAKE_SYSTEM_NAME=iOS \
             "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" \
-            -DCMAKE_OSX_DEPLOYMENT_TARGET=8 \
+            -DCMAKE_OSX_DEPLOYMENT_TARGET=9 \
             -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
             "-DMACOSX_BUNDLE_GUI_IDENTIFIER=GSL.\$(EXECUTABLE_NAME)" \
-            -DMACOSX_BUNDLE_BUNDLE_VERSION=3.0.1 \
-            -DMACOSX_BUNDLE_SHORT_VERSION_STRING=3.0.1 \
+            -DMACOSX_BUNDLE_BUNDLE_VERSION=3.1.0 \
+            -DMACOSX_BUNDLE_SHORT_VERSION_STRING=3.1.0 \
             ..
 
       - name: Build


Test patch:
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 368ce75e..c05aaa78 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -10,7 +10,7 @@ include(ExternalProject)
 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
 
 if(IOS)
-  add_compile_definitions(GTEST_HAS_DEATH_TEST=1)
+    add_compile_definitions(GTEST_HAS_DEATH_TEST=1 IOS_PROCESS_DELAY_WORKAROUND=1)
 endif()
 
 pkg_search_module(GTestMain gtest_main)
@@ -164,36 +164,27 @@ target_include_directories(gsl_tests_config SYSTEM INTERFACE
     googletest/googletest/include
 )
 
-set_property(TARGET  PROPERTY FOLDER "GSL_tests")
-
-function(add_gsl_test name)
-    add_executable(${name} ${name}.cpp)
-    target_link_libraries(${name}
-        Microsoft.GSL::GSL
-        gsl_tests_config
-        ${GTestMain_LIBRARIES}
-    )
-    add_test(
-        ${name}
-        ${name}
-    )
-    # group all tests under GSL_tests
-    set_property(TARGET ${name} PROPERTY FOLDER "GSL_tests")
-endfunction()
-
-add_gsl_test(span_tests)
-add_gsl_test(span_ext_tests)
-add_gsl_test(span_compatibility_tests)
-add_gsl_test(string_span_tests)
-add_gsl_test(at_tests)
-add_gsl_test(notnull_tests)
-add_gsl_test(assertion_tests)
-add_gsl_test(utils_tests)
-add_gsl_test(owner_tests)
-add_gsl_test(byte_tests)
-add_gsl_test(algorithm_tests)
-add_gsl_test(strict_notnull_tests)
+add_executable(gsl_tests
+    algorithm_tests.cpp
+    assertion_tests.cpp
+    at_tests.cpp
+    byte_tests.cpp
+    notnull_tests.cpp
+    owner_tests.cpp
+    span_compatibility_tests.cpp
+    span_ext_tests.cpp
+    span_tests.cpp
+    strict_notnull_tests.cpp
+    string_span_tests.cpp
+    utils_tests.cpp
+)
 
+target_link_libraries(gsl_tests
+    Microsoft.GSL::GSL
+    gsl_tests_config
+    ${GTestMain_LIBRARIES}
+)
+add_test(gsl_tests gsl_tests)
 
 # No exception tests
 
@@ -268,19 +259,9 @@ else()
     )
 endif(MSVC)
 
-function(add_gsl_test_noexcept name)
-    add_executable(${name} ${name}.cpp)
-    target_link_libraries(${name}
-        Microsoft.GSL::GSL
-        gsl_tests_config_noexcept
-        ${GTestMain_LIBRARIES}
-    )
-    add_test(
-      ${name}
-      ${name}
-    )
-    # group all tests under GSL_tests_noexcept
-    set_property(TARGET ${name} PROPERTY FOLDER "GSL_tests_noexcept")
-endfunction()
-
-add_gsl_test_noexcept(no_exception_ensure_tests)
+add_executable(gsl_noexcept_tests no_exception_ensure_tests.cpp)
+target_link_libraries(gsl_noexcept_tests
+    Microsoft.GSL::GSL
+    gsl_tests_config_noexcept
+)
+add_test(gsl_noexcept_tests gsl_noexcept_tests)
diff --git a/tests/no_exception_ensure_tests.cpp b/tests/no_exception_ensure_tests.cpp
index 2ec0ebb7..5fde41cf 100644
--- a/tests/no_exception_ensure_tests.cpp
+++ b/tests/no_exception_ensure_tests.cpp
@@ -14,8 +14,11 @@
 //
 ///////////////////////////////////////////////////////////////////////////////
 
+#include <chrono>
 #include <cstdlib>  // for std::exit
 #include <gsl/span> // for span
+#include <iostream>
+#include <thread>
 
 int operator_subscript_no_throw() noexcept
 {
@@ -42,6 +45,10 @@ void setup_termination_handler() noexcept
 
 int main() noexcept
 {
+    std::cout << "Running main() from " __FILE__ "\n";
+#if defined(IOS_PROCESS_DELAY_WORKAROUND)
+    std::this_thread::sleep_for(std::chrono::seconds(1));
+#endif
     setup_termination_handler();
     operator_subscript_no_throw();
     return -1;
diff --git a/tests/notnull_tests.cpp b/tests/notnull_tests.cpp
index b95bb01d..d4258e86 100644
--- a/tests/notnull_tests.cpp
+++ b/tests/notnull_tests.cpp
@@ -29,8 +29,8 @@ using namespace gsl;
 
 namespace
 {
-static constexpr char deathstring[] = "Expected Death";
-} //namespace
+constexpr char deathstring[] = "Expected Death";
+} // namespace
 
 struct MyBase
 {
@@ -118,12 +118,15 @@ struct NonCopyableNonMovable
     NonCopyableNonMovable& operator=(NonCopyableNonMovable&&) = delete;
 };
 
+namespace
+{
 GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
 bool helper(not_null<int*> p) { return *p == 12; }
 GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
 bool helper_const(not_null<const int*> p) { return *p == 12; }
 
 int* return_pointer() { return nullptr; }
+} // namespace
 
 TEST(notnull_tests, TestNotNullConstructors)
 {
diff --git a/tests/strict_notnull_tests.cpp b/tests/strict_notnull_tests.cpp
index 3cf69110..9de2760d 100644
--- a/tests/strict_notnull_tests.cpp
+++ b/tests/strict_notnull_tests.cpp
@@ -17,13 +17,10 @@
 #include <gtest/gtest.h>
 #include <gsl/pointers>           // for not_null, operator<, operator<=, operator>
 
-namespace gsl
-{
-struct fail_fast;
-} // namespace gsl
-
 using namespace gsl;
 
+namespace
+{
 GSL_SUPPRESS(f.4)  // NO-FORMAT: attribute
 bool helper(not_null<int*> p) { return *p == 12; }
 
@@ -36,8 +33,11 @@ bool strict_helper(strict_not_null<int*> p) { return *p == 12; }
 GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
 bool strict_helper_const(strict_not_null<const int*> p) { return *p == 12; }
 
+#ifdef CONFIRM_COMPILATION_ERRORS
 int* return_pointer() { return nullptr; }
 const int* return_pointer_const() { return nullptr; }
+#endif
+} // namespace
 
 TEST(strict_notnull_tests, TestStrictNotNull)
 {