Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: tests/SkSLErrorTest.cpp

Issue 1984363002: initial checkin of SkSL compiler (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: more cleanups Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/sksl/spirv.h ('K') | « src/sksl/spirv.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkSLCompiler.h"
9
10 #include "Test.h"
11
12 static void test_failure(skiatest::Reporter* r, const char* src, const char* err or) {
13 SkSL::Compiler compiler;
14 std::stringstream out;
15 bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, src, out);
16 REPORTER_ASSERT(r, !result);
17 REPORTER_ASSERT(r, compiler.errorText() == error);
18 }
19
20 static void test_success(skiatest::Reporter* r, const char* src) {
21 SkSL::Compiler compiler;
22 std::stringstream out;
23 bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, src, out);
24 REPORTER_ASSERT(r, result);
25 }
26
27 DEF_TEST(SkSLUndefinedSymbol, r) {
28 test_failure(r,
29 "void main() { x = vec2(1); }",
30 "error: 1: unknown identifier 'x'\n1 error\n");
31 }
32
33 DEF_TEST(SkSLUndefinedFunction, r) {
34 test_failure(r,
35 "void main() { int x = foo(1); }",
36 "error: 1: unknown identifier 'foo'\n1 error\n");
37 }
38
39 DEF_TEST(SkSLGenericParameterMismatch, r) {
40 test_failure(r,
41 "void main() { float x = sin(1, 2); }",
42 "error: 1: no match for sin(int, int)\n1 error\n");
43 }
44
45 DEF_TEST(SkSLParameterCountMismatch, r) {
46 test_failure(r,
47 "float foo(float x) { return x * x; }"
48 "void main() { float x = foo(1, 2); }",
49 "error: 1: call to 'foo' expected 1 parameter, but found 2\n1 e rror\n");
50 }
51
52 DEF_TEST(SkSLParameterMismatch, r) {
53 test_failure(r,
54 "float foo(float x) { return x * x; }"
55 "void main() { float x = foo(true); }",
56 "error: 1: expected 'float', but found 'bool'\n1 error\n");
57 }
58
59 DEF_TEST(SkSLIfTypeMismatch, r) {
60 test_failure(r,
61 "void main() { if (3) { } }",
62 "error: 1: expected 'bool', but found 'int'\n1 error\n");
63 }
64
65 DEF_TEST(SkSLDoTypeMismatch, r) {
66 test_failure(r,
67 "void main() { do { } while (vec2(1)); }",
68 "error: 1: expected 'bool', but found 'vec2'\n1 error\n");
69 }
70
71 DEF_TEST(SkSLWhileTypeMismatch, r) {
72 test_failure(r,
73 "void main() { while (vec3(1)) { } }",
74 "error: 1: expected 'bool', but found 'vec3'\n1 error\n");
75 }
76
77 DEF_TEST(SkSLForTypeMismatch, r) {
78 test_failure(r,
79 "void main() { for (int x = 0; x; x++) { } }",
80 "error: 1: expected 'bool', but found 'int'\n1 error\n");
81 }
82
83 DEF_TEST(SkSLConstructorTypeMismatch, r) {
84 test_failure(r,
85 "void main() { vec2 x = vec2(1.0, false); }",
86 "error: 1: expected 'float', but found 'bool'\n1 error\n");
87 }
88
89 DEF_TEST(SkSLConstructorParameterCount, r) {
90 test_failure(r,
91 "void main() { vec3 x = vec3(1.0, 2.0); }",
92 "error: 1: invalid parameters to 'vec3' constructor (expected 3 scalars, but "
93 "found 2)\n1 error\n");
94 test_success(r, "void main() { vec3 x = vec3(1.0, 2.0, 3.0, 4.0); }");
95 }
96
97 DEF_TEST(SkSLSwizzleScalar, r) {
98 test_failure(r,
99 "void main() { float x = 1; float y = x.y; }",
100 "error: 1: cannot swizzle value of type 'float'\n1 error\n");
101 }
102
103 DEF_TEST(SkSLSwizzleMatrix, r) {
104 test_failure(r,
105 "void main() { mat2 x = mat2(1); float y = x.y; }",
106 "error: 1: cannot swizzle value of type 'mat2'\n1 error\n");
107 }
108
109 DEF_TEST(SkSLSwizzleOutOfBounds, r) {
110 test_failure(r,
111 "void main() { vec3 test = vec2(1).xyz; }",
112 "error: 1: invalid swizzle component 'z'\n1 error\n");
113 }
114
115 DEF_TEST(SkSLSwizzleTooManyComponents, r) {
116 test_failure(r,
117 "void main() { vec4 test = vec2(1).xxxxx; }",
118 "error: 1: too many components in swizzle mask 'xxxxx'\n1 error \n");
119 }
120
121 DEF_TEST(SkSLMissingSemicolon, r) {
122 test_failure(r,
123 "void main() { float x = 1 float y = 2; }",
124 "error: 1: expected ';', but found 'float'\n1 error\n");
125 }
126
127 DEF_TEST(SkSLAssignmentTypeMismatch, r) {
128 test_failure(r,
129 "void main() { int x = 1.0; }",
130 "error: 1: expected 'int', but found 'float'\n1 error\n");
131 }
132
133 DEF_TEST(SkSLReturnFromVoid, r) {
134 test_failure(r,
135 "void main() { return true; }",
136 "error: 1: may not return a value from a void function\n1 error \n");
137 }
138
139 DEF_TEST(SkSLReturnMissingValue, r) {
140 test_failure(r,
141 "int foo() { return; } void main() { }",
142 "error: 1: expected function to return 'int'\n1 error\n");
143 }
144
145 DEF_TEST(SkSLReturnTypeMismatch, r) {
146 test_failure(r,
147 "int foo() { return 1.0; } void main() { }",
148 "error: 1: expected 'int', but found 'float'\n1 error\n");
149 }
150
151 DEF_TEST(SkSLDuplicateFunction, r) {
152 test_failure(r,
153 "void main() { } void main() { }",
154 "error: 1: duplicate definition of void main()\n1 error\n");
155 }
156
157 DEF_TEST(SkSLDifferentReturnType, r) {
158 test_failure(r,
159 "int main() { } void main() { }",
160 "error: 1: functions 'void main()' and 'int main()' differ only in return type\n1 "
161 "error\n");
162 }
163
164 DEF_TEST(SkSLDuplicateSymbol, r) {
165 test_failure(r,
166 "int main; void main() { }",
167 "error: 1: symbol 'main' was already defined\n1 error\n");
168
169 test_failure(r,
170 "int x; int x; void main() { }",
171 "error: 1: symbol 'x' was already defined\n1 error\n");
172
173 test_success(r, "int x; void main() { int x; }");
174 }
175
176 DEF_TEST(SkSLBinaryTypeMismatch, r) {
177 test_failure(r,
178 "void main() { float x = 3 * true; }",
179 "error: 1: type mismatch: '*' cannot operate on 'int', 'bool'\n 1 error\n");
180 }
181
182 DEF_TEST(SkSLCallNonFunction, r) {
183 test_failure(r,
184 "void main() { float x = 3; x(); }",
185 "error: 1: 'x' is not a function\n1 error\n");
186 }
187
188 DEF_TEST(SkSLInvalidUnary, r) {
189 test_failure(r,
190 "void main() { mat4 x = mat4(1); x++; }",
191 "error: 1: '++' cannot operate on 'mat4'\n1 error\n");
192 }
193
194 DEF_TEST(SkSLInvalidAssignment, r) {
195 test_failure(r,
196 "void main() { 1 = 2; }",
197 "error: 1: cannot assign to '1'\n1 error\n");
198 }
OLDNEW
« src/sksl/spirv.h ('K') | « src/sksl/spirv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698