mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-09 13:38:00 +00:00
test: Add Build() method for tests using ast::Builder
This separates out the usage of the built module from the construction of the module. Previously, we'd happily interleave generator testing with module construction statements. Once the AST / Program is made immutable, this will no longer be possible. Bug: tint:390 Change-Id: Ib4538228e93ca816f5bb796d024f021116609213 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38360 Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
207b5e2de1
commit
f12054ea2a
@@ -57,8 +57,11 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
|
||||
});
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(block));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0025: switch statement selector expression must be "
|
||||
"of a scalar integer type");
|
||||
}
|
||||
@@ -85,8 +88,11 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
|
||||
});
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(block));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0008: switch statement must have exactly one default "
|
||||
"clause");
|
||||
}
|
||||
@@ -124,8 +130,11 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
|
||||
});
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(block));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0008: switch statement must have exactly one default "
|
||||
"clause");
|
||||
}
|
||||
@@ -156,8 +165,11 @@ TEST_F(ValidateControlBlockTest,
|
||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||
});
|
||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(block));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0026: the case selector values must have the same "
|
||||
"type as the selector expression.");
|
||||
}
|
||||
@@ -188,8 +200,11 @@ TEST_F(ValidateControlBlockTest,
|
||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||
});
|
||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(block));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0026: the case selector values must have the same "
|
||||
"type as the selector expression.");
|
||||
}
|
||||
@@ -226,8 +241,11 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
|
||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||
});
|
||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(block));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0027: a literal value must not appear more than once "
|
||||
"in the case selectors for a switch statement: '2'");
|
||||
}
|
||||
@@ -266,8 +284,11 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
|
||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||
});
|
||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(block));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0027: a literal value must not appear more than once in "
|
||||
"the case selectors for a switch statement: '10'");
|
||||
}
|
||||
@@ -294,8 +315,11 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
|
||||
create<ast::SwitchStatement>(Expr("a"), body),
|
||||
});
|
||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(block));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0028: a fallthrough statement must not appear as the "
|
||||
"last statement in last clause of a switch");
|
||||
}
|
||||
@@ -324,7 +348,10 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
|
||||
create<ast::SwitchStatement>(Expr("a"), body),
|
||||
});
|
||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||
EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateStatements(block)) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
|
||||
@@ -351,7 +378,10 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
|
||||
mod->AddConstructedType(my_int);
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
||||
EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateStatements(block)) << v.error();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -52,7 +52,10 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_TRUE(v()->Validate());
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.Validate());
|
||||
}
|
||||
|
||||
TEST_F(ValidateFunctionTest,
|
||||
@@ -68,7 +71,10 @@ TEST_F(ValidateFunctionTest,
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_TRUE(v()->Validate());
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.Validate());
|
||||
}
|
||||
|
||||
TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||
@@ -86,8 +92,11 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0002: non-void function must end with a return statement");
|
||||
}
|
||||
|
||||
@@ -99,8 +108,11 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0002: non-void function must end with a return statement");
|
||||
}
|
||||
|
||||
@@ -118,7 +130,10 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_TRUE(td()->DetermineFunctions(mod->functions())) << td()->error();
|
||||
EXPECT_TRUE(v()->ValidateFunctions(mod->functions())) << v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateFunctions(mod->functions())) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
|
||||
@@ -132,9 +147,12 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
// TODO(sarahM0): replace 000y with a rule number
|
||||
EXPECT_EQ(v()->error(),
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-000y: return statement type must match its function "
|
||||
"return type, returned '__i32', expected '__void'");
|
||||
}
|
||||
@@ -150,9 +168,12 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
// TODO(sarahM0): replace 000y with a rule number
|
||||
EXPECT_EQ(v()->error(),
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-000y: return statement type must match its function "
|
||||
"return type, returned '__i32', expected '__f32'");
|
||||
}
|
||||
@@ -177,8 +198,11 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
|
||||
mod->AddFunction(func_copy);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
EXPECT_EQ(v()->error(), "12:34 v-0016: function names must be unique 'func'");
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(v.error(), "12:34 v-0016: function names must be unique 'func'");
|
||||
}
|
||||
|
||||
TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
|
||||
@@ -196,8 +220,11 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
|
||||
mod->AddFunction(func0);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate()) << v()->error();
|
||||
EXPECT_EQ(v()->error(), "12:34 v-0004: recursion is not allowed: 'func'");
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate()) << v.error();
|
||||
EXPECT_EQ(v.error(), "12:34 v-0004: recursion is not allowed: 'func'");
|
||||
}
|
||||
|
||||
TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
|
||||
@@ -217,8 +244,11 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
|
||||
mod->AddFunction(func0);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate()) << v()->error();
|
||||
EXPECT_EQ(v()->error(), "12:34 v-0004: recursion is not allowed: 'func'");
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate()) << v.error();
|
||||
EXPECT_EQ(v.error(), "12:34 v-0004: recursion is not allowed: 'func'");
|
||||
}
|
||||
|
||||
TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
|
||||
@@ -235,8 +265,11 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
|
||||
|
||||
mod->AddFunction(func);
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0024: Entry point function must return void: 'vtx_main'");
|
||||
}
|
||||
|
||||
@@ -257,8 +290,11 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
|
||||
|
||||
mod->AddFunction(func);
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0023: Entry point function must accept no parameters: "
|
||||
"'vtx_func'");
|
||||
}
|
||||
@@ -279,9 +315,12 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
|
||||
|
||||
mod->AddFunction(func);
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(
|
||||
v()->error(),
|
||||
v.error(),
|
||||
"12:34 v-0020: only one stage decoration permitted per entry point");
|
||||
}
|
||||
|
||||
@@ -299,7 +338,10 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_TRUE(v()->Validate()) << v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.Validate()) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
|
||||
@@ -312,8 +354,11 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(v.error(),
|
||||
"v-0003: At least one of vertex, fragment or compute shader must "
|
||||
"be present");
|
||||
}
|
||||
|
||||
@@ -73,12 +73,14 @@ TEST_F(ValidatorTest, AssignToScalar_Fail) {
|
||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||
RegisterVariable(var);
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(td()->DetermineResultType(assign));
|
||||
// TODO(sarahM0): Invalidate assignment to scalar.
|
||||
EXPECT_FALSE(v()->ValidateAssign(assign));
|
||||
ASSERT_TRUE(v()->has_error());
|
||||
EXPECT_FALSE(v.ValidateAssign(assign));
|
||||
ASSERT_TRUE(v.has_error());
|
||||
// TODO(sarahM0): figure out what should be the error number.
|
||||
EXPECT_EQ(v()->error(),
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-000x: invalid assignment: left-hand-side does not "
|
||||
"reference storage: __i32");
|
||||
}
|
||||
@@ -129,7 +131,9 @@ TEST_F(ValidatorTest, AssignCompatibleTypes_Pass) {
|
||||
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_TRUE(v()->ValidateAssign(assign)) << v()->error();
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, AssignCompatibleTypesThroughAlias_Pass) {
|
||||
@@ -149,7 +153,9 @@ TEST_F(ValidatorTest, AssignCompatibleTypesThroughAlias_Pass) {
|
||||
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_TRUE(v()->ValidateAssign(assign)) << v()->error();
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, AssignCompatibleTypesInferRHSLoad_Pass) {
|
||||
@@ -171,7 +177,9 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInferRHSLoad_Pass) {
|
||||
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_TRUE(v()->ValidateAssign(assign)) << v()->error();
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, AssignThroughPointer_Pass) {
|
||||
@@ -193,7 +201,10 @@ TEST_F(ValidatorTest, AssignThroughPointer_Pass) {
|
||||
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_TRUE(v()->ValidateAssign(assign)) << v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, AssignIncompatibleTypes_Fail) {
|
||||
@@ -215,10 +226,12 @@ TEST_F(ValidatorTest, AssignIncompatibleTypes_Fail) {
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
|
||||
EXPECT_FALSE(v()->ValidateAssign(assign));
|
||||
ASSERT_TRUE(v()->has_error());
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateAssign(assign));
|
||||
ASSERT_TRUE(v.has_error());
|
||||
// TODO(sarahM0): figure out what should be the error number.
|
||||
EXPECT_EQ(v()->error(),
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-000x: invalid assignment: can't assign value of type "
|
||||
"'__f32' to '__i32'");
|
||||
}
|
||||
@@ -242,8 +255,11 @@ TEST_F(ValidatorTest, AssignThroughPointerWrongeStoreType_Fail) {
|
||||
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_FALSE(v()->ValidateAssign(assign));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateAssign(assign));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-000x: invalid assignment: can't assign value of type "
|
||||
"'__i32' to '__f32'");
|
||||
}
|
||||
@@ -269,7 +285,9 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
|
||||
EXPECT_TRUE(v()->ValidateStatements(body)) << v()->error();
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateStatements(body)) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
|
||||
@@ -294,10 +312,12 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
|
||||
EXPECT_FALSE(v()->ValidateStatements(block));
|
||||
ASSERT_TRUE(v()->has_error());
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(block));
|
||||
ASSERT_TRUE(v.has_error());
|
||||
// TODO(sarahM0): figure out what should be the error number.
|
||||
EXPECT_EQ(v()->error(),
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-000x: invalid assignment: can't assign value of type "
|
||||
"'__f32' to '__i32'");
|
||||
}
|
||||
@@ -307,8 +327,10 @@ TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
|
||||
mod->AddGlobalVariable(Var(Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kInput, ty.f32, nullptr,
|
||||
ast::VariableDecorationList{}));
|
||||
EXPECT_TRUE(v()->ValidateGlobalVariables(mod->global_variables()))
|
||||
<< v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateGlobalVariables(mod->global_variables())) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
||||
@@ -317,8 +339,11 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
||||
ast::StorageClass::kNone, ty.f32, nullptr,
|
||||
ast::VariableDecorationList{}));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0022: global variables must have a storage class");
|
||||
}
|
||||
|
||||
@@ -328,9 +353,12 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
|
||||
ast::StorageClass::kInput, ty.f32, nullptr,
|
||||
ast::VariableDecorationList{}));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(
|
||||
v()->error(),
|
||||
v.error(),
|
||||
"12:34 v-global01: global constants shouldn't have a storage class");
|
||||
}
|
||||
|
||||
@@ -340,7 +368,10 @@ TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
|
||||
ast::StorageClass::kNone, ty.f32, nullptr,
|
||||
ast::VariableDecorationList{}));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate()) << v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate()) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
|
||||
@@ -363,8 +394,10 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
|
||||
ast::FunctionDecorationList{});
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
EXPECT_EQ(v()->error(), "12:34 v-0006: 'not_global_var' is not declared");
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(v.error(), "12:34 v-0006: 'not_global_var' is not declared");
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
||||
@@ -390,7 +423,10 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_TRUE(v()->Validate()) << v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.Validate()) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
|
||||
@@ -419,8 +455,11 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
|
||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_FALSE(v()->ValidateStatements(outer_body));
|
||||
EXPECT_EQ(v()->error(), "12:34 v-0006: 'a' is not declared");
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(outer_body));
|
||||
EXPECT_EQ(v.error(), "12:34 v-0006: 'a' is not declared");
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
|
||||
@@ -449,7 +488,10 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
|
||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_TRUE(v()->ValidateStatements(outer_body)) << v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateStatements(outer_body)) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
|
||||
@@ -464,8 +506,9 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
|
||||
ast::VariableDecorationList{});
|
||||
mod->AddGlobalVariable(var1);
|
||||
|
||||
EXPECT_TRUE(v()->ValidateGlobalVariables(mod->global_variables()))
|
||||
<< v()->error();
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateGlobalVariables(mod->global_variables())) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
|
||||
@@ -480,8 +523,10 @@ TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
|
||||
ast::VariableDecorationList{});
|
||||
mod->AddGlobalVariable(var1);
|
||||
|
||||
EXPECT_FALSE(v()->ValidateGlobalVariables(mod->global_variables()));
|
||||
EXPECT_EQ(v()->error(),
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateGlobalVariables(mod->global_variables()));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0011: redeclared global identifier 'global_var'");
|
||||
}
|
||||
|
||||
@@ -506,8 +551,10 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
|
||||
EXPECT_FALSE(v()->ValidateStatements(body));
|
||||
EXPECT_EQ(v()->error(), "12:34 v-0021: cannot re-assign a constant: 'a'");
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(body));
|
||||
EXPECT_EQ(v.error(), "12:34 v-0021: cannot re-assign a constant: 'a'");
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
|
||||
@@ -535,8 +582,11 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate()) << v()->error();
|
||||
EXPECT_EQ(v()->error(), "12:34 v-0013: redeclared identifier 'a'");
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate()) << v.error();
|
||||
EXPECT_EQ(v.error(), "12:34 v-0013: redeclared identifier 'a'");
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
|
||||
@@ -562,8 +612,11 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
EXPECT_EQ(v()->error(), "12:34 v-0014: redeclared identifier 'a'");
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(v.error(), "12:34 v-0014: redeclared identifier 'a'");
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
|
||||
@@ -589,7 +642,10 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
|
||||
});
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
||||
EXPECT_TRUE(v()->ValidateStatements(outer_body)) << v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateStatements(outer_body)) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
|
||||
@@ -616,8 +672,11 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
|
||||
});
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(outer_body));
|
||||
EXPECT_EQ(v()->error(), "12:34 v-0014: redeclared identifier 'a'");
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateStatements(outer_body));
|
||||
EXPECT_EQ(v.error(), "12:34 v-0014: redeclared identifier 'a'");
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
||||
@@ -652,7 +711,10 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
||||
mod->AddFunction(func1);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_TRUE(v()->Validate()) << v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.Validate()) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
|
||||
@@ -676,80 +738,107 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
|
||||
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_TRUE(v()->ValidateStatements(body)) << v()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateStatements(body)) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_Void) {
|
||||
EXPECT_FALSE(v()->IsStorable(ty.void_));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.IsStorable(ty.void_));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_Scalar) {
|
||||
EXPECT_TRUE(v()->IsStorable(ty.bool_));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.i32));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.u32));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.f32));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.IsStorable(ty.bool_));
|
||||
EXPECT_TRUE(v.IsStorable(ty.i32));
|
||||
EXPECT_TRUE(v.IsStorable(ty.u32));
|
||||
EXPECT_TRUE(v.IsStorable(ty.f32));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_Vector) {
|
||||
EXPECT_TRUE(v()->IsStorable(ty.vec2<int>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.vec3<int>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.vec4<int>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.vec2<unsigned>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.vec3<unsigned>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.vec4<unsigned>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.vec2<float>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.vec3<float>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.vec4<float>()));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.IsStorable(ty.vec2<int>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.vec3<int>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.vec4<int>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.vec2<unsigned>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.vec3<unsigned>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.vec4<unsigned>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.vec2<float>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.vec3<float>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.vec4<float>()));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_Matrix) {
|
||||
EXPECT_TRUE(v()->IsStorable(ty.mat2x2<float>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.mat2x3<float>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.mat2x4<float>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.mat3x2<float>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.mat3x3<float>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.mat3x4<float>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.mat4x2<float>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.mat4x3<float>()));
|
||||
EXPECT_TRUE(v()->IsStorable(ty.mat4x4<float>()));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.IsStorable(ty.mat2x2<float>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.mat2x3<float>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.mat2x4<float>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.mat3x2<float>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.mat3x3<float>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.mat3x4<float>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.mat4x2<float>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.mat4x3<float>()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.mat4x4<float>()));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_Pointer) {
|
||||
auto* ptr_ty = ty.pointer<int>(ast::StorageClass::kPrivate);
|
||||
EXPECT_FALSE(v()->IsStorable(ptr_ty));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.IsStorable(ptr_ty));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_AliasVoid) {
|
||||
auto* alias = ty.alias("myalias", ty.void_);
|
||||
EXPECT_FALSE(v()->IsStorable(alias));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.IsStorable(alias));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_AliasI32) {
|
||||
auto* alias = ty.alias("myalias", ty.i32);
|
||||
EXPECT_TRUE(v()->IsStorable(alias));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.IsStorable(alias));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_ArraySizedOfStorable) {
|
||||
EXPECT_TRUE(v()->IsStorable(ty.array(ty.i32, 5)));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.IsStorable(ty.array(ty.i32, 5)));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_ArraySizedOfNonStorable) {
|
||||
EXPECT_FALSE(v()->IsStorable(ty.array(ty.void_, 5)));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.IsStorable(ty.array(ty.void_, 5)));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_ArrayUnsizedOfStorable) {
|
||||
EXPECT_TRUE(v()->IsStorable(ty.array<int>()));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.IsStorable(ty.array<int>()));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_ArrayUnsizedOfNonStorable) {
|
||||
EXPECT_FALSE(v()->IsStorable(ty.array<void>()));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.IsStorable(ty.array<void>()));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_Struct_AllMembersStorable) {
|
||||
ast::StructMemberList members{Member("a", ty.i32), Member("b", ty.f32)};
|
||||
auto* s = create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
|
||||
auto* s_ty = ty.struct_("mystruct", s);
|
||||
EXPECT_TRUE(v()->IsStorable(s_ty));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.IsStorable(s_ty));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_Struct_SomeMembersNonStorable) {
|
||||
@@ -757,7 +846,9 @@ TEST_F(ValidatorTest, IsStorable_Struct_SomeMembersNonStorable) {
|
||||
ast::StructMemberList members{Member("a", ty.i32), Member("b", ptr_ty)};
|
||||
auto* s = create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
|
||||
auto* s_ty = ty.struct_("mystruct", s);
|
||||
EXPECT_FALSE(v()->IsStorable(s_ty));
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.IsStorable(s_ty));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace tint {
|
||||
|
||||
ValidatorTestHelper::ValidatorTestHelper() {
|
||||
td_ = std::make_unique<TypeDeterminer>(mod);
|
||||
v_ = std::make_unique<ValidatorImpl>(mod);
|
||||
}
|
||||
|
||||
ValidatorTestHelper::~ValidatorTestHelper() = default;
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
#ifndef SRC_VALIDATOR_VALIDATOR_TEST_HELPER_H_
|
||||
#define SRC_VALIDATOR_VALIDATOR_TEST_HELPER_H_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "src/ast/builder.h"
|
||||
#include "src/type/void_type.h"
|
||||
@@ -32,9 +34,21 @@ class ValidatorTestHelper : public ast::BuilderWithModule {
|
||||
ValidatorTestHelper();
|
||||
~ValidatorTestHelper() override;
|
||||
|
||||
/// A handle to validator
|
||||
/// @returns a pointer to the validator
|
||||
ValidatorImpl* v() const { return v_.get(); }
|
||||
/// Builds and returns a validator from the module.
|
||||
/// @note The validator is only built once. Multiple calls to Build() will
|
||||
/// return the same ValidatorImpl without rebuilding.
|
||||
/// @return the built validator
|
||||
ValidatorImpl& Build() {
|
||||
if (val_) {
|
||||
return *val_;
|
||||
}
|
||||
val_ = std::make_unique<ValidatorImpl>(mod);
|
||||
for (auto* var : vars_for_testing_) {
|
||||
val_->RegisterVariableForTesting(var);
|
||||
}
|
||||
return *val_;
|
||||
}
|
||||
|
||||
/// A handle to type_determiner
|
||||
/// @returns a pointer to the type_determiner object
|
||||
TypeDeterminer* td() const { return td_.get(); }
|
||||
@@ -42,13 +56,14 @@ class ValidatorTestHelper : public ast::BuilderWithModule {
|
||||
/// Inserts a variable into the current scope.
|
||||
/// @param var the variable to register.
|
||||
void RegisterVariable(ast::Variable* var) {
|
||||
v_->RegisterVariableForTesting(var);
|
||||
vars_for_testing_.emplace_back(var);
|
||||
td_->RegisterVariableForTesting(var);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<ValidatorImpl> v_;
|
||||
std::unique_ptr<TypeDeterminer> td_;
|
||||
std::unique_ptr<ValidatorImpl> val_;
|
||||
std::vector<ast::Variable*> vars_for_testing_;
|
||||
};
|
||||
|
||||
} // namespace tint
|
||||
|
||||
@@ -52,7 +52,10 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsLast_Pass) {
|
||||
auto* struct_type = ty.struct_("Foo", st);
|
||||
|
||||
mod->AddConstructedType(struct_type);
|
||||
EXPECT_TRUE(v()->ValidateConstructedTypes(mod->constructed_types()));
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateConstructedTypes(mod->constructed_types()));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTypeTest, RuntimeArrayIsLastNoBlock_Fail) {
|
||||
@@ -69,8 +72,11 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsLastNoBlock_Fail) {
|
||||
|
||||
auto* struct_type = ty.struct_("Foo", st);
|
||||
mod->AddConstructedType(struct_type);
|
||||
EXPECT_FALSE(v()->ValidateConstructedTypes(mod->constructed_types()));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateConstructedTypes(mod->constructed_types()));
|
||||
EXPECT_EQ(v.error(),
|
||||
"v-0031: a struct containing a runtime-sized array must be "
|
||||
"in the 'storage' storage class: 'Foo'");
|
||||
}
|
||||
@@ -94,8 +100,11 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsNotLast_Fail) {
|
||||
auto* struct_type = ty.struct_("Foo", st);
|
||||
|
||||
mod->AddConstructedType(struct_type);
|
||||
EXPECT_FALSE(v()->ValidateConstructedTypes(mod->constructed_types()));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateConstructedTypes(mod->constructed_types()));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0015: runtime arrays may only appear as the last member "
|
||||
"of a struct");
|
||||
}
|
||||
@@ -117,8 +126,11 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsNotLast_Fail) {
|
||||
|
||||
auto* struct_type = ty.struct_("s", st);
|
||||
mod->AddConstructedType(struct_type);
|
||||
EXPECT_FALSE(v()->ValidateConstructedTypes(mod->constructed_types()));
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateConstructedTypes(mod->constructed_types()));
|
||||
EXPECT_EQ(v.error(),
|
||||
"v-0015: runtime arrays may only appear as the last member "
|
||||
"of a struct");
|
||||
}
|
||||
@@ -140,7 +152,10 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsLast_Pass) {
|
||||
|
||||
auto* struct_type = ty.struct_("s", st);
|
||||
mod->AddConstructedType(struct_type);
|
||||
EXPECT_TRUE(v()->ValidateConstructedTypes(mod->constructed_types()));
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateConstructedTypes(mod->constructed_types()));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
|
||||
@@ -160,8 +175,11 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
|
||||
mod->AddFunction(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0015: runtime arrays may only appear as the last member "
|
||||
"of a struct");
|
||||
}
|
||||
@@ -192,8 +210,11 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) {
|
||||
mod->AddFunction(main);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate());
|
||||
EXPECT_EQ(v()->error(),
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.Validate());
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0015: runtime arrays may only appear as the last member "
|
||||
"of a struct");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user