Skip to content

Commit d360529

Browse files
committed
Add initial files to test string_CONFIG_NO_EXCEPTIONS
1 parent 4462221 commit d360529

File tree

3 files changed

+202
-0
lines changed

3 files changed

+202
-0
lines changed

test/string-noexcept.t.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (c) 2016-2020 Martin Moene
2+
//
3+
// https://github.com/martinmoene/string-bare
4+
//
5+
// Distributed under the Boost Software License, Version 1.0.
6+
// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7+
8+
#include "nonstd/string.hpp"
9+
#include <iostream>
10+
11+
template< typename T >
12+
void use( T const & /*x*/) {}
13+
14+
#define string_PRESENT( x ) \
15+
std::cout << #x << ": " << x << "\n"
16+
17+
#define string_ABSENT( x ) \
18+
std::cout << #x << ": (undefined)\n"
19+
20+
void report()
21+
{
22+
#ifdef __cpp_exceptions
23+
string_PRESENT( __cpp_exceptions );
24+
#else
25+
string_ABSENT( __cpp_exceptions );
26+
#endif
27+
28+
#ifdef __EXCEPTIONS
29+
string_PRESENT( __EXCEPTIONS );
30+
#else
31+
string_ABSENT( __EXCEPTIONS );
32+
#endif
33+
34+
#ifdef _HAS_EXCEPTIONS
35+
string_PRESENT( _HAS_EXCEPTIONS );
36+
#else
37+
string_ABSENT( _HAS_EXCEPTIONS );
38+
#endif
39+
40+
#ifdef _CPPUNWIND
41+
string_PRESENT( _CPPUNWIND );
42+
#else
43+
string_ABSENT( _CPPUNWIND );
44+
#endif
45+
46+
#ifdef _CPPRTTI
47+
string_PRESENT( _CPPRTTI );
48+
#else
49+
string_ABSENT( _CPPRTTI );
50+
#endif
51+
}
52+
53+
int violate_access()
54+
{
55+
// nonstd::expected<int, char> eu( nonstd:: make_unexpected('a') );
56+
57+
// return eu.value();
58+
59+
return -1;
60+
}
61+
62+
int main()
63+
{
64+
report();
65+
66+
#if ! nsel_CONFIG_NO_EXCEPTIONS_SEH
67+
return violate_access();
68+
#else
69+
__try
70+
{
71+
return violate_access();
72+
}
73+
__except( EXCEPTION_EXECUTE_HANDLER )
74+
{
75+
std::cerr << "\n*** Executing SEH __except block ***\n";
76+
}
77+
#endif
78+
}
79+
80+
// end of file

test/t-noexcept.bat

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@echo off & setlocal enableextensions enabledelayedexpansion
2+
::
3+
:: t.bat - compile & run tests (MSVC).
4+
::
5+
6+
set unit=string
7+
set unit_file=string
8+
9+
:: if no std is given, use compiler default
10+
11+
set std=%1
12+
if not "%std%"=="" set std=-std:%std%
13+
14+
call :CompilerVersion version
15+
echo VC%version%: %args%
16+
17+
set unit_config=^
18+
-Dstring_STRING_HEADER=\"nonstd/string.hpp\" ^
19+
-Dstring_CONFIG_NO_EXCEPTIONS=1 ^
20+
-Dstring_CONFIG_PROVIDE_REGEX=0 ^
21+
-Dstring_CONFIG_PROVIDE_CHAR_T=1 ^
22+
-Dstring_CONFIG_PROVIDE_WCHAR_T=1 ^
23+
-Dstring_CONFIG_PROVIDE_CHAR8_T=0 ^
24+
-Dstring_CONFIG_PROVIDE_CHAR16_T=0 ^
25+
-Dstring_CONFIG_PROVIDE_CHAR32_T=0
26+
27+
set msvc_defines=^
28+
-D_CRT_SECURE_NO_WARNINGS ^
29+
-D_SCL_SECURE_NO_WARNINGS ^
30+
-D_HAS_EXCEPTIONS=0 ^
31+
-Dstring_CONFIG_NO_SEH=0
32+
33+
:: -Dnsel_CONFIG_NO_EXCEPTIONS=1
34+
35+
set CppCoreCheckInclude=%VCINSTALLDIR%\Auxiliary\VS\include
36+
37+
:: -EHsc
38+
::cl -kernel -GR- -W3 %std% %unit_config% %msvc_defines% -I"%CppCoreCheckInclude%" -I../include -I. %unit%-noexcept.t.cpp && %unit%-noexcept.t.exe
39+
cl -EHs -GR- -W3 %std% %unit_config% %msvc_defines% -I"%CppCoreCheckInclude%" -Ilest -I../include -I. %unit_file%-noexcept.t.cpp && %unit_file%-noexcept.t.exe
40+
endlocal & goto :EOF
41+
42+
:: subroutines:
43+
44+
:CompilerVersion version
45+
@echo off & setlocal enableextensions
46+
set tmpprogram=_getcompilerversion.tmp
47+
set tmpsource=%tmpprogram%.c
48+
49+
echo #include ^<stdio.h^> >%tmpsource%
50+
echo int main(){printf("%%d\n",_MSC_VER);} >>%tmpsource%
51+
52+
cl /nologo %tmpsource% >nul
53+
for /f %%x in ('%tmpprogram%') do set version=%%x
54+
del %tmpprogram%.* >nul
55+
set offset=0
56+
if %version% LSS 1900 set /a offset=1
57+
set /a version="version / 10 - 10 * ( 5 + offset )"
58+
endlocal & set %1=%version%& goto :EOF
59+
60+
:: toupper; makes use of the fact that string
61+
:: replacement (via SET) is not case sensitive
62+
:toupper
63+
for %%L IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET %1=!%1:%%L=%%L!
64+
goto :EOF

test/tg-noexcept.bat

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
@echo off & setlocal enableextensions enabledelayedexpansion
2+
::
3+
:: tg.bat - compile & run tests (GNUC).
4+
::
5+
6+
set unit=expected
7+
set unit_file=string
8+
9+
:: if no std is given, use c++11
10+
11+
set std=%1
12+
set args=%2 %3 %4 %5 %6 %7 %8 %9
13+
if "%1" == "" set std=c++11
14+
15+
set gpp=g++
16+
17+
call :CompilerVersion version
18+
echo %gpp% %version%: %std% %args%
19+
20+
set unit_config=^
21+
-Dstring_STRING_HEADER=\"nonstd/string.hpp\" ^
22+
-Dstring_CONFIG_NO_EXCEPTIONS=1 ^
23+
-Dstring_CONFIG_PROVIDE_REGEX=0 ^
24+
-Dstring_CONFIG_PROVIDE_CHAR_T=1 ^
25+
-Dstring_CONFIG_PROVIDE_WCHAR_T=1 ^
26+
-Dstring_CONFIG_PROVIDE_CHAR8_T=0 ^
27+
-Dstring_CONFIG_PROVIDE_CHAR16_T=0 ^
28+
-Dstring_CONFIG_PROVIDE_CHAR32_T=0
29+
30+
31+
rem -flto / -fwhole-program
32+
set optflags=-O2 -fno-exceptions
33+
set warnflags=-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wno-padded -Wno-missing-noreturn
34+
35+
%gpp% -std=%std% %optflags% %warnflags% %unit_config% -o %unit_file%-noexcept.t.exe -I../include -I. %unit_file%-noexcept.t.cpp && %unit_file%-noexcept.t.exe
36+
37+
endlocal & goto :EOF
38+
39+
:: subroutines:
40+
41+
:CompilerVersion version
42+
echo off & setlocal enableextensions
43+
set tmpprogram=_getcompilerversion.tmp
44+
set tmpsource=%tmpprogram%.c
45+
46+
echo #include ^<stdio.h^> > %tmpsource%
47+
echo int main(){printf("%%d.%%d.%%d\n",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);} >> %tmpsource%
48+
49+
%gpp% -o %tmpprogram% %tmpsource% >nul
50+
for /f %%x in ('%tmpprogram%') do set version=%%x
51+
del %tmpprogram%.* >nul
52+
endlocal & set %1=%version%& goto :EOF
53+
54+
:: toupper; makes use of the fact that string
55+
:: replacement (via SET) is not case sensitive
56+
:toupper
57+
for %%L IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET %1=!%1:%%L=%%L!
58+
goto :EOF

0 commit comments

Comments
 (0)