diff options
author | Marco Poletti <poletti.marco@gmail.com> | 2019-07-20 19:21:21 -0700 |
---|---|---|
committer | Marco Poletti <poletti.marco@gmail.com> | 2019-07-20 19:21:21 -0700 |
commit | 4ded6e2e54e94b140d60e95cc10027a882e9c536 (patch) | |
tree | 6682225229714da84d8b19e2ac4c337397a3f4f8 /tests/util | |
parent | 9d6c3afce056da357eaa5e417304a79001b7e24d (diff) | |
download | google-fruit-4ded6e2e54e94b140d60e95cc10027a882e9c536.tar.gz |
Migrate tests to absl.testing, mainly to make Bazel test sharding work.
Diffstat (limited to 'tests/util')
-rw-r--r-- | tests/util/test_lambda_invoker.py | 80 | ||||
-rw-r--r-- | tests/util/test_type_info.py | 130 |
2 files changed, 107 insertions, 103 deletions
diff --git a/tests/util/test_lambda_invoker.py b/tests/util/test_lambda_invoker.py index e25214e..55c9cc4 100644 --- a/tests/util/test_lambda_invoker.py +++ b/tests/util/test_lambda_invoker.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from absl.testing import parameterized from fruit_test_common import * COMMON_DEFINITIONS = ''' @@ -22,45 +23,46 @@ COMMON_DEFINITIONS = ''' using namespace fruit::impl; ''' -def test_invoke_no_args(): - source = ''' - int main() { - // This is static because the lambda must have no captures. - static int num_invocations = 0; - - auto l = []() { - ++num_invocations; - }; - using L = decltype(l); - LambdaInvoker::invoke<L>(); - Assert(num_invocations == 1); - } - ''' - expect_success( - COMMON_DEFINITIONS, - source, - locals()) +class TestLambdaInvoker(parameterized.TestCase): + def test_invoke_no_args(self): + source = ''' + int main() { + // This is static because the lambda must have no captures. + static int num_invocations = 0; + + auto l = []() { + ++num_invocations; + }; + using L = decltype(l); + LambdaInvoker::invoke<L>(); + Assert(num_invocations == 1); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source, + locals()) -def test_invoke_some_args(): - source = ''' - int main() { - // This is static because the lambda must have no captures. - static int num_invocations = 0; - - auto l = [](int n, double x) { - Assert(n == 5); - Assert(x == 3.14); - ++num_invocations; - }; - using L = decltype(l); - LambdaInvoker::invoke<L>(5, 3.14); - Assert(num_invocations == 1); - } - ''' - expect_success( - COMMON_DEFINITIONS, - source, - locals()) + def test_invoke_some_args(self): + source = ''' + int main() { + // This is static because the lambda must have no captures. + static int num_invocations = 0; + + auto l = [](int n, double x) { + Assert(n == 5); + Assert(x == 3.14); + ++num_invocations; + }; + using L = decltype(l); + LambdaInvoker::invoke<L>(5, 3.14); + Assert(num_invocations == 1); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source, + locals()) if __name__ == '__main__': - main(__file__) + absltest.main() diff --git a/tests/util/test_type_info.py b/tests/util/test_type_info.py index 102e14c..1eb1806 100644 --- a/tests/util/test_type_info.py +++ b/tests/util/test_type_info.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from absl.testing import parameterized from fruit_test_common import * COMMON_DEFINITIONS = ''' @@ -22,73 +23,74 @@ COMMON_DEFINITIONS = ''' using namespace fruit::impl; ''' -def test_size(): - source = ''' - int main() { - Assert(getTypeId<char[27]>().type_info->size() == 27); - } - ''' - expect_success( - COMMON_DEFINITIONS, - source, - locals()) +class TestTypeInfo(parameterized.TestCase): + def test_size(self): + source = ''' + int main() { + Assert(getTypeId<char[27]>().type_info->size() == 27); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source, + locals()) -def test_alignment(): - source = ''' - struct alignas(128) TypeAligned128 { - }; - - int main() { - Assert(getTypeId<TypeAligned128>().type_info->alignment() == 128); - } - ''' - expect_success( - COMMON_DEFINITIONS, - source, - locals()) + def test_alignment(self): + source = ''' + struct alignas(128) TypeAligned128 { + }; + + int main() { + Assert(getTypeId<TypeAligned128>().type_info->alignment() == 128); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source, + locals()) -def test_name(): - source = ''' - struct MyStruct { - }; - - int main() { - std::string result = getTypeId<MyStruct>().type_info->name(); - if (result != "MyStruct" && result != "struct MyStruct") { - std::cerr << "Demangling failed." << std::endl; - std::cerr << "typeid(MyStruct).name() == " << typeid(MyStruct).name() << std::endl; - std::cerr << "getTypeId<MyStruct>().type_info->name() == " << result << std::endl; - abort(); - } - Assert(std::string(getTypeId<MyStruct>()) == "MyStruct" || std::string(getTypeId<MyStruct>()) == "struct MyStruct"); - } - ''' - expect_success( - COMMON_DEFINITIONS, - source, - locals()) + def test_name(self): + source = ''' + struct MyStruct { + }; + + int main() { + std::string result = getTypeId<MyStruct>().type_info->name(); + if (result != "MyStruct" && result != "struct MyStruct") { + std::cerr << "Demangling failed." << std::endl; + std::cerr << "typeid(MyStruct).name() == " << typeid(MyStruct).name() << std::endl; + std::cerr << "getTypeId<MyStruct>().type_info->name() == " << result << std::endl; + abort(); + } + Assert(std::string(getTypeId<MyStruct>()) == "MyStruct" || std::string(getTypeId<MyStruct>()) == "struct MyStruct"); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source, + locals()) -def test_isTriviallyDestructible_true(): - source = ''' - int main() { - Assert(getTypeId<int>().type_info->isTriviallyDestructible()); - } - ''' - expect_success( - COMMON_DEFINITIONS, - source, - locals()) + def test_isTriviallyDestructible_true(self): + source = ''' + int main() { + Assert(getTypeId<int>().type_info->isTriviallyDestructible()); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source, + locals()) -def test_isTriviallyDestructible_false(): - source = ''' - int main() { - Assert(!getTypeId<std::vector<int>>().type_info->isTriviallyDestructible()); - } - ''' - expect_success( - COMMON_DEFINITIONS, - source, - locals()) + def test_isTriviallyDestructible_false(self): + source = ''' + int main() { + Assert(!getTypeId<std::vector<int>>().type_info->isTriviallyDestructible()); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source, + locals()) if __name__ == '__main__': - main(__file__) + absltest.main() |