Validation tests: Check the Program is valid

If the program is invalid, then the content of the program is undefined.
Don't attempt to test undefined behavior.

Remove the one remaining test that was using an invalid program.

Change-Id: I4bb77b8048768717a312ed94b96efb3416274b63
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41384
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-02-10 21:47:04 +00:00 committed by Commit Bot service account
parent 47c4d18375
commit 8b1906d996
2 changed files with 5 additions and 25 deletions

View File

@ -422,31 +422,6 @@ TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
EXPECT_FALSE(v.Validate()) << v.error();
}
TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
// var global_var: f32 = 2.1;
// fn my_func() -> f32 {
// not_global_var = 3.14f;
// }
Global("global_var", ast::StorageClass::kPrivate, ty.f32(), Expr(2.1f),
ast::VariableDecorationList{});
SetSource(Source{Source::Location{12, 34}});
auto* lhs = Expr("not_global_var");
auto* rhs = Expr(3.14f);
Func("my_func", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}},
lhs, rhs),
},
ast::FunctionDecorationList{});
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());
EXPECT_EQ(v.error(), "12:34 v-0006: 'not_global_var' is not declared");
}
TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariableAfter_Fail) {
// fn my_func() -> void {
// global_var = 3.14f;

View File

@ -20,6 +20,7 @@
#include <utility>
#include <vector>
#include "gtest/gtest.h"
#include "src/program_builder.h"
#include "src/semantic/expression.h"
#include "src/type/void_type.h"
@ -44,6 +45,10 @@ class ValidatorTestHelper : public ProgramBuilder {
return *val_;
}
program_ = std::make_unique<Program>(std::move(*this));
[&]() {
ASSERT_TRUE(program_->IsValid())
<< diag::Formatter().format(program_->Diagnostics());
}();
val_ = std::make_unique<ValidatorImpl>(program_.get());
for (auto* var : vars_for_testing_) {
val_->RegisterVariableForTesting(var);