From 0e9d9ed60fba221d9a6f3a1e816edc5222f162ee Mon Sep 17 00:00:00 2001 From: dan sinclair <dsinclair@google.com> Date: Tue, 7 Apr 2020 19:27:49 +0000 Subject: [PATCH] Fill in some disabled tests This CL completes a few of the DISABLED tests. Change-Id: I38806fb9381240d6e3da700f1fb2dac5f899ca6d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19000 Reviewed-by: Ryan Harrison <rharrison@chromium.org> --- src/reader/wgsl/parser_impl_test.cc | 12 +++++++----- src/reader/wgsl/parser_test.cc | 12 +++++++----- src/writer/wgsl/generator.h | 3 +++ src/writer/wgsl/generator_impl_test.cc | 12 +++++++++++- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/reader/wgsl/parser_impl_test.cc b/src/reader/wgsl/parser_impl_test.cc index c4fa4420f1..890be8c0ef 100644 --- a/src/reader/wgsl/parser_impl_test.cc +++ b/src/reader/wgsl/parser_impl_test.cc @@ -28,12 +28,13 @@ TEST_F(ParserImplTest, Empty) { ASSERT_TRUE(p->Parse()) << p->error(); } -TEST_F(ParserImplTest, DISABLED_Parses) { +TEST_F(ParserImplTest, Parses) { auto p = parser(R"( import "GLSL.std.430" as glsl; [[location 0]] var<out> gl_FragColor : vec4<f32>; +entry_point vertex = main; fn main() -> void { gl_FragColor = vec4<f32>(.4, .2, .3, 1); } @@ -42,11 +43,12 @@ fn main() -> void { auto m = p->module(); ASSERT_EQ(1, m.imports().size()); - - // TODO(dsinclair) check rest of AST ... + ASSERT_EQ(1, m.entry_points().size()); + ASSERT_EQ(1, m.functions().size()); + ASSERT_EQ(1, m.global_variables().size()); } -TEST_F(ParserImplTest, DISABLED_HandlesError) { +TEST_F(ParserImplTest, HandlesError) { auto p = parser(R"( import "GLSL.std.430" as glsl; @@ -56,7 +58,7 @@ fn main() -> { # missing return type ASSERT_FALSE(p->Parse()); ASSERT_TRUE(p->has_error()); - EXPECT_EQ(p->error(), "4:15: missing return type for function"); + EXPECT_EQ(p->error(), "4:15: unable to determine function return type"); } TEST_F(ParserImplTest, GetRegisteredType) { diff --git a/src/reader/wgsl/parser_test.cc b/src/reader/wgsl/parser_test.cc index fa06290819..081deba00d 100644 --- a/src/reader/wgsl/parser_test.cc +++ b/src/reader/wgsl/parser_test.cc @@ -30,7 +30,7 @@ TEST_F(ParserTest, Empty) { ASSERT_TRUE(p.Parse()) << p.error(); } -TEST_F(ParserTest, DISABLED_Parses) { +TEST_F(ParserTest, Parses) { Context ctx; Parser p(&ctx, R"( @@ -38,6 +38,7 @@ import "GLSL.std.430" as glsl; [[location 0]] var<out> gl_FragColor : vec4<f32>; +entry_point vertex = main; fn main() -> void { gl_FragColor = vec4<f32>(.4, .2, .3, 1); } @@ -46,11 +47,12 @@ fn main() -> void { auto m = p.module(); ASSERT_EQ(1, m.imports().size()); - - // TODO(dsinclair) check rest of AST ... + ASSERT_EQ(1, m.entry_points().size()); + ASSERT_EQ(1, m.functions().size()); + ASSERT_EQ(1, m.global_variables().size()); } -TEST_F(ParserTest, DISABLED_HandlesError) { +TEST_F(ParserTest, HandlesError) { Context ctx; Parser p(&ctx, R"( import "GLSL.std.430" as glsl; @@ -61,7 +63,7 @@ fn main() -> { # missing return type ASSERT_FALSE(p.Parse()); ASSERT_TRUE(p.has_error()); - EXPECT_EQ(p.error(), "4:15: missing return type for function"); + EXPECT_EQ(p.error(), "4:15: unable to determine function return type"); } } // namespace diff --git a/src/writer/wgsl/generator.h b/src/writer/wgsl/generator.h index cc0cffa45b..827a060d5b 100644 --- a/src/writer/wgsl/generator.h +++ b/src/writer/wgsl/generator.h @@ -39,6 +39,9 @@ class Generator : public writer::Writer { /// @returns the result data std::string result() const { return impl_.result(); } + /// @returns the error + std::string error() const { return impl_.error(); } + private: GeneratorImpl impl_; }; diff --git a/src/writer/wgsl/generator_impl_test.cc b/src/writer/wgsl/generator_impl_test.cc index 1b0e10a3d1..814f214fc5 100644 --- a/src/writer/wgsl/generator_impl_test.cc +++ b/src/writer/wgsl/generator_impl_test.cc @@ -23,7 +23,17 @@ namespace { using GeneratorImplTest = testing::Test; -TEST_F(GeneratorImplTest, DISABLED_Generate) {} +TEST_F(GeneratorImplTest, Generate) { + ast::Module m; + m.AddImport(std::make_unique<ast::Import>("GLSL.std.430", "a")); + + GeneratorImpl g; + + ASSERT_TRUE(g.Generate(m)) << g.error(); + EXPECT_EQ(g.result(), R"(import "GLSL.std.430" as a; + +)"); +} } // namespace } // namespace wgsl