Program: Fix move of diagnostics.

Add test.

Change-Id: Ide47df8b3a946818ed9a8ffd62411284f568609b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42262
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
Ben Clayton 2021-02-24 13:51:13 +00:00 committed by Commit Bot service account
parent 33a8cddb2d
commit ce9229cd2e
2 changed files with 18 additions and 0 deletions

View File

@ -82,6 +82,7 @@ Program& Program::operator=(Program&& program) {
ast_ = std::move(program.ast_);
sem_ = std::move(program.sem_);
symbols_ = std::move(program.symbols_);
diagnostics_ = std::move(program.diagnostics_);
is_valid_ = program.is_valid_;
return *this;
}

View File

@ -152,5 +152,22 @@ TEST_F(ProgramTest, IsValid_GeneratesError) {
EXPECT_EQ(program.Diagnostics().begin()->message,
"invalid program generated");
}
TEST_F(ProgramTest, DiagnosticsMove) {
Diagnostics().add_error("an error message");
Program program_a(std::move(*this));
EXPECT_FALSE(program_a.IsValid());
EXPECT_EQ(program_a.Diagnostics().count(), 1u);
EXPECT_EQ(program_a.Diagnostics().error_count(), 1u);
EXPECT_EQ(program_a.Diagnostics().begin()->message, "an error message");
Program program_b(std::move(program_a));
EXPECT_FALSE(program_b.IsValid());
EXPECT_EQ(program_b.Diagnostics().count(), 1u);
EXPECT_EQ(program_b.Diagnostics().error_count(), 1u);
EXPECT_EQ(program_b.Diagnostics().begin()->message, "an error message");
}
} // namespace
} // namespace tint