Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkSLCompiler.h" | 8 #include "SkSLCompiler.h" |
| 9 | 9 |
| 10 #include "Test.h" | 10 #include "Test.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 DEF_TEST(SkSLUsingInvalidValue, r) { | 174 DEF_TEST(SkSLUsingInvalidValue, r) { |
| 175 test_failure(r, | 175 test_failure(r, |
| 176 "void main() { int x = int; }", | 176 "void main() { int x = int; }", |
| 177 "error: 1: expected '(' to begin constructor invocation\n1 erro r\n"); | 177 "error: 1: expected '(' to begin constructor invocation\n1 erro r\n"); |
| 178 test_failure(r, | 178 test_failure(r, |
| 179 "int test() { return 1; } void main() { int x = test; }", | 179 "int test() { return 1; } void main() { int x = test; }", |
| 180 "error: 1: expected '(' to begin function call\n1 error\n"); | 180 "error: 1: expected '(' to begin function call\n1 error\n"); |
| 181 } | 181 } |
| 182 DEF_TEST(SkSLDifferentReturnType, r) { | 182 DEF_TEST(SkSLDifferentReturnType, r) { |
| 183 test_failure(r, | 183 test_failure(r, |
| 184 "int main() { } void main() { }", | 184 "int main() { return 1; } void main() { }", |
| 185 "error: 1: functions 'void main()' and 'int main()' differ only in return type\n1 " | 185 "error: 1: functions 'void main()' and 'int main()' differ only in return type\n1 " |
| 186 "error\n"); | 186 "error\n"); |
| 187 } | 187 } |
| 188 | 188 |
| 189 DEF_TEST(SkSLDifferentModifiers, r) { | 189 DEF_TEST(SkSLDifferentModifiers, r) { |
| 190 test_failure(r, | 190 test_failure(r, |
| 191 "void test(int x); void test(out int x) { }", | 191 "void test(int x); void test(out int x) { }", |
| 192 "error: 1: modifiers on parameter 1 differ between declaration and definition\n1 " | 192 "error: 1: modifiers on parameter 1 differ between declaration and definition\n1 " |
| 193 "error\n"); | 193 "error\n"); |
| 194 } | 194 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 test_failure(r, | 271 test_failure(r, |
| 272 "void main() { int x = 5 > 2 ? true : 1.0; }", | 272 "void main() { int x = 5 > 2 ? true : 1.0; }", |
| 273 "error: 1: ternary operator result mismatch: 'bool', 'float'\n1 error\n"); | 273 "error: 1: ternary operator result mismatch: 'bool', 'float'\n1 error\n"); |
| 274 } | 274 } |
| 275 | 275 |
| 276 DEF_TEST(SkSLInterfaceBlockStorageModifiers, r) { | 276 DEF_TEST(SkSLInterfaceBlockStorageModifiers, r) { |
| 277 test_failure(r, | 277 test_failure(r, |
| 278 "uniform foo { out int x; };", | 278 "uniform foo { out int x; };", |
| 279 "error: 1: interface block fields may not have storage qualifie rs\n1 error\n"); | 279 "error: 1: interface block fields may not have storage qualifie rs\n1 error\n"); |
| 280 } | 280 } |
| 281 | |
| 282 DEF_TEST(SkSLUseWithoutInitialize, r) { | |
| 283 test_failure(r, | |
| 284 "void main() { int x; if (5 == 2) x = 3; x++; }", | |
|
dogben
2016/10/13 03:55:43
Would be good to add a few more test cases:
1. ex
ethannicholas
2016/10/13 17:41:28
Done.
| |
| 285 "error: 1: 'x' has not been assigned\n1 error\n"); | |
| 286 } | |
| 287 | |
| 288 DEF_TEST(SkSLUnreachable, r) { | |
| 289 test_failure(r, | |
| 290 "void main() { return; return; }", | |
| 291 "error: 1: unreachable\n1 error\n"); | |
| 292 test_failure(r, | |
| 293 "void main() { for (;;) { continue; int x = 1; } }", | |
| 294 "error: 1: unreachable\n1 error\n"); | |
| 295 test_failure(r, | |
| 296 "void main() { for (;;) { } return; }", | |
| 297 "error: 1: unreachable\n1 error\n"); | |
| 298 test_failure(r, | |
| 299 "void main() { if (true) return; else discard; return; }", | |
|
dogben
2016/10/13 03:55:43
Maybe add this test case: (I think this works corr
ethannicholas
2016/10/13 17:41:28
Done.
| |
| 300 "error: 1: unreachable\n1 error\n"); | |
| 301 } | |
| 302 | |
| 303 DEF_TEST(SkSLNoReturn, r) { | |
| 304 test_failure(r, | |
| 305 "int foo() { if (2 > 5) return 3; }", | |
| 306 "error: 1: function can exit without returning a value\n1 error \n"); | |
| 307 } | |
| 308 | |
| 309 DEF_TEST(SkSLBreakOutsideLoop, r) { | |
| 310 test_failure(r, | |
| 311 "void foo() { while(true) {} if (true) break; }", | |
| 312 "error: 1: break statement must be inside a loop\n1 error\n"); | |
| 313 } | |
| 314 | |
| 315 DEF_TEST(SkSLContinueOutsideLoop, r) { | |
| 316 test_failure(r, | |
| 317 "void foo() { for(;;); continue; }", | |
| 318 "error: 1: continue statement must be inside a loop\n1 error\n" ); | |
| 319 } | |
| OLD | NEW |