Skip to content

<generator>: Add death tests #4558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ tests\P2474R2_views_repeat
tests\P2474R2_views_repeat_death
tests\P2494R2_move_only_range_adaptors
tests\P2502R2_generator
tests\P2502R2_generator_death
tests\P2502R2_generator_promise
tests\P2505R5_monadic_functions_for_std_expected
tests\P2510R3_text_formatting_pointers
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P2502R2_generator_death/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_latest_matrix.lst
50 changes: 50 additions & 0 deletions tests/std/tests/P2502R2_generator_death/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <generator>
#include <utility>

#include <test_death.hpp>

std::generator<int> gen() {
co_return;
}

void test_begin_after_initial_suspend_point() {
auto g = gen();
(void) g.begin();
(void) g.begin();
}

void test_begin_after_moving_from() {
auto g = gen();
auto g2 = std::move(g);
(void) g.begin();
}

void test_end_iterator_dereference() {
auto g = gen();
auto i = g.begin();
(void) *i;
}

void test_end_iterator_incrementation() {
auto g = gen();
auto i = g.begin();
++i;
}

int main(int argc, char** argv) {
std_testing::death_test_executive exec;

#ifdef _DEBUG
exec.add_death_tests({
test_begin_after_initial_suspend_point,
test_begin_after_moving_from,
test_end_iterator_dereference,
test_end_iterator_incrementation,
});
#endif // _DEBUG

return exec.run(argc, argv);
}