Skip to content

Commit

Permalink
add reverse tests to compile-error-test
Browse files Browse the repository at this point in the history
to make sure that error tests do not fault because they become outdated
  • Loading branch information
alexezeder committed Dec 20, 2021
1 parent bd2ad77 commit baa749c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions test/compile-error-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,29 @@ endfunction ()

# check if the source file skeleton compiles
expect_compile(check "")
expect_compile(check-error "compilation_error" ERROR)

# Formatting a wide character with a narrow format string is forbidden.
expect_compile(wide-character-narrow-format-string "fmt::format(\"{}\", L'a');" ERROR XCHAR)
expect_compile(wide-character-narrow-format-string "fmt::format(L\"{}\", L'a');" XCHAR)
expect_compile(wide-character-narrow-format-string-error "fmt::format(\"{}\", L'a');" ERROR XCHAR)

# Formatting a wide string with a narrow format string is forbidden.
expect_compile(wide-string-narrow-format-string "fmt::format(\"{}\", L\"foo\");" ERROR XCHAR)
expect_compile(wide-string-narrow-format-string "fmt::format(L\"{}\", L\"foo\");" XCHAR)
expect_compile(wide-string-narrow-format-string-error "fmt::format(\"{}\", L\"foo\");" ERROR XCHAR)

# Formatting a narrow string with a wide format string is forbidden because
# mixing UTF-8 with UTF-16/32 can result in an invalid output.
expect_compile(narrow-string-wide-format-string "fmt::format(L\"{}\", \"foo\");" ERROR XCHAR)
expect_compile(narrow-string-wide-format-string "fmt::format(L\"{}\", L\"foo\");" XCHAR)
expect_compile(narrow-string-wide-format-string-error "fmt::format(L\"{}\", \"foo\");" ERROR XCHAR)

# Formatting a wide string with a narrow format string is forbidden.
expect_compile(cast-to-string "
struct S {
operator std::string() const { return std::string(); }
};
fmt::format(\"{}\", std::string(S()));
")
expect_compile(cast-to-string-error "
struct S {
operator std::string() const { return std::string(); }
};
Expand All @@ -112,6 +122,10 @@ expect_compile(cast-to-string "

# Formatting a function
expect_compile(format-function "
void (*f)();
fmt::format(\"{}\", fmt::ptr(f));
" FORMAT)
expect_compile(format-function-error "
void (*f)();
fmt::format(\"{}\", f);
" FORMAT ERROR)
Expand Down

0 comments on commit baa749c

Please sign in to comment.