Skip to content

Commit ae24823

Browse files
committed
test.cpp: added compilation test for safe api
1 parent dc294a5 commit ae24823

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

.github/workflows/CI-unixish.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ jobs:
5555
run: |
5656
python3 -m pytest integration_test.py -vv
5757
58+
- name: make testrunner (c++17)
59+
run: |
60+
make clean
61+
make -j$(nproc) testrunner CXXOPTS="-std=c++17"
62+
63+
- name: make testrunner (c++20)
64+
run: |
65+
make clean
66+
make -j$(nproc) testrunner CXXOPTS="-std=c++20"
67+
5868
- name: Run CMake
5969
run: |
6070
cmake -S . -B cmake.output

test.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,6 +3125,44 @@ static void preprocess_files()
31253125
}
31263126
}
31273127

3128+
static void safe_api()
3129+
{
3130+
// this test is to make sure the safe APIs are compiling
3131+
#if defined(__cpp_lib_string_view) || defined(__cpp_lib_span)
3132+
std::vector<std::string> filenames;
3133+
# if defined(__cpp_lib_string_view)
3134+
{
3135+
const char input[] = "code";
3136+
const std::string_view sv = input;
3137+
// std::string_view can be implicitly converted into a std::span
3138+
simplecpp::TokenList(sv,filenames,"");
3139+
}
3140+
# endif
3141+
# ifdef __cpp_lib_span
3142+
{
3143+
char input[] = "code";
3144+
const std::span<char, 5> sp = input;
3145+
simplecpp::TokenList(sp,filenames,"");
3146+
}
3147+
{
3148+
const char input[] = "code";
3149+
const std::span<const char, 5> sp = input;
3150+
simplecpp::TokenList(sp,filenames,"");
3151+
}
3152+
{
3153+
unsigned char input[] = "code";
3154+
const std::span<unsigned char, 5> sp = input;
3155+
simplecpp::TokenList(sp,filenames,"");
3156+
}
3157+
{
3158+
const unsigned char input[] = "code";
3159+
const std::span<const unsigned char, 5> sp = input;
3160+
simplecpp::TokenList(sp,filenames,"");
3161+
}
3162+
# endif
3163+
#endif
3164+
}
3165+
31283166
static void fuzz_crash()
31293167
{
31303168
{
@@ -3390,6 +3428,8 @@ int main(int argc, char **argv)
33903428

33913429
TEST_CASE(preprocess_files);
33923430

3431+
TEST_CASE(safe_api);
3432+
33933433
TEST_CASE(fuzz_crash);
33943434

33953435
return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;

0 commit comments

Comments
 (0)