Skip to content

Commit 5207325

Browse files
committed
test.cpp: added compilation test for safe api
1 parent 1aeef68 commit 5207325

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

.github/workflows/CI-unixish.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ jobs:
6161
run: |
6262
make -j$(nproc) selfcheck
6363
64+
- name: make testrunner (c++17)
65+
run: |
66+
make clean
67+
make -j$(nproc) testrunner CXXOPTS="-std=c++17"
68+
69+
- name: make testrunner (c++20)
70+
run: |
71+
make clean
72+
make -j$(nproc) testrunner CXXOPTS="-std=c++20"
73+
6474
- name: Run CMake
6575
run: |
6676
cmake -S . -B cmake.output -DCMAKE_COMPILE_WARNING_AS_ERROR=On

test.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,6 +3169,44 @@ static void preprocess_files()
31693169
}
31703170
}
31713171

3172+
static void safe_api()
3173+
{
3174+
// this test is to make sure the safe APIs are compiling
3175+
#if defined(__cpp_lib_string_view) || defined(__cpp_lib_span)
3176+
std::vector<std::string> filenames;
3177+
# if defined(__cpp_lib_string_view)
3178+
{
3179+
const char input[] = "code";
3180+
const std::string_view sv = input;
3181+
// std::string_view can be implicitly converted into a std::span
3182+
simplecpp::TokenList(sv,filenames,"");
3183+
}
3184+
# endif
3185+
# ifdef __cpp_lib_span
3186+
{
3187+
char input[] = "code";
3188+
const std::span sp = input;
3189+
simplecpp::TokenList(sp,filenames,"");
3190+
}
3191+
{
3192+
const char input[] = "code";
3193+
const std::span sp = input;
3194+
simplecpp::TokenList(sp,filenames,"");
3195+
}
3196+
{
3197+
unsigned char input[] = "code";
3198+
const std::span sp = input;
3199+
simplecpp::TokenList(sp,filenames,"");
3200+
}
3201+
{
3202+
const unsigned char input[] = "code";
3203+
const std::span sp = input;
3204+
simplecpp::TokenList(sp,filenames,"");
3205+
}
3206+
# endif
3207+
#endif
3208+
}
3209+
31723210
static void fuzz_crash()
31733211
{
31743212
{
@@ -3435,6 +3473,8 @@ int main(int argc, char **argv)
34353473

34363474
TEST_CASE(preprocess_files);
34373475

3476+
TEST_CASE(safe_api);
3477+
34383478
TEST_CASE(fuzz_crash);
34393479

34403480
return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;

0 commit comments

Comments
 (0)