Skip to content

Commit

Permalink
Improve UI tests (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui authored May 28, 2022
1 parent 7734213 commit 4eff87f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/ui/fmt/empty-name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ main() {
ofs << "[package]\n"
"name = \"\""; // empty name
ofs.close();
uitest<Target::Stdout>(__FILE__, {"fmt"}, temp_dir);
uitest<Target::Stdout>({"fmt"}, temp_dir);
};
}
2 changes: 1 addition & 1 deletion tests/ui/fmt/invalid-manifest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ main() {
std::ofstream ofs(temp_dir / "poac.toml");
ofs << "[package]";
ofs.close();
uitest<Target::Stderr>(__FILE__, {"fmt"}, temp_dir);
uitest<Target::Stderr>({"fmt"}, temp_dir);
};
}
5 changes: 2 additions & 3 deletions tests/ui/fmt/no-clang-format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ main() {
cfg<override> = {.tag = {"no-cf"}};
}

tag("no-cf") / "no clang-format"_test = [] {
uitest<Target::Stderr>(__FILE__, {"fmt"});
};
tag("no-cf") /
"no clang-format"_test = [] { uitest<Target::Stderr>({"fmt"}); };
}
3 changes: 1 addition & 2 deletions tests/ui/fmt/no-manifest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ main() {
cfg<override> = {.tag = {"has-cf"}};
}

tag("has-cf") /
"no manifest"_test = [] { uitest<Target::Stderr>(__FILE__, {"fmt"}); };
tag("has-cf") / "no manifest"_test = [] { uitest<Target::Stderr>({"fmt"}); };
}
2 changes: 1 addition & 1 deletion tests/ui/fmt/no-targets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ main() {
ofs << "[package]\n"
"name = \"test\"";
ofs.close();
uitest<Target::Stdout>(__FILE__, {"fmt"}, temp_dir);
uitest<Target::Stdout>({"fmt"}, temp_dir);
};
}
18 changes: 11 additions & 7 deletions tests/ui/util/ui_test_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <string>
#include <string_view>

#if defined(__cpp_lib_source_location)
# include <source_location>
#endif

// external
#include <boost/ut.hpp>

Expand Down Expand Up @@ -109,8 +113,13 @@ readfile(std::string_view name) {
template <Target target>
void
uitest(
std::string_view name, std::initializer_list<std::string_view> args,
const fs::path& temp_dir = get_temp_dir()
std::initializer_list<std::string_view> 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<target>(args, temp_dir);
if (target == Target::Stdout) {
Expand All @@ -123,9 +132,4 @@ uitest(

} // namespace poac::test

#define POAC_UITEST_STDOUT(...) \
poac::test::uitest<poac::test::Target::Stdout>(__FILE__, {__VA_ARGS__})
#define POAC_UITEST_STDERR(...) \
poac::test::uitest<poac::test::Target::Stderr>(__FILE__, {__VA_ARGS__})

#endif // TESTS_UI_UTIL_UI_TEST_UTIL_HPP_

0 comments on commit 4eff87f

Please sign in to comment.