TestHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
7 
8 #include <string>
9 
10 #include "DataStructures/DataBox/Tag.hpp"
11 #include "DataStructures/DataBox/TagName.hpp"
12 #include "DataStructures/DataBox/TagTraits.hpp"
13 #include "Utilities/TypeTraits.hpp"
14 #include "Utilities/TypeTraits/CreateIsCallable.hpp"
15 
16 namespace TestHelpers {
17 
18 namespace db {
19 
20 namespace detail {
22 CREATE_IS_CALLABLE_V(name)
23 
24 template <typename Tag>
25 void check_tag_name(const std::string& expected_name) {
26  CHECK(::db::tag_name<Tag>() == expected_name);
27  if (is_name_callable_v<Tag> and not ::db::is_compute_item_v<Tag>) {
28  INFO("Do not define name for Tag '" << ::db::tag_name<Tag>() << "',");
29  INFO("as it will automatically be generated with that name.");
30  CHECK(::db::tag_name<Tag>() != pretty_type::short_name<Tag>());
31  }
32 }
33 } // namespace detail
34 
35 template <typename Tag>
36 void test_base_tag(const std::string& expected_name) {
37  static_assert(::db::is_base_tag_v<Tag>,
38  "A base tag must be derived from db::BaseTag, but "
39  "not from db::SimpleTag nor db::ComputeTag");
40  detail::check_tag_name<Tag>(expected_name);
41 }
42 
43 template <typename Tag>
44 void test_compute_tag(const std::string& expected_name) {
45  static_assert(::db::is_compute_item_v<Tag>,
46  "A compute tag must be derived from db::ComputeTag");
47  detail::check_tag_name<Tag>(expected_name);
48 }
49 
50 template <typename Tag>
51 void test_prefix_tag(const std::string& expected_name) {
52  static_assert(cpp17::is_base_of_v<::db::PrefixTag, Tag>,
53  "A prefix tag must be derived from db::PrefixTag");
54  detail::check_tag_name<Tag>(expected_name);
55 }
56 
57 template <typename Tag>
58 void test_simple_tag(const std::string& expected_name) {
59  static_assert(cpp17::is_base_of_v<::db::SimpleTag, Tag> and
60  not cpp17::is_base_of_v<::db::ComputeTag, Tag>,
61  "A simple tag must be derived from "
62  "db::SimpleTag, but not db::ComputeTag");
63  static_assert(not cpp17::is_same_v<Tag, typename Tag::type>,
64  "A type cannot be its own tag.");
65  detail::check_tag_name<Tag>(expected_name);
66 }
67 
68 } // namespace db
69 
70 } // namespace TestHelpers
Definition: TestCreation.hpp:14
#define CREATE_IS_CALLABLE(METHOD_NAME)
Generate a type trait to check if a class has a member function that can be invoked with arguments of...
Definition: CreateIsCallable.hpp:32
Definition: Determinant.hpp:11
Namespace for DataBox related things.
Definition: DataBox.hpp:42
Code to wrap or improve the Catch testing framework used for unit tests.