From 4eff87fd32212f31fc17cc5c5a9d1c226cf58ece Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Sun, 29 May 2022 02:31:26 +0900 Subject: [PATCH] Improve UI tests (#602) --- tests/ui/fmt/empty-name.cc | 2 +- tests/ui/fmt/invalid-manifest.cc | 2 +- tests/ui/fmt/no-clang-format.cc | 5 ++--- tests/ui/fmt/no-manifest.cc | 3 +-- tests/ui/fmt/no-targets.cc | 2 +- tests/ui/util/ui_test_util.hpp | 18 +++++++++++------- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/tests/ui/fmt/empty-name.cc b/tests/ui/fmt/empty-name.cc index 97460f625..aec6dc968 100644 --- a/tests/ui/fmt/empty-name.cc +++ b/tests/ui/fmt/empty-name.cc @@ -23,6 +23,6 @@ main() { ofs << "[package]\n" "name = \"\""; // empty name ofs.close(); - uitest(__FILE__, {"fmt"}, temp_dir); + uitest({"fmt"}, temp_dir); }; } diff --git a/tests/ui/fmt/invalid-manifest.cc b/tests/ui/fmt/invalid-manifest.cc index bdf208258..e2fe19f09 100644 --- a/tests/ui/fmt/invalid-manifest.cc +++ b/tests/ui/fmt/invalid-manifest.cc @@ -22,6 +22,6 @@ main() { std::ofstream ofs(temp_dir / "poac.toml"); ofs << "[package]"; ofs.close(); - uitest(__FILE__, {"fmt"}, temp_dir); + uitest({"fmt"}, temp_dir); }; } diff --git a/tests/ui/fmt/no-clang-format.cc b/tests/ui/fmt/no-clang-format.cc index 6071bc4d0..bfbb85fe2 100644 --- a/tests/ui/fmt/no-clang-format.cc +++ b/tests/ui/fmt/no-clang-format.cc @@ -14,7 +14,6 @@ main() { cfg = {.tag = {"no-cf"}}; } - tag("no-cf") / "no clang-format"_test = [] { - uitest(__FILE__, {"fmt"}); - }; + tag("no-cf") / + "no clang-format"_test = [] { uitest({"fmt"}); }; } diff --git a/tests/ui/fmt/no-manifest.cc b/tests/ui/fmt/no-manifest.cc index a90cc469b..99a6faf0c 100644 --- a/tests/ui/fmt/no-manifest.cc +++ b/tests/ui/fmt/no-manifest.cc @@ -14,6 +14,5 @@ main() { cfg = {.tag = {"has-cf"}}; } - tag("has-cf") / - "no manifest"_test = [] { uitest(__FILE__, {"fmt"}); }; + tag("has-cf") / "no manifest"_test = [] { uitest({"fmt"}); }; } diff --git a/tests/ui/fmt/no-targets.cc b/tests/ui/fmt/no-targets.cc index 3cba04e79..88d261647 100644 --- a/tests/ui/fmt/no-targets.cc +++ b/tests/ui/fmt/no-targets.cc @@ -23,6 +23,6 @@ main() { ofs << "[package]\n" "name = \"test\""; ofs.close(); - uitest(__FILE__, {"fmt"}, temp_dir); + uitest({"fmt"}, temp_dir); }; } diff --git a/tests/ui/util/ui_test_util.hpp b/tests/ui/util/ui_test_util.hpp index b007ee195..48bfffcdd 100644 --- a/tests/ui/util/ui_test_util.hpp +++ b/tests/ui/util/ui_test_util.hpp @@ -11,6 +11,10 @@ #include #include +#if defined(__cpp_lib_source_location) +# include +#endif + // external #include @@ -109,8 +113,13 @@ readfile(std::string_view name) { template void uitest( - std::string_view name, std::initializer_list args, - const fs::path& temp_dir = get_temp_dir() + std::initializer_list args, + const fs::path& temp_dir = get_temp_dir(), +#if defined(__cpp_lib_source_location) + std::string name = std::source_location::current().file_name() +#else + std::string_view name = __builtin_FILE() +#endif ) { const auto result = dispatch(args, temp_dir); if (target == Target::Stdout) { @@ -123,9 +132,4 @@ uitest( } // namespace poac::test -#define POAC_UITEST_STDOUT(...) \ - poac::test::uitest(__FILE__, {__VA_ARGS__}) -#define POAC_UITEST_STDERR(...) \ - poac::test::uitest(__FILE__, {__VA_ARGS__}) - #endif // TESTS_UI_UTIL_UI_TEST_UTIL_HPP_