From 8fcf269d4b23e21d6dabc42e32367592d9d81223 Mon Sep 17 00:00:00 2001 From: Sarah Mashayekhi Date: Mon, 17 Aug 2020 21:01:28 +0000 Subject: [PATCH] [validation] Add Disabled test for detecting recursion This CL adds a disabled test for validating following rule: v-0004: Recursion is not allowed Bug: tint: 6 Change-Id: I35d51b08174ac23a4b1def9f762e80c5950a726d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/26942 Commit-Queue: dan sinclair Reviewed-by: dan sinclair --- src/validator_test.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/validator_test.cc b/src/validator_test.cc index aaed618b82..853fe6e9c5 100644 --- a/src/validator_test.cc +++ b/src/validator_test.cc @@ -23,6 +23,7 @@ #include "src/ast/bool_literal.h" #include "src/ast/break_statement.h" #include "src/ast/call_expression.h" +#include "src/ast/call_statement.h" #include "src/ast/case_statement.h" #include "src/ast/cast_expression.h" #include "src/ast/continue_statement.h" @@ -684,11 +685,33 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) { mod()->AddFunction(std::move(func0)); mod()->AddFunction(std::move(func1)); - EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error(); tint::ValidatorImpl v; EXPECT_TRUE(v.Validate(mod())) << v.error(); } +TEST_F(ValidatorTest, DISABLED_RecursionIsNotAllowed_Fail) { + // fn func() -> void {func(); return; } + ast::type::F32Type f32; + ast::type::VoidType void_type; + ast::ExpressionList call_params; + auto call_expr = std::make_unique( + Source{12, 34}, std::make_unique("func"), + std::move(call_params)); + ast::VariableList params0; + auto func0 = + std::make_unique("func", std::move(params0), &f32); + auto body0 = std::make_unique(); + body0->append(std::make_unique(std::move(call_expr))); + body0->append(std::make_unique()); + func0->set_body(std::move(body0)); + mod()->AddFunction(std::move(func0)); + + EXPECT_TRUE(td()->Determine()) << td()->error(); + tint::ValidatorImpl v; + EXPECT_FALSE(v.Validate(mod())) << v.error(); + EXPECT_EQ(v.error(), "12:34: v-0004: recursion is not allowed: 'func'"); +} + } // namespace } // namespace tint