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>
diff --git a/src/validator/validator_test.cc b/src/validator/validator_test.cc
index 1a88227..c41bc16 100644
--- a/src/validator/validator_test.cc
+++ b/src/validator/validator_test.cc
@@ -422,31 +422,6 @@
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;
diff --git a/src/validator/validator_test_helper.h b/src/validator/validator_test_helper.h
index 0768e7a..19d156c 100644
--- a/src/validator/validator_test_helper.h
+++ b/src/validator/validator_test_helper.h
@@ -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 @@
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);